use of com.ibm.cloud.sdk.core.http.RequestBuilder in project cloudant-java-sdk by IBM.
the class Cloudant method postDocument.
/**
* Create or modify a document in a database.
*
* Creates or modifies a document in the specified database by using the supplied JSON document. If the JSON document
* doesn't specify an `_id` field, then the document is created with a new unique ID generated by the UUID algorithm
* that is configured for the server. If the document includes the `_id` field, then it is created with that `_id` or
* updated if the `_id` already exists, and an appropriate `_rev` is included in the JSON document. If the `_id`
* includes the `_local` or `_design` prefix, then this operation is used to create or modify local or design
* documents respectively.
*
* @param postDocumentOptions the {@link PostDocumentOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link DocumentResult}
*/
public ServiceCall<DocumentResult> postDocument(PostDocumentOptions postDocumentOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(postDocumentOptions, "postDocumentOptions cannot be null");
if (postDocumentOptions.document() != null && postDocumentOptions.contentType() == null) {
postDocumentOptions = postDocumentOptions.newBuilder().contentType("application/json").build();
}
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", postDocumentOptions.db());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "postDocument");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
if (postDocumentOptions.contentType() != null) {
builder.header("Content-Type", postDocumentOptions.contentType());
}
if (postDocumentOptions.batch() != null) {
builder.query("batch", String.valueOf(postDocumentOptions.batch()));
}
builder.bodyContent(postDocumentOptions.contentType(), postDocumentOptions.document(), null, postDocumentOptions.body());
ResponseConverter<DocumentResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<DocumentResult>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.cloud.sdk.core.http.RequestBuilder in project cloudant-java-sdk by IBM.
the class Cloudant method deleteDocument.
/**
* Delete a document.
*
* Marks the specified document as deleted by adding a `_deleted` field with the value `true`. Documents with this
* field are not returned within requests anymore but stay in the database. You must supply the current (latest)
* revision, either by using the `rev` parameter or by using the `If-Match` header to specify the revision.
*
* @param deleteDocumentOptions the {@link DeleteDocumentOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link DocumentResult}
*/
public ServiceCall<DocumentResult> deleteDocument(DeleteDocumentOptions deleteDocumentOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(deleteDocumentOptions, "deleteDocumentOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", deleteDocumentOptions.db());
pathParamsMap.put("doc_id", deleteDocumentOptions.docId());
RequestBuilder builder = RequestBuilder.delete(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/{doc_id}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "deleteDocument");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
if (deleteDocumentOptions.ifMatch() != null) {
builder.header("If-Match", deleteDocumentOptions.ifMatch());
}
if (deleteDocumentOptions.batch() != null) {
builder.query("batch", String.valueOf(deleteDocumentOptions.batch()));
}
if (deleteDocumentOptions.rev() != null) {
builder.query("rev", String.valueOf(deleteDocumentOptions.rev()));
}
ResponseConverter<DocumentResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<DocumentResult>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.cloud.sdk.core.http.RequestBuilder in project cloudant-java-sdk by IBM.
the class Cloudant method getDocumentAsStream.
/**
* Retrieve a document as stream.
*
* Returns document with the specified `doc_id` from the specified database. Unless you request a specific revision,
* the latest revision of the document is always returned.
*
* @param getDocumentOptions the {@link GetDocumentOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link InputStream}
*/
public ServiceCall<InputStream> getDocumentAsStream(GetDocumentOptions getDocumentOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(getDocumentOptions, "getDocumentOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", getDocumentOptions.db());
pathParamsMap.put("doc_id", getDocumentOptions.docId());
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/{doc_id}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getDocumentAsStream");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
if (getDocumentOptions.ifNoneMatch() != null) {
builder.header("If-None-Match", getDocumentOptions.ifNoneMatch());
}
if (getDocumentOptions.attachments() != null) {
builder.query("attachments", String.valueOf(getDocumentOptions.attachments()));
}
if (getDocumentOptions.attEncodingInfo() != null) {
builder.query("att_encoding_info", String.valueOf(getDocumentOptions.attEncodingInfo()));
}
if (getDocumentOptions.conflicts() != null) {
builder.query("conflicts", String.valueOf(getDocumentOptions.conflicts()));
}
if (getDocumentOptions.deletedConflicts() != null) {
builder.query("deleted_conflicts", String.valueOf(getDocumentOptions.deletedConflicts()));
}
if (getDocumentOptions.latest() != null) {
builder.query("latest", String.valueOf(getDocumentOptions.latest()));
}
if (getDocumentOptions.localSeq() != null) {
builder.query("local_seq", String.valueOf(getDocumentOptions.localSeq()));
}
if (getDocumentOptions.meta() != null) {
builder.query("meta", String.valueOf(getDocumentOptions.meta()));
}
if (getDocumentOptions.rev() != null) {
builder.query("rev", String.valueOf(getDocumentOptions.rev()));
}
if (getDocumentOptions.revs() != null) {
builder.query("revs", String.valueOf(getDocumentOptions.revs()));
}
if (getDocumentOptions.revsInfo() != null) {
builder.query("revs_info", String.valueOf(getDocumentOptions.revsInfo()));
}
ResponseConverter<InputStream> responseConverter = ResponseConverterUtils.getInputStream();
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.cloud.sdk.core.http.RequestBuilder in project cloudant-java-sdk by IBM.
the class Cloudant method getSessionInformation.
/**
* Retrieve current session cookie information.
*
* Retrieves information about the authenticated user's session.
*
* @param getSessionInformationOptions the {@link GetSessionInformationOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link SessionInformation}
*/
public ServiceCall<SessionInformation> getSessionInformation(GetSessionInformationOptions getSessionInformationOptions) {
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_session"));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "getSessionInformation");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
ResponseConverter<SessionInformation> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<SessionInformation>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.cloud.sdk.core.http.RequestBuilder in project cloudant-java-sdk by IBM.
the class Cloudant method deleteDesignDocument.
/**
* Delete a design document.
*
* Marks the specified design document as deleted by adding a `_deleted` field with the value `true`. Documents with
* this field are not returned with requests but stay in the database. You must supply the current (latest) revision,
* either by using the `rev` parameter or by using the `If-Match` header to specify the revision.
*
* @param deleteDesignDocumentOptions the {@link DeleteDesignDocumentOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link DocumentResult}
*/
public ServiceCall<DocumentResult> deleteDesignDocument(DeleteDesignDocumentOptions deleteDesignDocumentOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(deleteDesignDocumentOptions, "deleteDesignDocumentOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", deleteDesignDocumentOptions.db());
pathParamsMap.put("ddoc", deleteDesignDocumentOptions.ddoc());
RequestBuilder builder = RequestBuilder.delete(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/{db}/_design/{ddoc}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "deleteDesignDocument");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
if (deleteDesignDocumentOptions.ifMatch() != null) {
builder.header("If-Match", deleteDesignDocumentOptions.ifMatch());
}
if (deleteDesignDocumentOptions.batch() != null) {
builder.query("batch", String.valueOf(deleteDesignDocumentOptions.batch()));
}
if (deleteDesignDocumentOptions.rev() != null) {
builder.query("rev", String.valueOf(deleteDesignDocumentOptions.rev()));
}
ResponseConverter<DocumentResult> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<DocumentResult>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
Aggregations