Search in sources :

Example 1 with RequestBuilder

use of com.ibm.cloud.sdk.core.http.RequestBuilder in project cloudant-java-sdk by IBM.

the class Cloudant method postPartitionAllDocsAsStream.

/**
 * Query a list of all documents in a database partition as stream.
 *
 * Queries the primary index (all document IDs). The results that match the query parameters are returned in a JSON
 * object, including a list of matching documents with basic contents, such as the ID and revision. When no query
 * parameters are specified, results for all documents in the database partition are returned. Optionally, document
 * content or additional metadata can be included in the response.
 *
 * @param postPartitionAllDocsOptions the {@link PostPartitionAllDocsOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link InputStream}
 */
public ServiceCall<InputStream> postPartitionAllDocsAsStream(PostPartitionAllDocsOptions postPartitionAllDocsOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(postPartitionAllDocsOptions, "postPartitionAllDocsOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", postPartitionAllDocsOptions.db());
    pathParamsMap.put("partition_key", postPartitionAllDocsOptions.partitionKey());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_partition/{partition_key}/_all_docs", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postPartitionAllDocsAsStream");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    final JsonObject contentJson = new JsonObject();
    if (postPartitionAllDocsOptions.attEncodingInfo() != null) {
        contentJson.addProperty("att_encoding_info", postPartitionAllDocsOptions.attEncodingInfo());
    }
    if (postPartitionAllDocsOptions.attachments() != null) {
        contentJson.addProperty("attachments", postPartitionAllDocsOptions.attachments());
    }
    if (postPartitionAllDocsOptions.conflicts() != null) {
        contentJson.addProperty("conflicts", postPartitionAllDocsOptions.conflicts());
    }
    if (postPartitionAllDocsOptions.descending() != null) {
        contentJson.addProperty("descending", postPartitionAllDocsOptions.descending());
    }
    if (postPartitionAllDocsOptions.includeDocs() != null) {
        contentJson.addProperty("include_docs", postPartitionAllDocsOptions.includeDocs());
    }
    if (postPartitionAllDocsOptions.inclusiveEnd() != null) {
        contentJson.addProperty("inclusive_end", postPartitionAllDocsOptions.inclusiveEnd());
    }
    if (postPartitionAllDocsOptions.limit() != null) {
        contentJson.addProperty("limit", postPartitionAllDocsOptions.limit());
    }
    if (postPartitionAllDocsOptions.skip() != null) {
        contentJson.addProperty("skip", postPartitionAllDocsOptions.skip());
    }
    if (postPartitionAllDocsOptions.updateSeq() != null) {
        contentJson.addProperty("update_seq", postPartitionAllDocsOptions.updateSeq());
    }
    if (postPartitionAllDocsOptions.endkey() != null) {
        contentJson.addProperty("endkey", postPartitionAllDocsOptions.endkey());
    }
    if (postPartitionAllDocsOptions.key() != null) {
        contentJson.addProperty("key", postPartitionAllDocsOptions.key());
    }
    if (postPartitionAllDocsOptions.keys() != null) {
        contentJson.add("keys", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postPartitionAllDocsOptions.keys()));
    }
    if (postPartitionAllDocsOptions.startkey() != null) {
        contentJson.addProperty("startkey", postPartitionAllDocsOptions.startkey());
    }
    builder.bodyJson(contentJson);
    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) JsonObject(com.google.gson.JsonObject)

Example 2 with RequestBuilder

use of com.ibm.cloud.sdk.core.http.RequestBuilder in project cloudant-java-sdk by IBM.

the class Cloudant method postViewQueries.

/**
 * Multi-query a MapReduce view.
 *
 * This operation runs multiple specified view queries against the view function from the specified design document.
 *
 * @param postViewQueriesOptions the {@link PostViewQueriesOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link ViewQueriesResult}
 */
public ServiceCall<ViewQueriesResult> postViewQueries(PostViewQueriesOptions postViewQueriesOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(postViewQueriesOptions, "postViewQueriesOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", postViewQueriesOptions.db());
    pathParamsMap.put("ddoc", postViewQueriesOptions.ddoc());
    pathParamsMap.put("view", postViewQueriesOptions.view());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_design/{ddoc}/_view/{view}/queries", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postViewQueries");
    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("queries", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postViewQueriesOptions.queries()));
    builder.bodyJson(contentJson);
    ResponseConverter<ViewQueriesResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<ViewQueriesResult>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) ViewQueriesResult(com.ibm.cloud.cloudant.v1.model.ViewQueriesResult) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject)

