use of com.ibm.watson.developer_cloud.http.RequestBuilder in project java-sdk by watson-developer-cloud.
the class Conversation method getDialogNode.
/**
* Get dialog node.
*
* Get information about a dialog node.
*
* @param getDialogNodeOptions the {@link GetDialogNodeOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link DialogNode}
*/
public ServiceCall<DialogNode> getDialogNode(GetDialogNodeOptions getDialogNodeOptions) {
Validator.notNull(getDialogNodeOptions, "getDialogNodeOptions cannot be null");
String[] pathSegments = { "v1/workspaces", "dialog_nodes" };
String[] pathParameters = { getDialogNodeOptions.workspaceId(), getDialogNodeOptions.dialogNode() };
RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
if (getDialogNodeOptions.includeAudit() != null) {
builder.query("include_audit", String.valueOf(getDialogNodeOptions.includeAudit()));
}
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(DialogNode.class));
}
use of com.ibm.watson.developer_cloud.http.RequestBuilder in project java-sdk by watson-developer-cloud.
the class Conversation method createExample.
/**
* Create user input example.
*
* Add a new user input example to an intent.
*
* @param createExampleOptions the {@link CreateExampleOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link Example}
*/
public ServiceCall<Example> createExample(CreateExampleOptions createExampleOptions) {
Validator.notNull(createExampleOptions, "createExampleOptions cannot be null");
String[] pathSegments = { "v1/workspaces", "intents", "examples" };
String[] pathParameters = { createExampleOptions.workspaceId(), createExampleOptions.intent() };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
final JsonObject contentJson = new JsonObject();
contentJson.addProperty("text", createExampleOptions.text());
builder.bodyJson(contentJson);
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Example.class));
}
use of com.ibm.watson.developer_cloud.http.RequestBuilder in project java-sdk by watson-developer-cloud.
the class Conversation method createWorkspace.
/**
* Create workspace.
*
* Create a workspace based on component objects. You must provide workspace components defining the content of the
* new workspace.
*
* @param createWorkspaceOptions the {@link CreateWorkspaceOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link Workspace}
*/
public ServiceCall<Workspace> createWorkspace(CreateWorkspaceOptions createWorkspaceOptions) {
String[] pathSegments = { "v1/workspaces" };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments));
builder.query(VERSION, versionDate);
if (createWorkspaceOptions != null) {
final JsonObject contentJson = new JsonObject();
if (createWorkspaceOptions.name() != null) {
contentJson.addProperty("name", createWorkspaceOptions.name());
}
if (createWorkspaceOptions.description() != null) {
contentJson.addProperty("description", createWorkspaceOptions.description());
}
if (createWorkspaceOptions.language() != null) {
contentJson.addProperty("language", createWorkspaceOptions.language());
}
if (createWorkspaceOptions.intents() != null) {
contentJson.add("intents", GsonSingleton.getGson().toJsonTree(createWorkspaceOptions.intents()));
}
if (createWorkspaceOptions.entities() != null) {
contentJson.add("entities", GsonSingleton.getGson().toJsonTree(createWorkspaceOptions.entities()));
}
if (createWorkspaceOptions.dialogNodes() != null) {
contentJson.add("dialog_nodes", GsonSingleton.getGson().toJsonTree(createWorkspaceOptions.dialogNodes()));
}
if (createWorkspaceOptions.counterexamples() != null) {
contentJson.add("counterexamples", GsonSingleton.getGson().toJsonTree(createWorkspaceOptions.counterexamples()));
}
if (createWorkspaceOptions.metadata() != null) {
contentJson.add("metadata", GsonSingleton.getGson().toJsonTree(createWorkspaceOptions.metadata()));
}
if (createWorkspaceOptions.learningOptOut() != null) {
contentJson.addProperty("learning_opt_out", createWorkspaceOptions.learningOptOut());
}
builder.bodyJson(contentJson);
}
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Workspace.class));
}
use of com.ibm.watson.developer_cloud.http.RequestBuilder in project java-sdk by watson-developer-cloud.
the class Conversation method message.
/**
* Get a response to a user's input.
*
* @param messageOptions the {@link MessageOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link MessageResponse}
*/
public ServiceCall<MessageResponse> message(MessageOptions messageOptions) {
Validator.notNull(messageOptions, "messageOptions cannot be null");
String[] pathSegments = { "v1/workspaces", "message" };
String[] pathParameters = { messageOptions.workspaceId() };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
if (messageOptions.nodesVisitedDetails() != null) {
builder.query("nodes_visited_details", String.valueOf(messageOptions.nodesVisitedDetails()));
}
final JsonObject contentJson = new JsonObject();
if (messageOptions.input() != null) {
contentJson.add("input", GsonSingleton.getGson().toJsonTree(messageOptions.input()));
}
if (messageOptions.alternateIntents() != null) {
contentJson.addProperty("alternate_intents", messageOptions.alternateIntents());
}
if (messageOptions.context() != null) {
contentJson.add("context", GsonSingleton.getGson().toJsonTree(messageOptions.context()));
}
if (messageOptions.entities() != null) {
contentJson.add("entities", GsonSingleton.getGson().toJsonTree(messageOptions.entities()));
}
if (messageOptions.intents() != null) {
contentJson.add("intents", GsonSingleton.getGson().toJsonTree(messageOptions.intents()));
}
if (messageOptions.output() != null) {
contentJson.add("output", GsonSingleton.getGson().toJsonTree(messageOptions.output()));
}
builder.bodyJson(contentJson);
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(MessageResponse.class));
}
use of com.ibm.watson.developer_cloud.http.RequestBuilder in project java-sdk by watson-developer-cloud.
the class Conversation method updateExample.
/**
* Update user input example.
*
* Update the text of a user input example.
*
* @param updateExampleOptions the {@link UpdateExampleOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link Example}
*/
public ServiceCall<Example> updateExample(UpdateExampleOptions updateExampleOptions) {
Validator.notNull(updateExampleOptions, "updateExampleOptions cannot be null");
String[] pathSegments = { "v1/workspaces", "intents", "examples" };
String[] pathParameters = { updateExampleOptions.workspaceId(), updateExampleOptions.intent(), updateExampleOptions.text() };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
final JsonObject contentJson = new JsonObject();
if (updateExampleOptions.newText() != null) {
contentJson.addProperty("text", updateExampleOptions.newText());
}
builder.bodyJson(contentJson);
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Example.class));
}
Aggregations