public class CommandApiAccessorImpl extends java.lang.Object implements CommandApiAccessor
Modifier | Constructor and Description |
---|---|
protected |
CommandApiAccessorImpl(java.lang.String apiKey,
java.lang.String apiUrl)
Instantiates a new Abstract api client delegate.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
protected <T> HttpResult<T> |
createAndTransform(java.lang.String uri,
AbstractEntityData entityData,
SDKFunction<JSONObject,T> convertFunction)
Create and transform.
|
protected <K,T> HttpResult<T> |
createAndTransform(java.lang.String uri,
AbstractEntityData entityData,
SDKThrowableFunction<com.squareup.okhttp.ResponseBody,K,java.lang.Exception> convertFunction,
SDKFunction<K,T> buildFunction)
Create and transform convenience method.
|
protected <T> HttpResult<T> |
createAndTransform(java.lang.String uri,
RequestDescription requestDescription,
SDKFunction<JSONObject,T> convertFunction)
Create and transform convenience method.
|
protected <T> HttpResult<T> |
getAndTransform(java.lang.String uri,
RequestDescription requestDescription,
SDKFunction<JSONObject,T> convertFunction)
Gets and transform.
|
protected <T> HttpResult<T> |
getAndTransformByteArray(java.lang.String uri,
RequestDescription requestDescription,
SDKFunction<byte[],T> convertFunction)
Gets and transform byte array.
|
protected <T> HttpResult<java.util.List<T>> |
getAndTransformToList(java.lang.String uri,
RequestDescription requestDescription,
int[] expectedStatuses,
java.lang.String jsonEntry,
SDKFunction<JSONObject,T> function) |
protected <K,T> HttpResult<T> |
getAndTransformToList(java.lang.String uri,
RequestDescription requestDescription,
SDKThrowableFunction<com.squareup.okhttp.ResponseBody,K,java.lang.Exception> convertFunction,
SDKFunction<K,T> buildFunction)
Gets and transform to list convenience method.
|
protected <T> HttpResult<java.util.List<T>> |
getAndTransformToList(java.lang.String uri,
RequestDescription requestDescription,
java.lang.String jsonEntry,
SDKFunction<JSONObject,T> function)
Gets and transform to list.
|
HttpResult<java.util.List<SecureCommandResponse>> |
getSecureCommand(java.util.Collection<java.lang.String> beaconUniqueIds,
SecureCommandType secureCommandType) |
void |
getSecureCommand(java.util.Collection<java.lang.String> beaconUniqueIds,
SecureCommandType secureCommandType,
ResultApiCallback<java.util.List<SecureCommandResponse>> apiCallback) |
protected static int |
httpStatusCode(com.squareup.okhttp.Response httpResponse)
Returns http status code from HTTP response and closes it quietly.
|
protected int |
postAndReturnHttpStatus(java.lang.String uri,
RequestDescription requestDescription)
Post and return http status convenience method.
|
protected <T> HttpResult<java.util.List<T>> |
postAndTransformToList(java.lang.String uri,
RequestDescription requestDescription,
int[] expectedStatuses,
java.lang.String jsonEntry,
SDKFunction<JSONObject,T> function) |
protected <T> HttpResult<T> |
selectFirstOrReturnAbsent(HttpResult<java.util.List<T>> listedRecordsResult,
SDKPredicate<T> predicate)
Select first or return absent.
|
protected static <K,T> HttpResult<T> |
transform(com.squareup.okhttp.Response response,
int[] expectedSuccessHttpStatus,
SDKThrowableFunction<com.squareup.okhttp.ResponseBody,K,java.lang.Exception> extractFunction,
SDKFunction<K,T> buildFunction)
Transforms Http Response to desired entity by extracting the content to desired format and then to build the
entity from it provided that Http Response status is equal to the expected one.
|
protected static <T> HttpResult<T> |
transformByteArrayToHttpResult(com.squareup.okhttp.Response response,
int expectedSuccessHttpStatus,
SDKFunction<byte[],T> buildFunction)
Transforms Http Response's entity to byte array and then converts to desired type.
|
protected static <T> HttpResult<T> |
transformJSONToEntity(com.squareup.okhttp.Response response,
int expectedSuccessHttpStatus,
SDKFunction<JSONObject,T> buildFunction)
Transforms Http Response's body to
JSONObject and then converts to
desired type. |
protected static <T> HttpResult<java.util.List<T>> |
transformJSONToList(com.squareup.okhttp.Response response,
int[] expectedSucceddHttpStatuses,
java.lang.String jsonEntry,
SDKFunction<JSONObject,T> buildFunction) |
protected static <T> HttpResult<java.util.List<T>> |
transformJSONToList(com.squareup.okhttp.Response httpResponse,
int expectedSuccessHttpStatus,
java.lang.String jsonEntry,
SDKFunction<JSONObject,T> buildFunction)
Transform HttpResponse with JSON content to list.
|
protected CommandApiAccessorImpl(java.lang.String apiKey, java.lang.String apiUrl)
apiKey
- the api keyapiUrl
- the api urlpublic HttpResult<java.util.List<SecureCommandResponse>> getSecureCommand(java.util.Collection<java.lang.String> beaconUniqueIds, SecureCommandType secureCommandType) throws ClientException
getSecureCommand
in interface CommandApiAccessor
ClientException
public void getSecureCommand(java.util.Collection<java.lang.String> beaconUniqueIds, SecureCommandType secureCommandType, ResultApiCallback<java.util.List<SecureCommandResponse>> apiCallback)
getSecureCommand
in interface CommandApiAccessor
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
protected static <T> HttpResult<T> transformJSONToEntity(com.squareup.okhttp.Response response, int expectedSuccessHttpStatus, SDKFunction<JSONObject,T> buildFunction) throws ClientException
org.json.JSONObject
and then converts to
desired type.T
- the type parameterresponse
- the responseexpectedSuccessHttpStatus
- the expected success http statusbuildFunction
- the build functionClientException
- the client exceptionprotected static <T> HttpResult<java.util.List<T>> transformJSONToList(com.squareup.okhttp.Response httpResponse, int expectedSuccessHttpStatus, java.lang.String jsonEntry, SDKFunction<JSONObject,T> buildFunction)
T
- the type parameterhttpResponse
- the http responseexpectedSuccessHttpStatus
- the expected success http statusjsonEntry
- the json entrybuildFunction
- the build functionprotected static <T> HttpResult<java.util.List<T>> transformJSONToList(com.squareup.okhttp.Response response, int[] expectedSucceddHttpStatuses, java.lang.String jsonEntry, SDKFunction<JSONObject,T> buildFunction)
protected static <T> HttpResult<T> transformByteArrayToHttpResult(com.squareup.okhttp.Response response, int expectedSuccessHttpStatus, SDKFunction<byte[],T> buildFunction) throws ClientException
T
- the type parameterresponse
- the responseexpectedSuccessHttpStatus
- the expected success http statusbuildFunction
- the build functionClientException
- the client exceptionprotected static <K,T> HttpResult<T> transform(com.squareup.okhttp.Response response, int[] expectedSuccessHttpStatus, SDKThrowableFunction<com.squareup.okhttp.ResponseBody,K,java.lang.Exception> extractFunction, SDKFunction<K,T> buildFunction) throws ClientException
K
- the generic extract parameterT
- the generic build parameterresponse
- the responseexpectedSuccessHttpStatus
- the expected success http statusextractFunction
- the extract functionbuildFunction
- the build functionClientException
- thrown if transformation fails.protected static int httpStatusCode(com.squareup.okhttp.Response httpResponse)
httpResponse
- the http responseprotected <T> HttpResult<T> getAndTransform(java.lang.String uri, RequestDescription requestDescription, SDKFunction<JSONObject,T> convertFunction) throws ClientException
uri
- the urirequestDescription
- the request descriptionconvertFunction
- the convert functionClientException
- the client exceptionprotected <T> HttpResult<T> getAndTransformByteArray(java.lang.String uri, RequestDescription requestDescription, SDKFunction<byte[],T> convertFunction) throws ClientException
uri
- the urirequestDescription
- the request descriptionconvertFunction
- the convert functionClientException
- the client exceptionprotected <T> HttpResult<T> selectFirstOrReturnAbsent(HttpResult<java.util.List<T>> listedRecordsResult, SDKPredicate<T> predicate)
T
- the type parameterlistedRecordsResult
- the listed records resultpredicate
- the predicateprotected <T> HttpResult<java.util.List<T>> getAndTransformToList(java.lang.String uri, RequestDescription requestDescription, java.lang.String jsonEntry, SDKFunction<JSONObject,T> function) throws ClientException
uri
- the urirequestDescription
- the request descriptionjsonEntry
- the json entryfunction
- the functionClientException
- the client exceptionprotected <T> HttpResult<java.util.List<T>> getAndTransformToList(java.lang.String uri, RequestDescription requestDescription, int[] expectedStatuses, java.lang.String jsonEntry, SDKFunction<JSONObject,T> function) throws ClientException
ClientException
protected <T> HttpResult<java.util.List<T>> postAndTransformToList(java.lang.String uri, RequestDescription requestDescription, int[] expectedStatuses, java.lang.String jsonEntry, SDKFunction<JSONObject,T> function) throws ClientException
ClientException
protected <T> HttpResult<T> createAndTransform(java.lang.String uri, AbstractEntityData entityData, SDKFunction<JSONObject,T> convertFunction) throws ClientException
T
- the type parameteruri
- the urientityData
- the entity dataconvertFunction
- the convert functionClientException
- the client exceptionprotected <T> HttpResult<T> createAndTransform(java.lang.String uri, RequestDescription requestDescription, SDKFunction<JSONObject,T> convertFunction) throws ClientException
T
- the type parameteruri
- the urirequestDescription
- the request descriptionconvertFunction
- the convert functionClientException
- the client exceptionprotected <K,T> HttpResult<T> createAndTransform(java.lang.String uri, AbstractEntityData entityData, SDKThrowableFunction<com.squareup.okhttp.ResponseBody,K,java.lang.Exception> convertFunction, SDKFunction<K,T> buildFunction) throws ClientException
K
- the type parameterT
- the type parameteruri
- the urientityData
- the entity dataconvertFunction
- the convert functionbuildFunction
- the build functionClientException
- the client exceptionprotected <K,T> HttpResult<T> getAndTransformToList(java.lang.String uri, RequestDescription requestDescription, SDKThrowableFunction<com.squareup.okhttp.ResponseBody,K,java.lang.Exception> convertFunction, SDKFunction<K,T> buildFunction) throws ClientException
uri
- the urirequestDescription
- the request descriptionconvertFunction
- the convert functionbuildFunction
- the build functionClientException
- the client exceptionprotected int postAndReturnHttpStatus(java.lang.String uri, RequestDescription requestDescription) throws ClientException
uri
- the urirequestDescription
- the request descriptionClientException
- the client exception