Search in sources :

Example 21 with RequestBuilder

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

the class Cloudant method putDatabase.

/**
 * Create a database.
 *
 * @param putDatabaseOptions the {@link PutDatabaseOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link Ok}
 */
public ServiceCall<Ok> putDatabase(PutDatabaseOptions putDatabaseOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(putDatabaseOptions, "putDatabaseOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", putDatabaseOptions.db());
    RequestBuilder builder = RequestBuilder.put(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "putDatabase");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    if (putDatabaseOptions.partitioned() != null) {
        builder.query("partitioned", String.valueOf(putDatabaseOptions.partitioned()));
    }
    if (putDatabaseOptions.q() != null) {
        builder.query("q", String.valueOf(putDatabaseOptions.q()));
    }
    ResponseConverter<Ok> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Ok>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) Ok(com.ibm.cloud.cloudant.v1.model.Ok)

Example 22 with RequestBuilder

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

the class Cloudant method putLocalDocument.

/**
 * Create or modify a local document.
 *
 * Stores the specified local document. The semantics are identical to storing a standard document in the specified
 * database, except that the document is not replicated.
 *
 * @param putLocalDocumentOptions the {@link PutLocalDocumentOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link DocumentResult}
 */
public ServiceCall<DocumentResult> putLocalDocument(PutLocalDocumentOptions putLocalDocumentOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(putLocalDocumentOptions, "putLocalDocumentOptions cannot be null");
    if (putLocalDocumentOptions.document() != null && putLocalDocumentOptions.contentType() == null) {
        putLocalDocumentOptions = putLocalDocumentOptions.newBuilder().contentType("application/json").build();
    }
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", putLocalDocumentOptions.db());
    pathParamsMap.put("doc_id", putLocalDocumentOptions.docId());
    RequestBuilder builder = RequestBuilder.put(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_local/{doc_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "putLocalDocument");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    if (putLocalDocumentOptions.contentType() != null) {
        builder.header("Content-Type", putLocalDocumentOptions.contentType());
    }
    if (putLocalDocumentOptions.batch() != null) {
        builder.query("batch", String.valueOf(putLocalDocumentOptions.batch()));
    }
    builder.bodyContent(putLocalDocumentOptions.contentType(), putLocalDocumentOptions.document(), null, putLocalDocumentOptions.body());
    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 23 with RequestBuilder

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

the class Cloudant method getReplicationDocument.

/**
 * Retrieve a replication document.
 *
 * Retrieves a replication document from the `_replicator` database to view the configuration of the replication. The
 * status of the replication is no longer recorded in the document but can be checked via the replication scheduler.
 *
 * @param getReplicationDocumentOptions the {@link GetReplicationDocumentOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link ReplicationDocument}
 */
public ServiceCall<ReplicationDocument> getReplicationDocument(GetReplicationDocumentOptions getReplicationDocumentOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getReplicationDocumentOptions, "getReplicationDocumentOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("doc_id", getReplicationDocumentOptions.docId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_replicator/{doc_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getReplicationDocument");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    if (getReplicationDocumentOptions.ifNoneMatch() != null) {
        builder.header("If-None-Match", getReplicationDocumentOptions.ifNoneMatch());
    }
    if (getReplicationDocumentOptions.attachments() != null) {
        builder.query("attachments", String.valueOf(getReplicationDocumentOptions.attachments()));
    }
    if (getReplicationDocumentOptions.attEncodingInfo() != null) {
        builder.query("att_encoding_info", String.valueOf(getReplicationDocumentOptions.attEncodingInfo()));
    }
    if (getReplicationDocumentOptions.conflicts() != null) {
        builder.query("conflicts", String.valueOf(getReplicationDocumentOptions.conflicts()));
    }
    if (getReplicationDocumentOptions.deletedConflicts() != null) {
        builder.query("deleted_conflicts", String.valueOf(getReplicationDocumentOptions.deletedConflicts()));
    }
    if (getReplicationDocumentOptions.latest() != null) {
        builder.query("latest", String.valueOf(getReplicationDocumentOptions.latest()));
    }
    if (getReplicationDocumentOptions.localSeq() != null) {
        builder.query("local_seq", String.valueOf(getReplicationDocumentOptions.localSeq()));
    }
    if (getReplicationDocumentOptions.meta() != null) {
        builder.query("meta", String.valueOf(getReplicationDocumentOptions.meta()));
    }
    if (getReplicationDocumentOptions.rev() != null) {
        builder.query("rev", String.valueOf(getReplicationDocumentOptions.rev()));
    }
    if (getReplicationDocumentOptions.revs() != null) {
        builder.query("revs", String.valueOf(getReplicationDocumentOptions.revs()));
    }
    if (getReplicationDocumentOptions.revsInfo() != null) {
        builder.query("revs_info", String.valueOf(getReplicationDocumentOptions.revsInfo()));
    }
    ResponseConverter<ReplicationDocument> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<ReplicationDocument>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) ReplicationDocument(com.ibm.cloud.cloudant.v1.model.ReplicationDocument)

Example 24 with RequestBuilder

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

the class Cloudant method getMembershipInformation.

/**
 * Retrieve cluster membership information.
 *
 * Displays the nodes that are part of the cluster as `cluster_nodes`. The field, `all_nodes`, displays all nodes this
 * node knows about, including the ones that are part of the cluster. This endpoint is useful when you set up a
 * cluster.
 *
 * @param getMembershipInformationOptions the {@link GetMembershipInformationOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link MembershipInformation}
 */
public ServiceCall<MembershipInformation> getMembershipInformation(GetMembershipInformationOptions getMembershipInformationOptions) {
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_membership"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getMembershipInformation");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    ResponseConverter<MembershipInformation> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<MembershipInformation>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) MembershipInformation(com.ibm.cloud.cloudant.v1.model.MembershipInformation)

