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

Trường

protected static final JsonFactory JSON_FACTORY

protected static final String JSON_MIME

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 URI cho lệnh gọi API bằng các phần và tuỳ chọn URI đã cho.

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

Thực thi 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ình 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ị không đổi: 2 (0x00000002)

Trường

JSON_FACTORY

protected static final JsonFactory JSON_FACTORY

JSON_MIME

protected static final String JSON_MIME

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: nhà máy để sử 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à tuỳ chọn URI đã cho. uriParts phải được mã hoá URL, trong khi các tuỳ chọn phải là Chuỗi chưa 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 yêu cầu API.

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

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

options : tên và giá trị tham số chưa 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ình 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