RestApiHelper

public class RestApiHelper
extends Object implements IRestApiHelper

java.lang.Object
   ↳ 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)

使用指定的 URI 部分和選項,為 API 呼叫建構 URI。

HttpResponse execute(String method, String[] uriParts, options, JSONObject data)

執行 API 要求。

HttpRequestFactory getRequestFactory()

傳回 HttpRequestFactory。

static RestApiHelper newInstanceWithGoogleCredential(String baseUri, File jsonKeyFile, scopes)

建立使用 Credential 進行驗證的 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 helper 例項。

參數
requestFactory HttpRequestFactory:建立 HttpRequest 時要使用的工廠。

baseUri String:API 的基礎 URI

公用方法

buildQueryUri

public GenericUrl buildQueryUri (String[] uriParts, 
                 options)

使用指定的 URI 部分和選項,為 API 呼叫建構 URI。uriParts 應已進行網址編碼,而 options 應為未編碼的字串。

參數
uriParts String

options

傳回
GenericUrl

執行

public HttpResponse execute (String method, 
                String[] uriParts, 
                 options, 
                JSONObject data)

執行 API 要求。

參數
method String:要求的 HTTP 方法

uriParts String:用於建構要求 URI 的網址編碼 URI 部分。

options :用於建構查詢字串的未經編碼參數名稱和值

data JSONObject:要隨要求傳送的資料

傳回
HttpResponse HttpResponse 物件

getRequestFactory

public HttpRequestFactory getRequestFactory ()

傳回 HttpRequestFactory。

公開測試。

傳回
HttpRequestFactory

newInstanceWithGoogleCredential

public static RestApiHelper newInstanceWithGoogleCredential (String baseUri, 
                File jsonKeyFile, 
                 scopes)

建立使用 Credential 進行驗證的 API 輔助程式執行個體。

參數
baseUri String:API 的基礎 URI

jsonKeyFile File:服務帳戶 JSON 金鑰檔案

scopes :與服務帳戶搭配使用的 OAuth 範圍集合

傳回
RestApiHelper

擲回
GeneralSecurityException
IOException