Package com.testdroid.api
Class DefaultAPIClient
- java.lang.Object
-
- com.testdroid.api.AbstractAPIClient
-
- com.testdroid.api.DefaultAPIClient
-
- All Implemented Interfaces:
APIClient
public class DefaultAPIClient extends AbstractAPIClient
- Author:
- Łukasz Kajda
, Slawomir Pawluk , Krzysztof Fonał
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String
accessToken
protected long
accessTokenExpireTime
static java.lang.String
BITBAR_API_OAUTH2_CLIENT_ID
protected java.lang.String
cloudURL
static int
HTTP_CONNECT_TIMEOUT
static int
HTTP_READ_TIMEOUT
protected java.lang.String
password
protected java.lang.String
refreshToken
protected java.lang.String
username
-
Fields inherited from class com.testdroid.api.AbstractAPIClient
ACCEPT_HEADER, API_URI, apiURL, clientConnectTimeout, clientRequestTimeout, DEVICES_URI, httpTransport, LABEL_GROUPS_URI
-
-
Constructor Summary
Constructors Constructor Description DefaultAPIClient(java.lang.String cloudURL, java.lang.String username, java.lang.String password)
DefaultAPIClient(java.lang.String cloudURL, java.lang.String username, java.lang.String password, boolean skipCheckCertificate)
DefaultAPIClient(java.lang.String cloudURL, java.lang.String username, java.lang.String password, org.apache.http.HttpHost proxy, boolean skipCheckCertificate)
DefaultAPIClient(java.lang.String cloudURL, java.lang.String username, java.lang.String password, org.apache.http.HttpHost proxy, java.lang.String proxyUser, java.lang.String proxyPassword, boolean skipCheckCertificate)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.String
acquireAccessToken()
void
delete(java.lang.String uri)
Calls DELETE request to APIjava.io.InputStream
get(java.lang.String uri)
Calls GET request to API.<T extends APIEntity>
Tget(java.lang.String uri, java.lang.Class<T> type)
Calls GET request to APIprotected com.google.api.client.http.HttpHeaders
getHttpHeaders()
protected com.google.api.client.http.HttpRequestFactory
getRequestFactory()
<T extends APIEntity>
Tpost(java.lang.String uri, java.lang.Object body, java.lang.Class<T> type)
Calls POST request to API<T extends APIEntity>
TpostFile(java.lang.String uri, java.lang.String contentType, java.io.File file, java.util.Map<java.lang.String,java.lang.String> fileExtraParams, java.lang.Class<T> type)
Calls POST request to APIprotected java.lang.String
refreshAccessToken()
-
Methods inherited from class com.testdroid.api.AbstractAPIClient
buildUrl, deleteOnce, disconnectQuietly, findDevicePropertyInLabelGroup, fixMapParameters, fromJson, fromJson, get, getAPIException, getDevices, getDevices, getHttpResponse, getLabelGroups, getLabelGroups, getOnce, getStream, me, postOnce, setConnectTimeout, setRequestTimeout
-
-
-
-
Field Detail
-
HTTP_CONNECT_TIMEOUT
public static final int HTTP_CONNECT_TIMEOUT
- See Also:
- Constant Field Values
-
HTTP_READ_TIMEOUT
public static final int HTTP_READ_TIMEOUT
- See Also:
- Constant Field Values
-
BITBAR_API_OAUTH2_CLIENT_ID
public static final java.lang.String BITBAR_API_OAUTH2_CLIENT_ID
- See Also:
- Constant Field Values
-
accessToken
protected java.lang.String accessToken
-
accessTokenExpireTime
protected long accessTokenExpireTime
-
cloudURL
protected java.lang.String cloudURL
-
password
protected java.lang.String password
-
refreshToken
protected java.lang.String refreshToken
-
username
protected java.lang.String username
-
-
Constructor Detail
-
DefaultAPIClient
public DefaultAPIClient(java.lang.String cloudURL, java.lang.String username, java.lang.String password)
-
DefaultAPIClient
public DefaultAPIClient(java.lang.String cloudURL, java.lang.String username, java.lang.String password, boolean skipCheckCertificate)
-
DefaultAPIClient
public DefaultAPIClient(java.lang.String cloudURL, java.lang.String username, java.lang.String password, org.apache.http.HttpHost proxy, boolean skipCheckCertificate)
-
DefaultAPIClient
public DefaultAPIClient(java.lang.String cloudURL, java.lang.String username, java.lang.String password, org.apache.http.HttpHost proxy, java.lang.String proxyUser, java.lang.String proxyPassword, boolean skipCheckCertificate)
-
-
Method Detail
-
getRequestFactory
protected com.google.api.client.http.HttpRequestFactory getRequestFactory() throws APIException
- Overrides:
getRequestFactory
in classAbstractAPIClient
- Throws:
APIException
-
acquireAccessToken
protected java.lang.String acquireAccessToken() throws APIException
- Throws:
APIException
-
refreshAccessToken
protected java.lang.String refreshAccessToken() throws APIException
- Throws:
APIException
-
get
public <T extends APIEntity> T get(java.lang.String uri, java.lang.Class<T> type) throws APIException
Description copied from interface:APIClient
Calls GET request to API- Specified by:
get
in interfaceAPIClient
- Overrides:
get
in classAbstractAPIClient
- 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
public java.io.InputStream get(java.lang.String uri) throws APIException
Description copied from interface:APIClient
Calls GET request to API. Used when result expected as stream.- Specified by:
get
in interfaceAPIClient
- Overrides:
get
in classAbstractAPIClient
- Parameters:
uri
- context URI of the resource (without/api/v2
prefix- Returns:
- stream with response
- Throws:
APIException
- on any problem related to API communication
-
post
public <T extends APIEntity> T post(java.lang.String uri, java.lang.Object body, java.lang.Class<T> type) throws APIException
Description copied from interface:APIClient
Calls POST request to API- Specified by:
post
in interfaceAPIClient
- Overrides:
post
in classAbstractAPIClient
- 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
-
postFile
public <T extends APIEntity> T postFile(java.lang.String uri, java.lang.String contentType, java.io.File file, java.util.Map<java.lang.String,java.lang.String> fileExtraParams, java.lang.Class<T> type) throws APIException
Description copied from interface:APIClient
Calls POST request to API- Specified by:
postFile
in interfaceAPIClient
- Overrides:
postFile
in classAbstractAPIClient
- 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
public void delete(java.lang.String uri) throws APIException
Description copied from interface:APIClient
Calls DELETE request to API- Specified by:
delete
in interfaceAPIClient
- Overrides:
delete
in classAbstractAPIClient
- Parameters:
uri
- context URI of the resource (without/api/v2
prefix- Throws:
APIException
- on any problem related to API communication
-
getHttpHeaders
protected com.google.api.client.http.HttpHeaders getHttpHeaders()
- Specified by:
getHttpHeaders
in classAbstractAPIClient
-
-