RestApi助手

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) 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)

建立一個使用Credential進行驗證的 API 幫助程式實例。

static RestApiHelper newInstanceWithGoogleCredential (String baseUri, String serviceAccount, File keyFile, scopes) newInstanceWithGoogleCredential (String baseUri, String serviceAccount, File keyFile, 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

公共構造函數

RestApi助手

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 :用於建構請求 URI 的 URL 編碼的 URI 部分。

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

data JSONObject :隨請求一起傳送的數據

退貨
HttpResponse一個 HttpResponse 對象

取得請求工廠

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

投擲
通用安全異常
IO異常

newInstanceWithGoogleCredential

public static RestApiHelper newInstanceWithGoogleCredential (String baseUri, 
                String serviceAccount, 
                File keyFile, 
                 scopes)

建立一個使用Credential進行驗證的 API 幫助程式實例。

參數
baseUri String : API 的基本 URI

serviceAccount String :要使用的服務帳戶的名稱

keyFile File :服務帳戶金鑰文件

scopes :與服務帳戶一起使用的 OAuth 範圍的集合

退貨
RestApiHelper

投擲
通用安全異常
IO異常