Search in sources :

Example 66 with RequestBuilder

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

the class VisualRecognition method getObjectMetadata.

/**
 * Get object metadata.
 *
 * <p>Get the number of bounding boxes for a single object in a collection.
 *
 * @param getObjectMetadataOptions the {@link GetObjectMetadataOptions} containing the options for
 *     the call
 * @return a {@link ServiceCall} with a result of type {@link ObjectMetadata}
 */
public ServiceCall<ObjectMetadata> getObjectMetadata(GetObjectMetadataOptions getObjectMetadataOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getObjectMetadataOptions, "getObjectMetadataOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("collection_id", getObjectMetadataOptions.collectionId());
    pathParamsMap.put("object", getObjectMetadataOptions.object());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v4/collections/{collection_id}/objects/{object}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("watson_vision_combined", "v4", "getObjectMetadata");
    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));
    ResponseConverter<ObjectMetadata> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<ObjectMetadata>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) UpdateObjectMetadata(com.ibm.watson.visual_recognition.v4.model.UpdateObjectMetadata) ObjectMetadata(com.ibm.watson.visual_recognition.v4.model.ObjectMetadata)

Example 67 with RequestBuilder

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

the class VisualRecognition method getModelFile.

/**
 * Get a model.
 *
 * <p>Download a model that you can deploy to detect objects in images. The collection must
 * include a generated model, which is indicated in the response for the collection details as
 * `"rscnn_ready": true`. If the value is `false`, train or retrain the collection to generate the
 * model.
 *
 * <p>Currently, the model format is specific to Android apps. For more information about how to
 * deploy the model to your app, see the [Watson Visual Recognition on
 * Android](https://github.com/matt-ny/rscnn) project in GitHub.
 *
 * @param getModelFileOptions the {@link GetModelFileOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link InputStream}
 */
public ServiceCall<InputStream> getModelFile(GetModelFileOptions getModelFileOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getModelFileOptions, "getModelFileOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("collection_id", getModelFileOptions.collectionId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v4/collections/{collection_id}/model", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("watson_vision_combined", "v4", "getModelFile");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/octet-stream");
    builder.query("version", String.valueOf(this.version));
    builder.query("feature", String.valueOf(getModelFileOptions.feature()));
    builder.query("model_format", String.valueOf(getModelFileOptions.modelFormat()));
    ResponseConverter<InputStream> responseConverter = ResponseConverterUtils.getInputStream();
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) InputStream(java.io.InputStream)

Example 68 with RequestBuilder

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

the class VisualRecognition method deleteUserData.

/**
 * Delete labeled data.
 *
 * <p>Deletes all data associated with a specified customer ID. The method has no effect if no
 * data is associated with the customer ID.
 *
 * <p>You associate a customer ID with data by passing the `X-Watson-Metadata` header with a
 * request that passes data. For more information about personal data and customer IDs, see
 * [Information
 * security](https://cloud.ibm.com/docs/visual-recognition?topic=visual-recognition-information-security).
 *
 * @param deleteUserDataOptions the {@link DeleteUserDataOptions} containing the options for the
 *     call
 * @return a {@link ServiceCall} with a void result
 */
public ServiceCall<Void> deleteUserData(DeleteUserDataOptions deleteUserDataOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(deleteUserDataOptions, "deleteUserDataOptions cannot be null");
    RequestBuilder builder = RequestBuilder.delete(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v4/user_data"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("watson_vision_combined", "v4", "deleteUserData");
    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));
    builder.query("customer_id", String.valueOf(deleteUserDataOptions.customerId()));
    ResponseConverter<Void> responseConverter = ResponseConverterUtils.getVoid();
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder)

Example 69 with RequestBuilder

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

the class VisualRecognition method getCollection.

/**
 * Get collection details.
 *
 * <p>Get details of one collection.
 *
 * @param getCollectionOptions the {@link GetCollectionOptions} containing the options for the
 *     call
 * @return a {@link ServiceCall} with a result of type {@link Collection}
 */
public ServiceCall<Collection> getCollection(GetCollectionOptions getCollectionOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getCollectionOptions, "getCollectionOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("collection_id", getCollectionOptions.collectionId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v4/collections/{collection_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("watson_vision_combined", "v4", "getCollection");
    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));
    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) Collection(com.ibm.watson.visual_recognition.v4.model.Collection)

Example 70 with RequestBuilder

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

the class VisualRecognition method analyze.

/**
 * Analyze images.
 *
 * <p>Analyze images by URL, by file, or both against your own collection. Make sure that
 * **training_status.objects.ready** is `true` for the feature before you use a collection to
 * analyze images.
 *
 * <p>Encode the image and .zip file names in UTF-8 if they contain non-ASCII characters. The
 * service assumes UTF-8 encoding if it encounters non-ASCII characters.
 *
 * @param analyzeOptions the {@link AnalyzeOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link AnalyzeResponse}
 */
public ServiceCall<AnalyzeResponse> analyze(AnalyzeOptions analyzeOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(analyzeOptions, "analyzeOptions cannot be null");
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v4/analyze"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("watson_vision_combined", "v4", "analyze");
    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));
    MultipartBody.Builder multipartBuilder = new MultipartBody.Builder();
    multipartBuilder.setType(MultipartBody.FORM);
    for (String item : analyzeOptions.collectionIds()) {
        multipartBuilder.addFormDataPart("collection_ids", item);
    }
    for (String item : analyzeOptions.features()) {
        multipartBuilder.addFormDataPart("features", item);
    }
    if (analyzeOptions.imagesFile() != null) {
        for (FileWithMetadata item : analyzeOptions.imagesFile()) {
            okhttp3.RequestBody itemBody = RequestUtils.inputStreamBody(item.data(), item.contentType());
            multipartBuilder.addFormDataPart("images_file", item.filename(), itemBody);
        }
    }
    if (analyzeOptions.imageUrl() != null) {
        for (String item : analyzeOptions.imageUrl()) {
            multipartBuilder.addFormDataPart("image_url", item);
        }
    }
    if (analyzeOptions.threshold() != null) {
        multipartBuilder.addFormDataPart("threshold", String.valueOf(analyzeOptions.threshold()));
    }
    builder.body(multipartBuilder.build());
    ResponseConverter<AnalyzeResponse> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<AnalyzeResponse>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) AnalyzeResponse(com.ibm.watson.visual_recognition.v4.model.AnalyzeResponse) MultipartBody(okhttp3.MultipartBody) FileWithMetadata(com.ibm.cloud.sdk.core.service.model.FileWithMetadata)

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