Example 3 with RequestBuilder

use of com.ibm.cloud.sdk.core.http.RequestBuilder in project cloudant-java-sdk by IBM.

the class Cloudant method deleteAttachment.

/**
 * Delete an attachment.
 *
 * Deletes the attachment with the filename, `{attachment_name}`, from the specified doc. You must supply the `rev`
 * query parameter or `If-Match` header with the current revision to delete the attachment.
 *
 * @param deleteAttachmentOptions the {@link DeleteAttachmentOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link DocumentResult}
 */
public ServiceCall<DocumentResult> deleteAttachment(DeleteAttachmentOptions deleteAttachmentOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(deleteAttachmentOptions, "deleteAttachmentOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", deleteAttachmentOptions.db());
    pathParamsMap.put("doc_id", deleteAttachmentOptions.docId());
    pathParamsMap.put("attachment_name", deleteAttachmentOptions.attachmentName());
    RequestBuilder builder = RequestBuilder.delete(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/{doc_id}/{attachment_name}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "deleteAttachment");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    if (deleteAttachmentOptions.ifMatch() != null) {
        builder.header("If-Match", deleteAttachmentOptions.ifMatch());
    }
    if (deleteAttachmentOptions.rev() != null) {
        builder.query("rev", String.valueOf(deleteAttachmentOptions.rev()));
    }
    if (deleteAttachmentOptions.batch() != null) {
        builder.query("batch", String.valueOf(deleteAttachmentOptions.batch()));
    }
    ResponseConverter<DocumentResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<DocumentResult>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) DocumentResult(com.ibm.cloud.cloudant.v1.model.DocumentResult)

Example 4 with RequestBuilder

use of com.ibm.cloud.sdk.core.http.RequestBuilder in project cloudant-java-sdk by IBM.

the class Cloudant method getSearchInfo.

/**
 * Retrieve information about a search index.
 *
 * Retrieve search index metadata information, such as the size of the index on disk.
 *
 * @param getSearchInfoOptions the {@link GetSearchInfoOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link SearchInfoResult}
 */
public ServiceCall<SearchInfoResult> getSearchInfo(GetSearchInfoOptions getSearchInfoOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getSearchInfoOptions, "getSearchInfoOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", getSearchInfoOptions.db());
    pathParamsMap.put("ddoc", getSearchInfoOptions.ddoc());
    pathParamsMap.put("index", getSearchInfoOptions.index());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_design/{ddoc}/_search_info/{index}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getSearchInfo");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    ResponseConverter<SearchInfoResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<SearchInfoResult>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : SearchInfoResult(com.ibm.cloud.cloudant.v1.model.SearchInfoResult) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap)

Example 5 with RequestBuilder

use of com.ibm.cloud.sdk.core.http.RequestBuilder in project cloudant-java-sdk by IBM.

the class Cloudant method headReplicationDocument.

/**
 * Retrieve the HTTP headers for a replication document.
 *
 * Retrieves the HTTP headers containing minimal amount of information about the specified replication document from
 * the `_replicator` database.  The method supports the same query arguments as the `GET /_replicator/{doc_id}`
 * method, but only headers like content length and the revision (ETag header) are returned.
 *
 * @param headReplicationDocumentOptions the {@link HeadReplicationDocumentOptions} containing the options for the call
 * @return a {@link ServiceCall} with a void result
 */
public ServiceCall<Void> headReplicationDocument(HeadReplicationDocumentOptions headReplicationDocumentOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(headReplicationDocumentOptions, "headReplicationDocumentOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("doc_id", headReplicationDocumentOptions.docId());
    RequestBuilder builder = RequestBuilder.head(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_replicator/{doc_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "headReplicationDocument");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    if (headReplicationDocumentOptions.ifNoneMatch() != null) {
        builder.header("If-None-Match", headReplicationDocumentOptions.ifNoneMatch());
    }
    ResponseConverter<Void> responseConverter = ResponseConverterUtils.getVoid();
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap)

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