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)

创建一个 API 帮助程序实例,该实例使用 Credential 进行身份验证。

常量

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

公共方法

buildQueryUri

public GenericUrl buildQueryUri (String[] uriParts, 
                 options)

使用给定的 URI 部分和选项为 API 调用构建 URI。uriParts 应已进行网址编码,而 options 应为未编码的字符串。

参数
uriParts String

options

返回
GenericUrl

execute

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)

创建一个 API 帮助程序实例,该实例使用 Credential 进行身份验证。

参数
baseUri String:API 的基本 URI

jsonKeyFile File:服务账号 JSON 密钥文件

scopes :要与服务账号搭配使用的 OAuth 权限范围集合

返回
RestApiHelper

抛出
GeneralSecurityException
IOException