Search in sources :

Example 46 with RequestBuilder

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));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) DialogNode(com.ibm.watson.developer_cloud.conversation.v1.model.DialogNode)

Example 47 with RequestBuilder

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));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) Example(com.ibm.watson.developer_cloud.conversation.v1.model.Example) JsonObject(com.google.gson.JsonObject)

Example 48 with RequestBuilder

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));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) JsonObject(com.google.gson.JsonObject) Workspace(com.ibm.watson.developer_cloud.conversation.v1.model.Workspace)

Example 49 with RequestBuilder

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));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) MessageResponse(com.ibm.watson.developer_cloud.conversation.v1.model.MessageResponse) JsonObject(com.google.gson.JsonObject)

Example 50 with RequestBuilder

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));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) Example(com.ibm.watson.developer_cloud.conversation.v1.model.Example) JsonObject(com.google.gson.JsonObject)

Aggregations

RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)206 JsonObject (com.google.gson.JsonObject)60 MultipartBody (okhttp3.MultipartBody)10 RequestBody (okhttp3.RequestBody)10 Counterexample (com.ibm.watson.developer_cloud.assistant.v1.model.Counterexample)3 DialogNode (com.ibm.watson.developer_cloud.assistant.v1.model.DialogNode)3 Example (com.ibm.watson.developer_cloud.assistant.v1.model.Example)3 Synonym (com.ibm.watson.developer_cloud.assistant.v1.model.Synonym)3 Counterexample (com.ibm.watson.developer_cloud.conversation.v1.model.Counterexample)3 DialogNode (com.ibm.watson.developer_cloud.conversation.v1.model.DialogNode)3 Example (com.ibm.watson.developer_cloud.conversation.v1.model.Example)3 Synonym (com.ibm.watson.developer_cloud.conversation.v1.model.Synonym)3 Collection (com.ibm.watson.developer_cloud.discovery.v1.model.Collection)3 Configuration (com.ibm.watson.developer_cloud.discovery.v1.model.Configuration)3 Environment (com.ibm.watson.developer_cloud.discovery.v1.model.Environment)3 Entity (com.ibm.watson.developer_cloud.assistant.v1.model.Entity)2 Intent (com.ibm.watson.developer_cloud.assistant.v1.model.Intent)2 LogCollection (com.ibm.watson.developer_cloud.assistant.v1.model.LogCollection)2 Value (com.ibm.watson.developer_cloud.assistant.v1.model.Value)2 Workspace (com.ibm.watson.developer_cloud.assistant.v1.model.Workspace)2