Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2954,4 +2954,106 @@ public String deleteFacetConfiguration(FacetConfigurationRequest facetConfigurat
facetConfigurationRequest.geFacetConfiguration().getName(),
facetConfigurationRequest.getSection());
}

/**
* Creates a facet option configuration
*
* @param request The facet option configuration request containing the configuration to create
* @return returns the created facet option configuration
* @throws ConstructorException if the request is invalid
*/
public String createFacetOptionConfiguration(
FacetOptionConfigurationRequest facetOptionConfigurationRequest)
throws ConstructorException {
try {
HttpUrl url =
this.makeUrl(
Arrays.asList(
"v1",
"facets",
facetOptionConfigurationRequest.getFacetName(),
"options"));
url =
url.newBuilder()
.addQueryParameter(
"section", facetOptionConfigurationRequest.getSection())
.build();

String params =
new Gson()
.toJson(facetOptionConfigurationRequest.getFacetOptionConfiguration());
RequestBody body =
RequestBody.create(params, MediaType.parse("application/json; charset=utf-8"));
Request request = this.makeAuthorizedRequestBuilder().url(url).post(body).build();

Response response = client.newCall(request).execute();

return getResponseBody(response);
} catch (Exception exception) {
throw new ConstructorException(exception);
}
}

/**
* Deletes a facet option configuration
*
* @param facetName the name of the facet
* @param facetOptionValue the value of the facet option to delete
* @param section the section of the facet
* @return returns the deleted facet option configuration
* @throws ConstructorException if the request is invalid
*/
public String deleteFacetOptionConfiguration(
String facetName, String facetOptionValue, String section) throws ConstructorException {
if (facetName == null || facetName.trim().isEmpty()) {
throw new IllegalArgumentException("facetName is required");
}
if (facetOptionValue == null || facetOptionValue.trim().isEmpty()) {
throw new IllegalArgumentException("facetOptionValue is required");
}

try {
HttpUrl url =
this.makeUrl(
Arrays.asList("v1", "facets", facetName, "options", facetOptionValue));
url = url.newBuilder().addQueryParameter("section", section).build();

Request request = this.makeAuthorizedRequestBuilder().url(url).delete().build();

Response response = client.newCall(request).execute();

return getResponseBody(response);
} catch (Exception exception) {
throw new ConstructorException(exception);
}
}

/**
* Deletes a facet option configuration with default section "Products"
*
* @param facetName the name of the facet
* @param facetOptionValue the value of the facet option to delete
* @return returns the deleted facet option configuration
* @throws ConstructorException if the request is invalid
*/
public String deleteFacetOptionConfiguration(String facetName, String facetOptionValue)
throws ConstructorException {
return deleteFacetOptionConfiguration(facetName, facetOptionValue, "Products");
}

/**
* Deletes a facet option configuration
*
* @param request The facet option configuration request containing the configuration to delete
* @return returns the deleted facet option configuration
* @throws ConstructorException if the request is invalid
*/
public String deleteFacetOptionConfiguration(
FacetOptionConfigurationRequest facetOptionConfigurationRequest)
throws ConstructorException {
return deleteFacetOptionConfiguration(
facetOptionConfigurationRequest.getFacetName(),
facetOptionConfigurationRequest.getFacetOptionConfiguration().getValue(),
facetOptionConfigurationRequest.getSection());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package io.constructor.client;

import io.constructor.client.models.FacetOptionConfiguration;

/** Constructor.io Facet Option Configuration Request */
public class FacetOptionConfigurationRequest {
private FacetOptionConfiguration facetOptionConfiguration;
private String facetName;
private String section;

/**
* Creates a facet option configuration request
*
* @param facetOptionConfiguration the facet option configuration to be created
* @param facetName the name of the facet
* @param section the section to which the facet belongs
*/
public FacetOptionConfigurationRequest(
FacetOptionConfiguration facetOptionConfiguration, String facetName, String section) {
if (facetOptionConfiguration == null) {
throw new IllegalArgumentException("facetOptionConfiguration is required");
}
if (facetName == null || facetName.trim().isEmpty()) {
throw new IllegalArgumentException("facetName is required");
}

this.facetOptionConfiguration = facetOptionConfiguration;
this.facetName = facetName;
this.section = section;
}

/**
* Creates a facet option configuration request with default section "Products"
*
* @param option the facet option configuration to be created
* @param facetName the name of the facet
*/
public FacetOptionConfigurationRequest(
FacetOptionConfiguration facetOptionConfiguration, String facetName) {
this(facetOptionConfiguration, facetName, "Products");
}

/**
* @return the facet option configuration
*/
public FacetOptionConfiguration getFacetOptionConfiguration() {
return facetOptionConfiguration;
}

/**
* @param option the facet option configuration to set
*/
public void setFacetOptionConfiguration(FacetOptionConfiguration facetOptionConfiguration) {
this.facetOptionConfiguration = facetOptionConfiguration;
}

/**
* @return the facet name
*/
public String getFacetName() {
return facetName;
}

/**
* @param facetName the facet name to set
*/
public void setFacetName(String facetName) {
this.facetName = facetName;
}

/**
* @return the section
*/
public String getSection() {
return section;
}

/**
* @param section the section to set
*/
public void setSection(String section) {
this.section = section;
}
}
Loading
Loading