Search in sources :

Example 56 with RequestBuilder

use of com.ibm.cloud.sdk.core.http.RequestBuilder in project java-sdk by watson-developer-cloud.

the class NaturalLanguageClassifier method deleteClassifier.

/**
 * Delete classifier.
 *
 * @param deleteClassifierOptions the {@link DeleteClassifierOptions} containing the options for
 *     the call
 * @return a {@link ServiceCall} with a void result
 */
public ServiceCall<Void> deleteClassifier(DeleteClassifierOptions deleteClassifierOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(deleteClassifierOptions, "deleteClassifierOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("classifier_id", deleteClassifierOptions.classifierId());
    RequestBuilder builder = RequestBuilder.delete(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/classifiers/{classifier_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("natural_language_classifier", "v1", "deleteClassifier");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    ResponseConverter<Void> responseConverter = ResponseConverterUtils.getVoid();
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap)

Example 57 with RequestBuilder

use of com.ibm.cloud.sdk.core.http.RequestBuilder in project java-sdk by watson-developer-cloud.

the class NaturalLanguageClassifier method getClassifier.

/**
 * Get information about a classifier.
 *
 * <p>Returns status and other information about a classifier.
 *
 * @param getClassifierOptions the {@link GetClassifierOptions} containing the options for the
 *     call
 * @return a {@link ServiceCall} with a result of type {@link Classifier}
 */
public ServiceCall<Classifier> getClassifier(GetClassifierOptions getClassifierOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getClassifierOptions, "getClassifierOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("classifier_id", getClassifierOptions.classifierId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/classifiers/{classifier_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("natural_language_classifier", "v1", "getClassifier");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    ResponseConverter<Classifier> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Classifier>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) Classifier(com.ibm.watson.natural_language_classifier.v1.model.Classifier)

Example 58 with RequestBuilder

use of com.ibm.cloud.sdk.core.http.RequestBuilder in project java-sdk by watson-developer-cloud.

the class NaturalLanguageClassifier method classifyCollection.

/**
 * Classify multiple phrases.
 *
 * <p>Returns label information for multiple phrases. The status must be `Available` before you
 * can use the classifier to classify text.
 *
 * <p>Note that classifying Japanese texts is a beta feature.
 *
 * @param classifyCollectionOptions the {@link ClassifyCollectionOptions} containing the options
 *     for the call
 * @return a {@link ServiceCall} with a result of type {@link ClassificationCollection}
 */
public ServiceCall<ClassificationCollection> classifyCollection(ClassifyCollectionOptions classifyCollectionOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(classifyCollectionOptions, "classifyCollectionOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("classifier_id", classifyCollectionOptions.classifierId());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/classifiers/{classifier_id}/classify_collection", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("natural_language_classifier", "v1", "classifyCollection");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    final JsonObject contentJson = new JsonObject();
    contentJson.add("collection", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(classifyCollectionOptions.collection()));
    builder.bodyJson(contentJson);
    ResponseConverter<ClassificationCollection> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<ClassificationCollection>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : ClassificationCollection(com.ibm.watson.natural_language_classifier.v1.model.ClassificationCollection) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject)

Example 59 with RequestBuilder

use of com.ibm.cloud.sdk.core.http.RequestBuilder in project java-sdk by watson-developer-cloud.

the class CompareComply method extractTables.

/**
 * Extract a document's tables.
 *
 * <p>Analyzes the tables in a document.
 *
 * @param extractTablesOptions the {@link ExtractTablesOptions} containing the options for the
 *     call
 * @return a {@link ServiceCall} with a result of type {@link TableReturn}
 */
public ServiceCall<TableReturn> extractTables(ExtractTablesOptions extractTablesOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(extractTablesOptions, "extractTablesOptions cannot be null");
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/tables"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("compare-comply", "v1", "extractTables");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    builder.query("version", String.valueOf(this.version));
    if (extractTablesOptions.model() != null) {
        builder.query("model", String.valueOf(extractTablesOptions.model()));
    }
    MultipartBody.Builder multipartBuilder = new MultipartBody.Builder();
    multipartBuilder.setType(MultipartBody.FORM);
    okhttp3.RequestBody fileBody = RequestUtils.inputStreamBody(extractTablesOptions.file(), extractTablesOptions.fileContentType());
    multipartBuilder.addFormDataPart("file", "filename", fileBody);
    builder.body(multipartBuilder.build());
    ResponseConverter<TableReturn> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<TableReturn>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) TableReturn(com.ibm.watson.compare_comply.v1.model.TableReturn) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) MultipartBody(okhttp3.MultipartBody)

Example 60 with RequestBuilder

use of com.ibm.cloud.sdk.core.http.RequestBuilder in project java-sdk by watson-developer-cloud.

the class VisualRecognition method updateCollection.

/**
 * Update a collection.
 *
 * <p>Update the name or description of a collection.
 *
 * <p>Encode the name and description in UTF-8 if they contain non-ASCII characters. The service
 * assumes UTF-8 encoding if it encounters non-ASCII characters.
 *
 * @param updateCollectionOptions the {@link UpdateCollectionOptions} containing the options for
 *     the call
 * @return a {@link ServiceCall} with a result of type {@link Collection}
 */
public ServiceCall<Collection> updateCollection(UpdateCollectionOptions updateCollectionOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(updateCollectionOptions, "updateCollectionOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("collection_id", updateCollectionOptions.collectionId());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v4/collections/{collection_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("watson_vision_combined", "v4", "updateCollection");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    builder.query("version", String.valueOf(this.version));
    final JsonObject contentJson = new JsonObject();
    if (updateCollectionOptions.name() != null) {
        contentJson.addProperty("name", updateCollectionOptions.name());
    }
    if (updateCollectionOptions.description() != null) {
        contentJson.addProperty("description", updateCollectionOptions.description());
    }
    builder.bodyJson(contentJson);
    ResponseConverter<Collection> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Collection>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) Collection(com.ibm.watson.visual_recognition.v4.model.Collection)

Aggregations

RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)422 HashMap (java.util.HashMap)324 JsonObject (com.google.gson.JsonObject)111 MultipartBody (okhttp3.MultipartBody)30 InputStream (java.io.InputStream)27 DocumentResult (com.ibm.cloud.cloudant.v1.model.DocumentResult)12 Ok (com.ibm.cloud.cloudant.v1.model.Ok)8 MetricResponse (com.ibm.watson.discovery.v1.model.MetricResponse)4 DeleteModelResults (com.ibm.watson.natural_language_understanding.v1.model.DeleteModelResults)4 Collection (com.ibm.watson.visual_recognition.v4.model.Collection)4 DesignDocument (com.ibm.cloud.cloudant.v1.model.DesignDocument)3 ReplicationDocument (com.ibm.cloud.cloudant.v1.model.ReplicationDocument)3 TagsSubscriptionList (com.ibm.cloud.eventnotifications.event_notifications.v1.model.TagsSubscriptionList)3 Counterexample (com.ibm.watson.assistant.v1.model.Counterexample)3 DialogNode (com.ibm.watson.assistant.v1.model.DialogNode)3 Entity (com.ibm.watson.assistant.v1.model.Entity)3 Intent (com.ibm.watson.assistant.v1.model.Intent)3 Value (com.ibm.watson.assistant.v1.model.Value)3 DeleteCredentials (com.ibm.watson.discovery.v1.model.DeleteCredentials)3 TokenDictStatusResponse (com.ibm.watson.discovery.v1.model.TokenDictStatusResponse)3