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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations