Search in sources :

Example 16 with Cloudant

use of com.ibm.cloud.cloudant.v1.Cloudant 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 17 with Cloudant

use of com.ibm.cloud.cloudant.v1.Cloudant 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 18 with Cloudant

use of com.ibm.cloud.cloudant.v1.Cloudant 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 19 with Cloudant

use of com.ibm.cloud.cloudant.v1.Cloudant 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 20 with Cloudant

use of com.ibm.cloud.cloudant.v1.Cloudant in project cloudant-java-sdk by IBM.

the class Cloudant method getCorsInformation.

/**
 * Retrieve CORS configuration information.
 *
 * Lists all Cross-origin resource sharing (CORS) configuration. CORS defines a way in which the browser and the
 * server interact to determine whether or not to allow the request.
 *
 * @param getCorsInformationOptions the {@link GetCorsInformationOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link CorsInformation}
 */
public ServiceCall<CorsInformation> getCorsInformation(GetCorsInformationOptions getCorsInformationOptions) {
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_api/v2/user/config/cors"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getCorsInformation");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    ResponseConverter<CorsInformation> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<CorsInformation>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : CorsInformation(com.ibm.cloud.cloudant.v1.model.CorsInformation) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder)

Aggregations

RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)70 HashMap (java.util.HashMap)51 JsonObject (com.google.gson.JsonObject)23 DocumentResult (com.ibm.cloud.cloudant.v1.model.DocumentResult)17 Ok (com.ibm.cloud.cloudant.v1.model.Ok)11 Document (com.ibm.cloud.cloudant.v1.model.Document)9 List (java.util.List)8 AllDocsResult (com.ibm.cloud.cloudant.v1.model.AllDocsResult)6 NotFoundException (com.ibm.cloud.sdk.core.service.exception.NotFoundException)6 ArrayList (java.util.ArrayList)6 Cloudant (com.ibm.cloud.cloudant.v1.Cloudant)5 SecurityObject (com.ibm.cloud.cloudant.v1.model.SecurityObject)5 Test (org.testng.annotations.Test)5 DesignDocument (com.ibm.cloud.cloudant.v1.model.DesignDocument)3 GetDocumentOptions (com.ibm.cloud.cloudant.v1.model.GetDocumentOptions)3 PostAllDocsOptions (com.ibm.cloud.cloudant.v1.model.PostAllDocsOptions)3 PostDocumentOptions (com.ibm.cloud.cloudant.v1.model.PostDocumentOptions)3 ReplicationDocument (com.ibm.cloud.cloudant.v1.model.ReplicationDocument)3 MockResponse (okhttp3.mockwebserver.MockResponse)3 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3