Search in sources :

Example 26 with RequestBuilder

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

the class Cloudant method getIndexesInformation.

/**
 * Retrieve information about all indexes.
 *
 * When you make a GET request to `/db/_index`, you get a list of all indexes used by Cloudant Query in the database,
 * including the primary index. In addition to the information available through this API, indexes are also stored in
 * the `indexes` property of design documents.
 *
 * @param getIndexesInformationOptions the {@link GetIndexesInformationOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link IndexesInformation}
 */
public ServiceCall<IndexesInformation> getIndexesInformation(GetIndexesInformationOptions getIndexesInformationOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getIndexesInformationOptions, "getIndexesInformationOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", getIndexesInformationOptions.db());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_index", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getIndexesInformation");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    ResponseConverter<IndexesInformation> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<IndexesInformation>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) IndexesInformation(com.ibm.cloud.cloudant.v1.model.IndexesInformation)

Example 27 with RequestBuilder

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

the class Cloudant method postAllDocsAsStream.

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

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

the class Cloudant method getSchedulerJobs.

/**
 * Retrieve replication scheduler jobs.
 *
 * Retrieves information about replications that were created via `/_replicate` endpoint, as well as those created
 * from replication documents. It doesn't include replications that completed or failed to start because replication
 * documents were malformed. Each job description includes source and target information, replication ID, history of
 * recent events, and other information.
 *
 * @param getSchedulerJobsOptions the {@link GetSchedulerJobsOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link SchedulerJobsResult}
 */
public ServiceCall<SchedulerJobsResult> getSchedulerJobs(GetSchedulerJobsOptions getSchedulerJobsOptions) {
    if (getSchedulerJobsOptions == null) {
        getSchedulerJobsOptions = new GetSchedulerJobsOptions.Builder().build();
    }
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_scheduler/jobs"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getSchedulerJobs");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    if (getSchedulerJobsOptions.limit() != null) {
        builder.query("limit", String.valueOf(getSchedulerJobsOptions.limit()));
    }
    if (getSchedulerJobsOptions.skip() != null) {
        builder.query("skip", String.valueOf(getSchedulerJobsOptions.skip()));
    }
    ResponseConverter<SchedulerJobsResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<SchedulerJobsResult>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) SchedulerJobsResult(com.ibm.cloud.cloudant.v1.model.SchedulerJobsResult)

Example 29 with RequestBuilder

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

the class Cloudant method putCorsConfiguration.

/**
 * Modify CORS configuration.
 *
 * Sets the CORS configuration. The configuration applies to all databases and all account level endpoints in your
 * account.
 *
 * @param putCorsConfigurationOptions the {@link PutCorsConfigurationOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link Ok}
 */
public ServiceCall<Ok> putCorsConfiguration(PutCorsConfigurationOptions putCorsConfigurationOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(putCorsConfigurationOptions, "putCorsConfigurationOptions cannot be null");
    RequestBuilder builder = RequestBuilder.put(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_api/v2/user/config/cors"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "putCorsConfiguration");
    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("origins", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(putCorsConfigurationOptions.origins()));
    if (putCorsConfigurationOptions.allowCredentials() != null) {
        contentJson.addProperty("allow_credentials", putCorsConfigurationOptions.allowCredentials());
    }
    if (putCorsConfigurationOptions.enableCors() != null) {
        contentJson.addProperty("enable_cors", putCorsConfigurationOptions.enableCors());
    }
    builder.bodyJson(contentJson);
    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) JsonObject(com.google.gson.JsonObject) Ok(com.ibm.cloud.cloudant.v1.model.Ok)

Example 30 with RequestBuilder

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

the class Cloudant method headSchedulerDocument.

/**
 * Retrieve HTTP headers for a replication scheduler document.
 *
 * Retrieves the HTTP headers containing minimal amount of information about the specified replication scheduler
 * document.  Since the response body is empty, using the HEAD method is a lightweight way to check if the replication
 * scheduler document exists or not.
 *
 * @param headSchedulerDocumentOptions the {@link HeadSchedulerDocumentOptions} containing the options for the call
 * @return a {@link ServiceCall} with a void result
 */
public ServiceCall<Void> headSchedulerDocument(HeadSchedulerDocumentOptions headSchedulerDocumentOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(headSchedulerDocumentOptions, "headSchedulerDocumentOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("doc_id", headSchedulerDocumentOptions.docId());
    RequestBuilder builder = RequestBuilder.head(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_scheduler/docs/_replicator/{doc_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "headSchedulerDocument");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    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