use of com.ibm.cloud.cloudant.v1.model.Ok in project cloudant-java-sdk by IBM.
the class Cloudant method postActivityTrackerEvents.
/**
* Modify Activity Tracker events configuration.
*
* Configure event types that are being sent to IBM Cloud Activity Tracker for the IBM Cloudant instance.
*
* @param postActivityTrackerEventsOptions the {@link PostActivityTrackerEventsOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link Ok}
*/
public ServiceCall<Ok> postActivityTrackerEvents(PostActivityTrackerEventsOptions postActivityTrackerEventsOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(postActivityTrackerEventsOptions, "postActivityTrackerEventsOptions cannot be null");
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_api/v2/user/activity_tracker/events"));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postActivityTrackerEvents");
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("types", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(postActivityTrackerEventsOptions.types()));
builder.bodyJson(contentJson);
ResponseConverter<Ok> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Ok>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.cloud.cloudant.v1.model.Ok in project cloudant-java-sdk by IBM.
the class Cloudant method deleteIndex.
/**
* Delete an index.
*
* @param deleteIndexOptions the {@link DeleteIndexOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link Ok}
*/
public ServiceCall<Ok> deleteIndex(DeleteIndexOptions deleteIndexOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(deleteIndexOptions, "deleteIndexOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", deleteIndexOptions.db());
pathParamsMap.put("ddoc", deleteIndexOptions.ddoc());
pathParamsMap.put("type", deleteIndexOptions.type());
pathParamsMap.put("index", deleteIndexOptions.index());
RequestBuilder builder = RequestBuilder.delete(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_index/_design/{ddoc}/{type}/{index}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "deleteIndex");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
ResponseConverter<Ok> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Ok>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.cloud.cloudant.v1.model.Ok 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);
}
use of com.ibm.cloud.cloudant.v1.model.Ok 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);
}
use of com.ibm.cloud.cloudant.v1.model.Ok in project cloudant-java-sdk by IBM.
the class CloudantTest method testDeleteDesignDocumentWOptions.
@Test
public void testDeleteDesignDocumentWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"id\": \"id\", \"rev\": \"rev\", \"ok\": true, \"caused_by\": \"causedBy\", \"error\": \"error\", \"reason\": \"reason\"}";
String deleteDesignDocumentPath = "/testString/_design/testString";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the DeleteDesignDocumentOptions model
DeleteDesignDocumentOptions deleteDesignDocumentOptionsModel = new DeleteDesignDocumentOptions.Builder().db("testString").ddoc("testString").ifMatch("testString").batch("ok").rev("testString").build();
// Invoke operation with valid options model (positive test)
Response<DocumentResult> response = cloudantService.deleteDesignDocument(deleteDesignDocumentOptionsModel).execute();
assertNotNull(response);
DocumentResult responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "DELETE");
// Check query
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
// Get query params
assertEquals(query.get("batch"), "ok");
assertEquals(query.get("rev"), "testString");
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, deleteDesignDocumentPath);
}
Aggregations