Search in sources :

Example 46 with RequestBuilder

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

the class Cloudant method postView.

/**
 * Query a MapReduce view.
 *
 * This operation queries the specified MapReduce view of the specified design document. By default, the map and
 * reduce functions of the view are run to update the view before returning the response. The advantage of using the
 * HTTP `POST` method is that the query is submitted as a JSON object in the request body. This avoids the limitations
 * of passing query options as URL query parameters of a `GET` request.
 *
 * @param postViewOptions the {@link PostViewOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link ViewResult}
 */
public ServiceCall<ViewResult> postView(PostViewOptions postViewOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(postViewOptions, "postViewOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", postViewOptions.db());
    pathParamsMap.put("ddoc", postViewOptions.ddoc());
    pathParamsMap.put("view", postViewOptions.view());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_design/{ddoc}/_view/{view}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postView");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    final JsonObject contentJson = new JsonObject();
    if (postViewOptions.attEncodingInfo() != null) {
        contentJson.addProperty("att_encoding_info", postViewOptions.attEncodingInfo());
    }
    if (postViewOptions.attachments() != null) {
        contentJson.addProperty("attachments", postViewOptions.attachments());
    }
    if (postViewOptions.conflicts() != null) {
        contentJson.addProperty("conflicts", postViewOptions.conflicts());
    }
    if (postViewOptions.descending() != null) {
        contentJson.addProperty("descending", postViewOptions.descending());
    }
    if (postViewOptions.includeDocs() != null) {
        contentJson.addProperty("include_docs", postViewOptions.includeDocs());
    }
    if (postViewOptions.inclusiveEnd() != null) {
        contentJson.addProperty("inclusive_end", postViewOptions.inclusiveEnd());
    }
    if (postViewOptions.limit() != null) {
        contentJson.addProperty("limit", postViewOptions.limit());
    }
    if (postViewOptions.skip() != null) {
        contentJson.addProperty("skip", postViewOptions.skip());
    }
    if (postViewOptions.updateSeq() != null) {
        contentJson.addProperty("update_seq", postViewOptions.updateSeq());
    }
    if (postViewOptions.endkey() != null) {
        contentJson.add("endkey", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postViewOptions.endkey()));
    }
    if (postViewOptions.endkeyDocid() != null) {
        contentJson.addProperty("endkey_docid", postViewOptions.endkeyDocid());
    }
    if (postViewOptions.group() != null) {
        contentJson.addProperty("group", postViewOptions.group());
    }
    if (postViewOptions.groupLevel() != null) {
        contentJson.addProperty("group_level", postViewOptions.groupLevel());
    }
    if (postViewOptions.key() != null) {
        contentJson.add("key", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postViewOptions.key()));
    }
    if (postViewOptions.keys() != null) {
        contentJson.add("keys", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postViewOptions.keys()));
    }
    if (postViewOptions.reduce() != null) {
        contentJson.addProperty("reduce", postViewOptions.reduce());
    }
    if (postViewOptions.stable() != null) {
        contentJson.addProperty("stable", postViewOptions.stable());
    }
    if (postViewOptions.startkey() != null) {
        contentJson.add("startkey", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postViewOptions.startkey()));
    }
    if (postViewOptions.startkeyDocid() != null) {
        contentJson.addProperty("startkey_docid", postViewOptions.startkeyDocid());
    }
    if (postViewOptions.update() != null) {
        contentJson.addProperty("update", postViewOptions.update());
    }
    builder.bodyJson(contentJson);
    ResponseConverter<ViewResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<ViewResult>() {
    }.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) ViewResult(com.ibm.cloud.cloudant.v1.model.ViewResult)

Example 47 with RequestBuilder

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

the class Cloudant method postPartitionAllDocs.

/**
 * Query a list of all documents in a database partition.
 *
 * 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 AllDocsResult}
 */
public ServiceCall<AllDocsResult> postPartitionAllDocs(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", "postPartitionAllDocs");
    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<AllDocsResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<AllDocsResult>() {
    }.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) AllDocsResult(com.ibm.cloud.cloudant.v1.model.AllDocsResult)

Example 48 with RequestBuilder

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

the class Cloudant method postChanges.

/**
 * Query the database document changes feed.
 *
 * Requests the database changes feed in the same way as `GET /{db}/_changes` does. It is widely used with the
 * `filter` query parameter because it allows one to pass more information to the filter.
 *
 * @param postChangesOptions the {@link PostChangesOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link ChangesResult}
 */
