use of com.ibm.watson.developer_cloud.http.RequestBuilder in project java-sdk by watson-developer-cloud.
the class Conversation method createEntity.
/**
* Create entity.
*
* Create a new entity.
*
* @param createEntityOptions the {@link CreateEntityOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link Entity}
*/
public ServiceCall<Entity> createEntity(CreateEntityOptions createEntityOptions) {
Validator.notNull(createEntityOptions, "createEntityOptions cannot be null");
String[] pathSegments = { "v1/workspaces", "entities" };
String[] pathParameters = { createEntityOptions.workspaceId() };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
final JsonObject contentJson = new JsonObject();
contentJson.addProperty("entity", createEntityOptions.entity());
if (createEntityOptions.description() != null) {
contentJson.addProperty("description", createEntityOptions.description());
}
if (createEntityOptions.metadata() != null) {
contentJson.add("metadata", GsonSingleton.getGson().toJsonTree(createEntityOptions.metadata()));
}
if (createEntityOptions.values() != null) {
contentJson.add("values", GsonSingleton.getGson().toJsonTree(createEntityOptions.values()));
}
if (createEntityOptions.fuzzyMatch() != null) {
contentJson.addProperty("fuzzy_match", createEntityOptions.fuzzyMatch());
}
builder.bodyJson(contentJson);
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Entity.class));
}
use of com.ibm.watson.developer_cloud.http.RequestBuilder in project java-sdk by watson-developer-cloud.
the class Conversation method createIntent.
/**
* Create intent.
*
* Create a new intent.
*
* @param createIntentOptions the {@link CreateIntentOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link Intent}
*/
public ServiceCall<Intent> createIntent(CreateIntentOptions createIntentOptions) {
Validator.notNull(createIntentOptions, "createIntentOptions cannot be null");
String[] pathSegments = { "v1/workspaces", "intents" };
String[] pathParameters = { createIntentOptions.workspaceId() };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
final JsonObject contentJson = new JsonObject();
contentJson.addProperty("intent", createIntentOptions.intent());
if (createIntentOptions.description() != null) {
contentJson.addProperty("description", createIntentOptions.description());
}
if (createIntentOptions.examples() != null) {
contentJson.add("examples", GsonSingleton.getGson().toJsonTree(createIntentOptions.examples()));
}
builder.bodyJson(contentJson);
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Intent.class));
}
use of com.ibm.watson.developer_cloud.http.RequestBuilder in project java-sdk by watson-developer-cloud.
the class Conversation method deleteValue.
/**
* Delete entity value.
*
* Delete a value for an entity.
*
* @param deleteValueOptions the {@link DeleteValueOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of Void
*/
public ServiceCall<Void> deleteValue(DeleteValueOptions deleteValueOptions) {
Validator.notNull(deleteValueOptions, "deleteValueOptions cannot be null");
String[] pathSegments = { "v1/workspaces", "entities", "values" };
String[] pathParameters = { deleteValueOptions.workspaceId(), deleteValueOptions.entity(), deleteValueOptions.value() };
RequestBuilder builder = RequestBuilder.delete(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
return createServiceCall(builder.build(), ResponseConverterUtils.getVoid());
}
use of com.ibm.watson.developer_cloud.http.RequestBuilder in project java-sdk by watson-developer-cloud.
the class Conversation method getWorkspace.
/**
* Get information about a workspace.
*
* Get information about a workspace, optionally including all workspace content.
*
* @param getWorkspaceOptions the {@link GetWorkspaceOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link WorkspaceExport}
*/
public ServiceCall<WorkspaceExport> getWorkspace(GetWorkspaceOptions getWorkspaceOptions) {
Validator.notNull(getWorkspaceOptions, "getWorkspaceOptions cannot be null");
String[] pathSegments = { "v1/workspaces" };
String[] pathParameters = { getWorkspaceOptions.workspaceId() };
RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
if (getWorkspaceOptions.export() != null) {
builder.query("export", String.valueOf(getWorkspaceOptions.export()));
}
if (getWorkspaceOptions.includeAudit() != null) {
builder.query("include_audit", String.valueOf(getWorkspaceOptions.includeAudit()));
}
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(WorkspaceExport.class));
}
use of com.ibm.watson.developer_cloud.http.RequestBuilder in project java-sdk by watson-developer-cloud.
the class Conversation method createSynonym.
/**
* Add entity value synonym.
*
* Add a new synonym to an entity value.
*
* @param createSynonymOptions the {@link CreateSynonymOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link Synonym}
*/
public ServiceCall<Synonym> createSynonym(CreateSynonymOptions createSynonymOptions) {
Validator.notNull(createSynonymOptions, "createSynonymOptions cannot be null");
String[] pathSegments = { "v1/workspaces", "entities", "values", "synonyms" };
String[] pathParameters = { createSynonymOptions.workspaceId(), createSynonymOptions.entity(), createSynonymOptions.value() };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
final JsonObject contentJson = new JsonObject();
contentJson.addProperty("synonym", createSynonymOptions.synonym());
builder.bodyJson(contentJson);
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Synonym.class));
}
Aggregations