RestApiHelper
public class RestApiHelper
extends Object
implements IRestApiHelper
對象 | |
↳ | com.android.tradefed.util.RestApiHelper |
用於執行 REST API 調用的輔助類。
概括
常數 | |
---|---|
int | DEFAULT_NUMBER_OF_RETRIES
|
字段 | |
---|---|
protected static final JsonFactory | JSON_FACTORY |
protected static final String | JSON_MIME
|
公共構造函數 | |
---|---|
RestApiHelper (HttpRequestFactory requestFactory, String baseUri) 使用給定信息創建 API 幫助程序實例。 |
公共方法 | |
---|---|
GenericUrl | buildQueryUri (String[] uriParts, options) buildQueryUri (String[] uriParts, options) 使用給定的 URI 部分和選項為 API 調用構造一個 URI。 |
HttpResponse | execute (String method, String[] uriParts, options, JSONObject data) execute (String method, String[] uriParts, options, JSONObject data) 執行 API 請求。 |
HttpRequestFactory | getRequestFactory () 返回 HttpRequestFactory。 |
static RestApiHelper | newInstanceWithGoogleCredential (String baseUri, File jsonKeyFile, scopes) newInstanceWithGoogleCredential (String baseUri, File jsonKeyFile, scopes) 創建它使用的API幫助程序實例 |
static RestApiHelper | newInstanceWithGoogleCredential (String baseUri, String serviceAccount, File keyFile, scopes) newInstanceWithGoogleCredential (String baseUri, String serviceAccount, File keyFile, scopes) 創建它使用的API幫助程序實例 |
常數
DEFAULT_NUMBER_OF_RETRIES
protected static final int DEFAULT_NUMBER_OF_RETRIES
常數值:2 (0x00000002)
字段
JSON_FACTORY
protected static final JsonFactory JSON_FACTORY
JSON_MIME
protected static final String JSON_MIME
公共構造函數
RestApiHelper
public RestApiHelper (HttpRequestFactory requestFactory, String baseUri)
使用給定信息創建 API 幫助程序實例。
參數 | |
---|---|
requestFactory | HttpRequestFactory :當創建工廠使用HttpRequest 秒。 |
baseUri | String :API的基本URI |
公共方法
構建查詢Uri
public GenericUrl buildQueryUri (String[] uriParts,options)
使用給定的 URI 部分和選項為 API 調用構造一個 URI。 uriParts 應該已經是 URL 編碼的,而選項應該是未編碼的字符串。
參數 | |
---|---|
uriParts | String |
options |
退貨 | |
---|---|
GenericUrl |
執行
public HttpResponse execute (String method, String[] uriParts,options, JSONObject data)
執行 API 請求。
參數 | |
---|---|
method | String :所述請求的HTTP方法 |
uriParts | String :URL編碼中使用URI部件構造請求URI。 |
options | |
data | JSONObject :數據到與請求被發送 |
退貨 | |
---|---|
HttpResponse | 一個 HttpResponse 對象 |
獲取請求工廠
public HttpRequestFactory getRequestFactory ()
返回 HttpRequestFactory。
暴露用於測試。
退貨 | |
---|---|
HttpRequestFactory |
newInstanceWithGoogleCredential
public static RestApiHelper newInstanceWithGoogleCredential (String baseUri, File jsonKeyFile,scopes)
創建它使用的API幫助程序實例Credential
進行認證。
參數 | |
---|---|
baseUri | String :API的基本URI |
jsonKeyFile | File :服務帳戶JSON密鑰文件 |
scopes |
退貨 | |
---|---|
RestApiHelper |
投擲 | |
---|---|
| 一般安全異常 |
newInstanceWithGoogleCredential
public static RestApiHelper newInstanceWithGoogleCredential (String baseUri, String serviceAccount, File keyFile,scopes)
創建它使用的API幫助程序實例Credential
進行認證。
參數 | |
---|---|
baseUri | String :API的基本URI |
serviceAccount | String :該服務的名稱帳戶使用 |
keyFile | File :服務帳戶密鑰文件 |
scopes |
退貨 | |
---|---|
RestApiHelper |
投擲 | |
---|---|
| 一般安全異常 |