Search in sources :

Example 51 with Cloudant

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

the class Cloudant method postApiKeys.

/**
 * Generates API keys for apps or persons to enable database access.
 *
 * Generates API keys to enable database access for a person or application, but without creating a new IBM Cloudant
 * account for that person or application. An API key is a randomly generated username and password. The key is given
 * the wanted access permissions for a database.
 *
 * @param postApiKeysOptions the {@link PostApiKeysOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link ApiKeysResult}
 */
public ServiceCall<ApiKeysResult> postApiKeys(PostApiKeysOptions postApiKeysOptions) {
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_api/v2/api_keys"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postApiKeys");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    ResponseConverter<ApiKeysResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<ApiKeysResult>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : ApiKeysResult(com.ibm.cloud.cloudant.v1.model.ApiKeysResult) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder)

Example 52 with Cloudant

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

the class Cloudant method postFind.

/**
 * Query an index by using selector syntax.
 *
 * 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 postFindOptions the {@link PostFindOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link FindResult}
 */
public ServiceCall<FindResult> postFind(PostFindOptions postFindOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(postFindOptions, "postFindOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", postFindOptions.db());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_find", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postFind");
    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(postFindOptions.selector()));
    if (postFindOptions.bookmark() != null) {
        contentJson.addProperty("bookmark", postFindOptions.bookmark());
    }
    if (postFindOptions.conflicts() != null) {
        contentJson.addProperty("conflicts", postFindOptions.conflicts());
    }
    if (postFindOptions.executionStats() != null) {
        contentJson.addProperty("execution_stats", postFindOptions.executionStats());
    }
    if (postFindOptions.fields() != null) {
        contentJson.add("fields", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postFindOptions.fields()));
    }
    if (postFindOptions.limit() != null) {
        contentJson.addProperty("limit", postFindOptions.limit());
    }
    if (postFindOptions.skip() != null) {
        contentJson.addProperty("skip", postFindOptions.skip());
    }
    if (postFindOptions.sort() != null) {
        contentJson.add("sort", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postFindOptions.sort()));
    }
    if (postFindOptions.stable() != null) {
        contentJson.addProperty("stable", postFindOptions.stable());
    }
    if (postFindOptions.update() != null) {
        contentJson.addProperty("update", postFindOptions.update());
    }
    if (postFindOptions.useIndex() != null) {
        contentJson.add("use_index", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postFindOptions.useIndex()));
    }
    if (postFindOptions.r() != null) {
        contentJson.addProperty("r", postFindOptions.r());
    }
    builder.bodyJson(contentJson);
    ResponseConverter<FindResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<FindResult>() {
    }.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) FindResult(com.ibm.cloud.cloudant.v1.model.FindResult)

Example 53 with Cloudant

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

the class Cloudant method getGeoIndexInformation.

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

Example 54 with Cloudant

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

the class Cloudant method postBulkDocs.

/**
 * Bulk modify multiple documents in a database.
 *
 * The bulk document API allows you to create and update multiple documents at the same time within a single request.
 * The basic operation is similar to creating or updating a single document, except that you batch the document
 * structure and information.
 *
 * @param postBulkDocsOptions the {@link PostBulkDocsOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link List}
 */
public ServiceCall<List<DocumentResult>> postBulkDocs(PostBulkDocsOptions postBulkDocsOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(postBulkDocsOptions, "postBulkDocsOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("db", postBulkDocsOptions.db());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_bulk_docs", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postBulkDocs");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    builder.bodyContent("application/json", postBulkDocsOptions.bulkDocs(), null, postBulkDocsOptions.body());
    ResponseConverter<List<DocumentResult>> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<List<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) List(java.util.List)

Example 55 with Cloudant

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

the class Cloudant method postDbsInfo.

/**
 * Query information about multiple databases.
 *
 * This operation enables you to request information about multiple databases in a single request, instead of issuing
 * multiple `GET /{db}` requests. It returns a list that contains an information object for each database specified in
 * the request.
 *
 * @param postDbsInfoOptions the {@link PostDbsInfoOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link List}
 */
public ServiceCall<List<DbsInfoResult>> postDbsInfo(PostDbsInfoOptions postDbsInfoOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(postDbsInfoOptions, "postDbsInfoOptions cannot be null");
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_dbs_info"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postDbsInfo");
    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("keys", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postDbsInfoOptions.keys()));
    builder.bodyJson(contentJson);
    ResponseConverter<List<DbsInfoResult>> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<List<DbsInfoResult>>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : DbsInfoResult(com.ibm.cloud.cloudant.v1.model.DbsInfoResult) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) JsonObject(com.google.gson.JsonObject) List(java.util.List)

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