RestApiHelper

public class RestApiHelper
extends Object implements IRestApiHelper

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


Một lớp trợ giúp để thực hiện các lệnh gọi API REST.

Tóm tắt

Hằng số

int DEFAULT_NUMBER_OF_RETRIES

String JSON_MIME

Trường

protected static final JsonFactory JSON_FACTORY

Hàm khởi tạo công khai

RestApiHelper(HttpRequestFactory requestFactory, String baseUri)

Tạo một thực thể trình trợ giúp API bằng thông tin đã cho.

Phương thức công khai

GenericUrl buildQueryUri(String[] uriParts, options)

Tạo một URI cho lệnh gọi API với các phần và lựa chọn URI đã cho.

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

Thực thi một yêu cầu API.

HttpRequestFactory getRequestFactory()

Trả về HttpRequestFactory.

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

Tạo một thực thể trợ giúp API sử dụng Credential để xác thực.

Hằng số

DEFAULT_NUMBER_OF_RETRIES

protected static final int DEFAULT_NUMBER_OF_RETRIES

Giá trị hằng số: 2 (0x00000002)

JSON_MIME

protected static final String JSON_MIME

Giá trị không đổi: "application/json"

Trường

JSON_FACTORY

protected static final JsonFactory JSON_FACTORY

Hàm khởi tạo công khai

RestApiHelper

public RestApiHelper (HttpRequestFactory requestFactory, 
                String baseUri)

Tạo một thực thể trình trợ giúp API bằng thông tin đã cho.

Tham số
requestFactory HttpRequestFactory: trạng thái ban đầu để dùng khi tạo HttpRequest.

baseUri String: URI cơ sở của API

Phương thức công khai

buildQueryUri

public GenericUrl buildQueryUri (String[] uriParts, 
                 options)

Tạo một URI cho lệnh gọi API với các phần và lựa chọn URI đã cho. uriParts phải được mã hoá URL, trong khi options phải là các chuỗi chưa được mã hoá.

Tham số
uriParts String

options

Giá trị trả về
GenericUrl

thực thi

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

Thực thi một yêu cầu API.

Tham số
method String: phương thức HTTP của yêu cầu

uriParts String: Các phần URI được mã hoá URL sẽ dùng để tạo URI yêu cầu.

options : tên và giá trị tham số chưa được mã hoá dùng để tạo chuỗi truy vấn

data JSONObject: dữ liệu sẽ được gửi cùng với yêu cầu

Giá trị trả về
HttpResponse đối tượng HttpResponse

getRequestFactory

public HttpRequestFactory getRequestFactory ()

Trả về HttpRequestFactory.

Được hiển thị để kiểm thử.

Giá trị trả về
HttpRequestFactory

newInstanceWithGoogleCredential

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

Tạo một thực thể trợ giúp API sử dụng Credential để xác thực.

Tham số
baseUri String: URI cơ sở của API

jsonKeyFile File: tệp khoá json của tài khoản dịch vụ

scopes : tập hợp các phạm vi OAuth để sử dụng với tài khoản dịch vụ

Giá trị trả về
RestApiHelper

Gửi
GeneralSecurityException
IOException