RestApiHelper
public
class
RestApiHelper
extends Object
implements
IRestApiHelper
| java.lang.Object | |
| ↳ | com.android.tradefed.util.RestApiHelper |
A helper class for performing REST API calls.
Summary
Constants | |
|---|---|
int |
DEFAULT_NUMBER_OF_RETRIES
|
Fields | |
|---|---|
protected
static
final
JsonFactory |
JSON_FACTORY
|
protected
static
final
String |
JSON_MIME
|
Public constructors | |
|---|---|
RestApiHelper(HttpRequestFactory requestFactory, String baseUri)
Creates an API helper instance with the given information. |
|
Public methods | |
|---|---|
GenericUrl
|
buildQueryUri(String[] uriParts,
Construct a URI for a API call with given URI parts and options. |
HttpResponse
|
execute(String method, String[] uriParts,
Executes an API request. |
HttpRequestFactory
|
getRequestFactory()
Returns the HttpRequestFactory. |
static
RestApiHelper
|
newInstanceWithGoogleCredential(String baseUri, File jsonKeyFile,
Creates an API helper instance which uses a |
Constants
DEFAULT_NUMBER_OF_RETRIES
protected static final int DEFAULT_NUMBER_OF_RETRIES
Constant Value: 2 (0x00000002)
Fields
JSON_FACTORY
protected static final JsonFactory JSON_FACTORY
JSON_MIME
protected static final String JSON_MIME
Public constructors
RestApiHelper
public RestApiHelper (HttpRequestFactory requestFactory,
String baseUri)Creates an API helper instance with the given information.
| Parameters | |
|---|---|
requestFactory |
HttpRequestFactory: the factory to use when creating HttpRequests. |
baseUri |
String: the base URI of API |
Public methods
buildQueryUri
public GenericUrl buildQueryUri (String[] uriParts,
options) Construct a URI for a API call with given URI parts and options. uriParts should be URL-encoded already, while options should be unencoded Strings.
| Parameters | |
|---|---|
uriParts |
String |
options |
|
| Returns | |
|---|---|
GenericUrl |
|
execute
public HttpResponse execute (String method,
String[] uriParts,
options,
JSONObject data) Executes an API request.
| Parameters | |
|---|---|
method |
String: a HTTP method of the request |
uriParts |
String: URL encoded URI parts to be used to construct the request URI. |
options |
: unencoded parameter names and values used to construct the query string |
data |
JSONObject: data to be sent with the request |
| Returns | |
|---|---|
HttpResponse |
a HttpResponse object |
getRequestFactory
public HttpRequestFactory getRequestFactory ()
Returns the HttpRequestFactory.
Exposed for testing.
| Returns | |
|---|---|
HttpRequestFactory |
|
newInstanceWithGoogleCredential
public static RestApiHelper newInstanceWithGoogleCredential (String baseUri, File jsonKeyFile,scopes)
Creates an API helper instance which uses a Credential for authentication.
| Parameters | |
|---|---|
baseUri |
String: the base URI of the API |
jsonKeyFile |
File: the service account json key file |
scopes |
: the collection of OAuth scopes to use with the service account |
| Returns | |
|---|---|
RestApiHelper |
|
| Throws | |
|---|---|
|
GeneralSecurityException |
|
IOException |