Package com.testdroid.api
Class AbstractAPIClient
java.lang.Object
com.testdroid.api.AbstractAPIClient
- All Implemented Interfaces:
APIClient
- Direct Known Subclasses:
APIKeyClient
- Author:
- MichaĆ Szpruta <[email protected]>
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final String
protected static final String
protected String
protected static final okhttp3.MediaType
protected int
protected int
protected static final String
protected static final okhttp3.MediaType
protected static final String
protected Proxy
protected String
protected String
protected boolean
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static okhttp3.RequestBody
buildFromMap
(Map map) void
Calls DELETE request to APIprotected void
deleteOnce
(String uri) findDevicePropertyInLabelGroup
(String groupName, String labelName) protected <T> T
fromJson
(InputStream inputStream, com.fasterxml.jackson.core.type.TypeReference<T> type) protected <T> T
Calls GET request to API.<T extends APIEntity>
TCalls GET request to APIprotected APIException
getAPIException
(okhttp3.Response response) protected final okhttp3.OkHttpClient
return resource for accessing list of devices in Cloud using provided filtersgetDevices
(Context<APIDevice> context) okhttp3.Response
getHttpResponse
(String uri, Context<?> context) protected abstract okhttp3.Interceptor
getLabelGroups
(Context<APILabelGroup> context) protected <T extends APIEntity>
TTries to call API once.protected InputStream
me()
Fetch and return me - the authenticated user.<T extends APIEntity>
TCalls POST request to API<T extends APIEntity>
TpostFile
(String uri, String contentType, File file, Map<String, String> fileExtraParams, Class<T> type) Calls POST request to APIprotected <T extends APIEntity>
TpostOnce
(String uri, Object body, Map<String, String> fileExtraParams, String contentType, com.fasterxml.jackson.core.type.TypeReference<T> type) void
setConnectTimeout
(int timeout) Sets establish connection timeout for APIClient requests.void
setRequestTimeout
(int timeout) Sets timeout for read data from established connection for APIClient requests.
-
Field Details
-
API_URI
- See Also:
-
ACCEPT_HEADER
- See Also:
-
APPLICATION_JSON
protected static final okhttp3.MediaType APPLICATION_JSON -
FORM_URLENCODED
protected static final okhttp3.MediaType FORM_URLENCODED -
DEVICES_URI
- See Also:
-
LABEL_GROUPS_URI
- See Also:
-
clientConnectTimeout
protected int clientConnectTimeout -
clientRequestTimeout
protected int clientRequestTimeout -
skipCheckCertificate
protected boolean skipCheckCertificate -
proxy
-
proxyUser
-
proxyPassword
-
apiURL
-
-
Constructor Details
-
AbstractAPIClient
public AbstractAPIClient()
-
-
Method Details
-
getClient
protected final okhttp3.OkHttpClient getClient() -
setConnectTimeout
public void setConnectTimeout(int timeout) Description copied from interface:APIClient
Sets establish connection timeout for APIClient requests.- Specified by:
setConnectTimeout
in interfaceAPIClient
- Parameters:
timeout
- timeout is ms. Value 0 means infinite timeout.
-
setRequestTimeout
public void setRequestTimeout(int timeout) Description copied from interface:APIClient
Sets timeout for read data from established connection for APIClient requests.- Specified by:
setRequestTimeout
in interfaceAPIClient
- Parameters:
timeout
- timeout is ms. Value 0 means infinite timeout.
-
get
Description copied from interface:APIClient
Calls GET request to API- Specified by:
get
in interfaceAPIClient
- Type Parameters:
T
- expected result class to be parsed from response- Parameters:
uri
- context URI of the resource (without/api/v2
prefixtype
- expected result class to be parsed from response- Returns:
- object defined as
T
if succesfully returned and parsed - Throws:
APIException
- on any problem related to API communication
-
get
Description copied from interface:APIClient
Calls GET request to API. Used when result expected as stream.- Specified by:
get
in interfaceAPIClient
- Parameters:
uri
- context URI of the resource (without/api/v2
prefix- Returns:
- stream with response
- Throws:
APIException
- on any problem related to API communication
-
get
- Specified by:
get
in interfaceAPIClient
- Throws:
APIException
-
getInterceptor
protected abstract okhttp3.Interceptor getInterceptor() -
getOnce
protected <T extends APIEntity> T getOnce(String uri, Context<?> context, com.fasterxml.jackson.core.type.TypeReference<T> type) throws APIException Tries to call API once. Returns expected entity or throws exception.- Throws:
APIException
-
getStream
- Throws:
APIException
-
getHttpResponse
- Specified by:
getHttpResponse
in interfaceAPIClient
- Throws:
APIException
-
post
Description copied from interface:APIClient
Calls POST request to API- Specified by:
post
in interfaceAPIClient
- Type Parameters:
T
- expected result class to be parsed from response- Parameters:
uri
- context URI of the resource (without/api/v2
prefixbody
- body - usually url encoded, to POST to APItype
- expected result class to be parsed from response- Returns:
- object defined as
T
if succesfully returned and parsed - Throws:
APIException
- on any problem related to API communication
-
postOnce
protected <T extends APIEntity> T postOnce(String uri, Object body, Map<String, String> fileExtraParams, String contentType, com.fasterxml.jackson.core.type.TypeReference<T> type) throws APIException- Throws:
APIException
-
buildFromMap
-
postFile
public <T extends APIEntity> T postFile(String uri, String contentType, File file, Map<String, String> fileExtraParams, Class<T> type) throws APIExceptionDescription copied from interface:APIClient
Calls POST request to API- Specified by:
postFile
in interfaceAPIClient
- Type Parameters:
T
- expected result class to be parsed from response- Parameters:
uri
- context URI of the resource (without/api/v2
prefix)contentType
- content type of uploaded filefile
- file to be uploaded with that requestfileExtraParams
- extra parameters for form-data describing the filetype
- expected result class to be parsed from response- Returns:
- object defined as
T
if successfully returned and parsed - Throws:
APIException
- on any problem related to API communication
-
delete
Description copied from interface:APIClient
Calls DELETE request to API- Specified by:
delete
in interfaceAPIClient
- Parameters:
uri
- context URI of the resource (without/api/v2
prefix- Throws:
APIException
- on any problem related to API communication
-
deleteOnce
- Throws:
APIException
-
me
Description copied from interface:APIClient
Fetch and return me - the authenticated user.- Specified by:
me
in interfaceAPIClient
- Throws:
APIException
- on invalid username, password or API error.
-
getDevices
Description copied from interface:APIClient
return resource for accessing list of devices in Cloud using provided filters- Specified by:
getDevices
in interfaceAPIClient
- Returns:
- list resource for accessing all devices matching selected filters, if no filter used returns all devices
-
getDevices
- Specified by:
getDevices
in interfaceAPIClient
-
getLabelGroups
- Specified by:
getLabelGroups
in interfaceAPIClient
-
getLabelGroups
- Specified by:
getLabelGroups
in interfaceAPIClient
-
findDevicePropertyInLabelGroup
public Optional<APIDeviceProperty> findDevicePropertyInLabelGroup(String groupName, String labelName) throws APIException - Specified by:
findDevicePropertyInLabelGroup
in interfaceAPIClient
- Throws:
APIException
-
fromJson
protected <T> T fromJson(InputStream inputStream, com.fasterxml.jackson.core.type.TypeReference<T> type) throws APIException - Throws:
APIException
-
fromJson
protected <T> T fromJson(String content, com.fasterxml.jackson.core.type.TypeReference<T> type) throws APIException - Throws:
APIException
-
buildUrl
-
getAPIException
-