Skip to content

Commit 5467f68

Browse files
authored
Add create/delete facet option configuration (#156)
* Add create/delete facet option configuration * update names * lint
1 parent e1ffd49 commit 5467f68

File tree

3 files changed

+414
-0
lines changed

3 files changed

+414
-0
lines changed

constructorio-client/src/main/java/io/constructor/client/ConstructorIO.java

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2954,4 +2954,106 @@ public String deleteFacetConfiguration(FacetConfigurationRequest facetConfigurat
29542954
facetConfigurationRequest.geFacetConfiguration().getName(),
29552955
facetConfigurationRequest.getSection());
29562956
}
2957+
2958+
/**
2959+
* Creates a facet option configuration
2960+
*
2961+
* @param request The facet option configuration request containing the configuration to create
2962+
* @return returns the created facet option configuration
2963+
* @throws ConstructorException if the request is invalid
2964+
*/
2965+
public String createFacetOptionConfiguration(
2966+
FacetOptionConfigurationRequest facetOptionConfigurationRequest)
2967+
throws ConstructorException {
2968+
try {
2969+
HttpUrl url =
2970+
this.makeUrl(
2971+
Arrays.asList(
2972+
"v1",
2973+
"facets",
2974+
facetOptionConfigurationRequest.getFacetName(),
2975+
"options"));
2976+
url =
2977+
url.newBuilder()
2978+
.addQueryParameter(
2979+
"section", facetOptionConfigurationRequest.getSection())
2980+
.build();
2981+
2982+
String params =
2983+
new Gson()
2984+
.toJson(facetOptionConfigurationRequest.getFacetOptionConfiguration());
2985+
RequestBody body =
2986+
RequestBody.create(params, MediaType.parse("application/json; charset=utf-8"));
2987+
Request request = this.makeAuthorizedRequestBuilder().url(url).post(body).build();
2988+
2989+
Response response = client.newCall(request).execute();
2990+
2991+
return getResponseBody(response);
2992+
} catch (Exception exception) {
2993+
throw new ConstructorException(exception);
2994+
}
2995+
}
2996+
2997+
/**
2998+
* Deletes a facet option configuration
2999+
*
3000+
* @param facetName the name of the facet
3001+
* @param facetOptionValue the value of the facet option to delete
3002+
* @param section the section of the facet
3003+
* @return returns the deleted facet option configuration
3004+
* @throws ConstructorException if the request is invalid
3005+
*/
3006+
public String deleteFacetOptionConfiguration(
3007+
String facetName, String facetOptionValue, String section) throws ConstructorException {
3008+
if (facetName == null || facetName.trim().isEmpty()) {
3009+
throw new IllegalArgumentException("facetName is required");
3010+
}
3011+
if (facetOptionValue == null || facetOptionValue.trim().isEmpty()) {
3012+
throw new IllegalArgumentException("facetOptionValue is required");
3013+
}
3014+
3015+
try {
3016+
HttpUrl url =
3017+
this.makeUrl(
3018+
Arrays.asList("v1", "facets", facetName, "options", facetOptionValue));
3019+
url = url.newBuilder().addQueryParameter("section", section).build();
3020+
3021+
Request request = this.makeAuthorizedRequestBuilder().url(url).delete().build();
3022+
3023+
Response response = client.newCall(request).execute();
3024+
3025+
return getResponseBody(response);
3026+
} catch (Exception exception) {
3027+
throw new ConstructorException(exception);
3028+
}
3029+
}
3030+
3031+
/**
3032+
* Deletes a facet option configuration with default section "Products"
3033+
*
3034+
* @param facetName the name of the facet
3035+
* @param facetOptionValue the value of the facet option to delete
3036+
* @return returns the deleted facet option configuration
3037+
* @throws ConstructorException if the request is invalid
3038+
*/
3039+
public String deleteFacetOptionConfiguration(String facetName, String facetOptionValue)
3040+
throws ConstructorException {
3041+
return deleteFacetOptionConfiguration(facetName, facetOptionValue, "Products");
3042+
}
3043+
3044+
/**
3045+
* Deletes a facet option configuration
3046+
*
3047+
* @param request The facet option configuration request containing the configuration to delete
3048+
* @return returns the deleted facet option configuration
3049+
* @throws ConstructorException if the request is invalid
3050+
*/
3051+
public String deleteFacetOptionConfiguration(
3052+
FacetOptionConfigurationRequest facetOptionConfigurationRequest)
3053+
throws ConstructorException {
3054+
return deleteFacetOptionConfiguration(
3055+
facetOptionConfigurationRequest.getFacetName(),
3056+
facetOptionConfigurationRequest.getFacetOptionConfiguration().getValue(),
3057+
facetOptionConfigurationRequest.getSection());
3058+
}
29573059
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package io.constructor.client;
2+
3+
import io.constructor.client.models.FacetOptionConfiguration;
4+
5+
/** Constructor.io Facet Option Configuration Request */
6+
public class FacetOptionConfigurationRequest {
7+
private FacetOptionConfiguration facetOptionConfiguration;
8+
private String facetName;
9+
private String section;
10+
11+
/**
12+
* Creates a facet option configuration request
13+
*
14+
* @param facetOptionConfiguration the facet option configuration to be created
15+
* @param facetName the name of the facet
16+
* @param section the section to which the facet belongs
17+
*/
18+
public FacetOptionConfigurationRequest(
19+
FacetOptionConfiguration facetOptionConfiguration, String facetName, String section) {
20+
if (facetOptionConfiguration == null) {
21+
throw new IllegalArgumentException("facetOptionConfiguration is required");
22+
}
23+
if (facetName == null || facetName.trim().isEmpty()) {
24+
throw new IllegalArgumentException("facetName is required");
25+
}
26+
27+
this.facetOptionConfiguration = facetOptionConfiguration;
28+
this.facetName = facetName;
29+
this.section = section;
30+
}
31+
32+
/**
33+
* Creates a facet option configuration request with default section "Products"
34+
*
35+
* @param option the facet option configuration to be created
36+
* @param facetName the name of the facet
37+
*/
38+
public FacetOptionConfigurationRequest(
39+
FacetOptionConfiguration facetOptionConfiguration, String facetName) {
40+
this(facetOptionConfiguration, facetName, "Products");
41+
}
42+
43+
/**
44+
* @return the facet option configuration
45+
*/
46+
public FacetOptionConfiguration getFacetOptionConfiguration() {
47+
return facetOptionConfiguration;
48+
}
49+
50+
/**
51+
* @param option the facet option configuration to set
52+
*/
53+
public void setFacetOptionConfiguration(FacetOptionConfiguration facetOptionConfiguration) {
54+
this.facetOptionConfiguration = facetOptionConfiguration;
55+
}
56+
57+
/**
58+
* @return the facet name
59+
*/
60+
public String getFacetName() {
61+
return facetName;
62+
}
63+
64+
/**
65+
* @param facetName the facet name to set
66+
*/
67+
public void setFacetName(String facetName) {
68+
this.facetName = facetName;
69+
}
70+
71+
/**
72+
* @return the section
73+
*/
74+
public String getSection() {
75+
return section;
76+
}
77+
78+
/**
79+
* @param section the section to set
80+
*/
81+
public void setSection(String section) {
82+
this.section = section;
83+
}
84+
}

0 commit comments

Comments
 (0)