RestApiHelper

public class RestApiHelper
extends Object implements IRestApiHelper

java.lang.Object
   ↳ com.android.tradefed.util.RestApiHelper


用於執行 REST API 呼叫的輔助類別。

摘要

常數

int DEFAULT_NUMBER_OF_RETRIES

String JSON_MIME

欄位

protected static final JsonFactory JSON_FACTORY

公用建構函式

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)

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

常數

DEFAULT_NUMBER_OF_RETRIES

protected static final int DEFAULT_NUMBER_OF_RETRIES

常數值: 2 (0x00000002)

JSON_MIME

protected static final String JSON_MIME

常數值: "application/json"

欄位

JSON_FACTORY

protected static final JsonFactory JSON_FACTORY

公用建構函式

RestApiHelper

public RestApiHelper (HttpRequestFactory requestFactory, 
                String baseUri)

使用指定資訊建立 API 輔助程式例項。

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

baseUri String:API 的基礎 URI

公用方法

buildQueryUri

public GenericUrl buildQueryUri (String[] uriParts, 
                 options)

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

參數
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