public ServiceCall<ChangesResult> postChanges(PostChangesOptions postChangesOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(postChangesOptions, "postChangesOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", postChangesOptions.db());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_changes", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postChanges");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    if (postChangesOptions.lastEventId() != null) {
        builder.header("Last-Event-ID", postChangesOptions.lastEventId());
    }
    if (postChangesOptions.attEncodingInfo() != null) {
        builder.query("att_encoding_info", String.valueOf(postChangesOptions.attEncodingInfo()));
    }
    if (postChangesOptions.attachments() != null) {
        builder.query("attachments", String.valueOf(postChangesOptions.attachments()));
    }
    if (postChangesOptions.conflicts() != null) {
        builder.query("conflicts", String.valueOf(postChangesOptions.conflicts()));
    }
    if (postChangesOptions.descending() != null) {
        builder.query("descending", String.valueOf(postChangesOptions.descending()));
    }
    if (postChangesOptions.feed() != null) {
        builder.query("feed", String.valueOf(postChangesOptions.feed()));
    }
    if (postChangesOptions.filter() != null) {
        builder.query("filter", String.valueOf(postChangesOptions.filter()));
    }
    if (postChangesOptions.heartbeat() != null) {
        builder.query("heartbeat", String.valueOf(postChangesOptions.heartbeat()));
    }
    if (postChangesOptions.includeDocs() != null) {
        builder.query("include_docs", String.valueOf(postChangesOptions.includeDocs()));
    }
    if (postChangesOptions.limit() != null) {
        builder.query("limit", String.valueOf(postChangesOptions.limit()));
    }
    if (postChangesOptions.seqInterval() != null) {
        builder.query("seq_interval", String.valueOf(postChangesOptions.seqInterval()));
    }
    if (postChangesOptions.since() != null) {
        builder.query("since", String.valueOf(postChangesOptions.since()));
    }
    if (postChangesOptions.style() != null) {
        builder.query("style", String.valueOf(postChangesOptions.style()));
    }
    if (postChangesOptions.timeout() != null) {
        builder.query("timeout", String.valueOf(postChangesOptions.timeout()));
    }
    if (postChangesOptions.view() != null) {
        builder.query("view", String.valueOf(postChangesOptions.view()));
    }
    final JsonObject contentJson = new JsonObject();
    if (postChangesOptions.docIds() != null) {
        contentJson.add("doc_ids", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postChangesOptions.docIds()));
    }
    if (postChangesOptions.fields() != null) {
        contentJson.add("fields", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postChangesOptions.fields()));
    }
    if (postChangesOptions.selector() != null) {
        contentJson.add("selector", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postChangesOptions.selector()));
    }
    builder.bodyJson(contentJson);
    ResponseConverter<ChangesResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<ChangesResult>() {
    }.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) ChangesResult(com.ibm.cloud.cloudant.v1.model.ChangesResult)

Example 49 with RequestBuilder

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

the class Cloudant method getDesignDocument.

/**
 * Retrieve a design document.
 *
 * Returns design document with the specified `doc_id` from the specified database. Unless you request a specific
 * revision, the current revision of the design document is always returned.
 *
 * @param getDesignDocumentOptions the {@link GetDesignDocumentOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link DesignDocument}
 */
public ServiceCall<DesignDocument> getDesignDocument(GetDesignDocumentOptions getDesignDocumentOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getDesignDocumentOptions, "getDesignDocumentOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", getDesignDocumentOptions.db());
    pathParamsMap.put("ddoc", getDesignDocumentOptions.ddoc());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_design/{ddoc}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getDesignDocument");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    if (getDesignDocumentOptions.ifNoneMatch() != null) {
        builder.header("If-None-Match", getDesignDocumentOptions.ifNoneMatch());
    }
    if (getDesignDocumentOptions.attachments() != null) {
        builder.query("attachments", String.valueOf(getDesignDocumentOptions.attachments()));
    }
    if (getDesignDocumentOptions.attEncodingInfo() != null) {
        builder.query("att_encoding_info", String.valueOf(getDesignDocumentOptions.attEncodingInfo()));
    }
    if (getDesignDocumentOptions.conflicts() != null) {
        builder.query("conflicts", String.valueOf(getDesignDocumentOptions.conflicts()));
    }
    if (getDesignDocumentOptions.deletedConflicts() != null) {
        builder.query("deleted_conflicts", String.valueOf(getDesignDocumentOptions.deletedConflicts()));
    }
    if (getDesignDocumentOptions.latest() != null) {
        builder.query("latest", String.valueOf(getDesignDocumentOptions.latest()));
    }
    if (getDesignDocumentOptions.localSeq() != null) {
        builder.query("local_seq", String.valueOf(getDesignDocumentOptions.localSeq()));
    }
    if (getDesignDocumentOptions.meta() != null) {
        builder.query("meta", String.valueOf(getDesignDocumentOptions.meta()));
    }
    if (getDesignDocumentOptions.rev() != null) {
        builder.query("rev", String.valueOf(getDesignDocumentOptions.rev()));
    }
    if (getDesignDocumentOptions.revs() != null) {
        builder.query("revs", String.valueOf(getDesignDocumentOptions.revs()));
    }
    if (getDesignDocumentOptions.revsInfo() != null) {
        builder.query("revs_info", String.valueOf(getDesignDocumentOptions.revsInfo()));
    }
    ResponseConverter<DesignDocument> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<DesignDocument>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) DesignDocument(com.ibm.cloud.cloudant.v1.model.DesignDocument)

Example 50 with RequestBuilder

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

the class Cloudant method postAllDocsQueries.

/**
 * Multi-query the list of all documents in a database.
 *
 * Runs multiple queries using the primary index (all document IDs). Returns a JSON object that contains a list of
 * result objects, one for each query, with a structure equivalent to that of a single `_all_docs` request. This
 * enables you to request multiple queries in a single request, in place of multiple `POST /{db}/_all_docs` requests.
 *
 * @param postAllDocsQueriesOptions the {@link PostAllDocsQueriesOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link AllDocsQueriesResult}
 */
public ServiceCall<AllDocsQueriesResult> postAllDocsQueries(PostAllDocsQueriesOptions postAllDocsQueriesOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(postAllDocsQueriesOptions, "postAllDocsQueriesOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", postAllDocsQueriesOptions.db());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_all_docs/queries", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postAllDocsQueries");
    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(postAllDocsQueriesOptions.queries()));
    builder.bodyJson(contentJson);
    ResponseConverter<AllDocsQueriesResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<AllDocsQueriesResult>() {
    }.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) AllDocsQueriesResult(com.ibm.cloud.cloudant.v1.model.AllDocsQueriesResult)

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