Example 25 with RequestBuilder

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

the class Cloudant method postPartitionFindAsStream.

/**
 * Query a database partition index by using selector syntax (POST) as stream.
 *
 * Query documents by using a declarative JSON querying syntax. Queries can use the built-in `_all_docs` index or
 * custom indices, specified by using the `_index` endpoint.
 *
 * @param postPartitionFindOptions the {@link PostPartitionFindOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link InputStream}
 */
public ServiceCall<InputStream> postPartitionFindAsStream(PostPartitionFindOptions postPartitionFindOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(postPartitionFindOptions, "postPartitionFindOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", postPartitionFindOptions.db());
    pathParamsMap.put("partition_key", postPartitionFindOptions.partitionKey());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_partition/{partition_key}/_find", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postPartitionFindAsStream");
    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("selector", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postPartitionFindOptions.selector()));
    if (postPartitionFindOptions.bookmark() != null) {
        contentJson.addProperty("bookmark", postPartitionFindOptions.bookmark());
    }
    if (postPartitionFindOptions.conflicts() != null) {
        contentJson.addProperty("conflicts", postPartitionFindOptions.conflicts());
    }
    if (postPartitionFindOptions.executionStats() != null) {
        contentJson.addProperty("execution_stats", postPartitionFindOptions.executionStats());
    }
    if (postPartitionFindOptions.fields() != null) {
        contentJson.add("fields", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postPartitionFindOptions.fields()));
    }
    if (postPartitionFindOptions.limit() != null) {
        contentJson.addProperty("limit", postPartitionFindOptions.limit());
    }
    if (postPartitionFindOptions.skip() != null) {
        contentJson.addProperty("skip", postPartitionFindOptions.skip());
    }
    if (postPartitionFindOptions.sort() != null) {
        contentJson.add("sort", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postPartitionFindOptions.sort()));
    }
    if (postPartitionFindOptions.stable() != null) {
        contentJson.addProperty("stable", postPartitionFindOptions.stable());
    }
    if (postPartitionFindOptions.update() != null) {
        contentJson.addProperty("update", postPartitionFindOptions.update());
    }
    if (postPartitionFindOptions.useIndex() != null) {
        contentJson.add("use_index", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postPartitionFindOptions.useIndex()));
    }
    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)

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