Package cloud.genesys.webmessaging.sdk
Class ApiClient
- java.lang.Object
-
- cloud.genesys.webmessaging.sdk.ApiClient
-
- All Implemented Interfaces:
AutoCloseable
public class ApiClient extends Object implements AutoCloseable
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classApiClient.Builderstatic classApiClient.Retrystatic classApiClient.RetryConfiguration
-
Constructor Summary
Constructors Constructor Description ApiClient()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static com.fasterxml.jackson.databind.ObjectMapperbuildObjectMapper(DateFormat dateFormat)voidclose()<T> Tdeserialize(String obj, Class<T> type)Deserialize the string into the provided typeStringescapeString(String str)Escape the given string to be used as URL query value.StringformatDate(Date date)Format the given Date object into string.StringgetBasePath()intgetConnectTimeout()Connect timeout (in milliseconds).com.fasterxml.jackson.databind.ObjectMappergetObjectMapper()booleangetShouldThrowErrors()<T> ApiResponse<T>invoke(ApiRequest<?> request, com.fasterxml.jackson.core.type.TypeReference<T> returnType)booleanisJsonMime(String mime)Check if the given MIME is a JSON MIME.List<Pair>parameterToPairs(String collectionFormat, String name, Object value)StringparameterToString(Object param)Format the given parameter object into string.DateparseDate(String str)Parse the given string into Date object.StringselectHeaderAccept(String[] accepts)Select the Accept header's value from the given accepts array: if JSON exists in the given array, use it; otherwise use all of them (joining into a string)StringselectHeaderContentType(String[] contentTypes)Select the Content-Type header's value from the given array: if JSON exists in the given array, use it; otherwise use the first one of the array.Stringserialize(Object obj)Serialize the given Java object into string according the given Content-Type (only JSON is supported for now).voidsetAccessToken(String accessToken)Helper method to set access token for the first OAuth2 authentication.
-
-
-
Method Detail
-
close
public void close() throws Exception- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
buildObjectMapper
public static com.fasterxml.jackson.databind.ObjectMapper buildObjectMapper(DateFormat dateFormat)
-
getShouldThrowErrors
public boolean getShouldThrowErrors()
-
getBasePath
public String getBasePath()
-
getObjectMapper
public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
-
setAccessToken
public void setAccessToken(String accessToken)
Helper method to set access token for the first OAuth2 authentication.
-
getConnectTimeout
public int getConnectTimeout()
Connect timeout (in milliseconds).
-
parameterToString
public String parameterToString(Object param)
Format the given parameter object into string.
-
parameterToPairs
public List<Pair> parameterToPairs(String collectionFormat, String name, Object value)
-
isJsonMime
public boolean isJsonMime(String mime)
Check if the given MIME is a JSON MIME. JSON MIME examples: application/json application/json; charset=UTF8 APPLICATION/JSON
-
selectHeaderAccept
public String selectHeaderAccept(String[] accepts)
Select the Accept header's value from the given accepts array: if JSON exists in the given array, use it; otherwise use all of them (joining into a string)- Parameters:
accepts- The accepts array to select from- Returns:
- The Accept header to use. If the given array is empty, null will be returned (not to set the Accept header explicitly).
-
selectHeaderContentType
public String selectHeaderContentType(String[] contentTypes)
Select the Content-Type header's value from the given array: if JSON exists in the given array, use it; otherwise use the first one of the array.- Parameters:
contentTypes- The Content-Type array to select from- Returns:
- The Content-Type header to use. If the given array is empty, JSON will be used.
-
escapeString
public String escapeString(String str)
Escape the given string to be used as URL query value.
-
serialize
public String serialize(Object obj) throws IOException
Serialize the given Java object into string according the given Content-Type (only JSON is supported for now).- Throws:
IOException
-
deserialize
public <T> T deserialize(String obj, Class<T> type) throws IOException
Deserialize the string into the provided type- Parameters:
obj- the string to deserializetype- the target type for deserialization- Throws:
IOException
-
invoke
public <T> ApiResponse<T> invoke(ApiRequest<?> request, com.fasterxml.jackson.core.type.TypeReference<T> returnType) throws WebMessagingException, IOException
- Throws:
WebMessagingExceptionIOException
-
-