Search in sources :

Example 1 with RequestParam

use of com.hyq0719.mktapi.common.executor.parameter.RequestParam in project marketing-api-java-sdks by Hyq0719.

the class ApiRequest method executeWithHttp.

protected ApiResponse<R> executeWithHttp(T t, String token) throws ApiException {
    RequestParam param = constructParameters(t, token);
    paramValidate(t);
    updateParamsForAuth(param);
    return getApiClient().execute(param, localVarReturnType);
}
Also used : RequestParam(com.hyq0719.mktapi.common.executor.parameter.RequestParam)

Example 2 with RequestParam

use of com.hyq0719.mktapi.common.executor.parameter.RequestParam in project marketing-api-java-sdks by Hyq0719.

the class ApacheHttpHandler method execute.

@Override
public <T> ApiResponse<T> execute(RequestParam param, Type returnType) throws ApiException {
    try {
        HttpResponse response = doRequest(param);
        Header[] headers = response.getAllHeaders();
        Map<String, List<String>> headerMap = toMultimap(headers);
        T data = handleResponse(response, returnType);
        return new ApiResponse<>(response.getStatusLine().getStatusCode(), headerMap, data);
    } catch (IOException e) {
        throw new ApiException(e);
    }
}
Also used : BasicHeader(org.apache.http.message.BasicHeader) IOException(java.io.IOException) ApiResponse(com.hyq0719.mktapi.common.ApiResponse) ApiException(com.hyq0719.mktapi.common.exception.ApiException)

Example 3 with RequestParam

use of com.hyq0719.mktapi.common.executor.parameter.RequestParam in project marketing-api-java-sdks by Hyq0719.

the class BaseHttpHandler method appendCollectionQueryParams.

/**
 * 添加请求参数集合
 *
 * @param url          当前url
 * @param requestParam 请求参数
 */
private void appendCollectionQueryParams(StringBuilder url, RequestParam requestParam) {
    List<Pair> collectionQueryParams = requestParam.getCollectionQueryParams();
    if (collectionQueryParams != null && !collectionQueryParams.isEmpty()) {
        String prefix = url.toString().contains("?") ? "&" : "?";
        for (Pair param : collectionQueryParams) {
            if (param.getValue() != null) {
                if (prefix != null) {
                    url.append(prefix);
                    prefix = null;
                } else {
                    url.append("&");
                }
                String value = parameterToString(param.getValue());
                // collection query parameter value already escaped as part of parameterToPairs
                url.append(escapeString(param.getName())).append("=").append(value);
            }
        }
    }
}
Also used : Pair(com.hyq0719.mktapi.common.executor.parameter.Pair)

Example 4 with RequestParam

use of com.hyq0719.mktapi.common.executor.parameter.RequestParam in project marketing-api-java-sdks by Hyq0719.

the class BaseHttpHandler method appendQueryParams.

/**
 * 添加请求参数
 *
 * @param url          当前url
 * @param requestParam 请求参数
 */
private void appendQueryParams(StringBuilder url, RequestParam requestParam) {
    List<Pair> queryParams = requestParam.getQueryParams();
    if (queryParams != null && !queryParams.isEmpty()) {
        // support (constant) query string in `path`, e.g. "/posts?draft=1"
        String prefix = "?";
        for (Pair param : queryParams) {
            if (param.getValue() != null) {
                if (prefix != null) {
                    url.append(prefix);
                    prefix = null;
                } else {
                    url.append("&");
                }
                String value = parameterToString(param.getValue());
                url.append(escapeString(param.getName())).append("=").append(escapeString(value));
            }
        }
    }
}
Also used : Pair(com.hyq0719.mktapi.common.executor.parameter.Pair)

Example 5 with RequestParam

use of com.hyq0719.mktapi.common.executor.parameter.RequestParam in project marketing-api-java-sdks by Hyq0719.

the class OkhttpHttpHandler method execute.

@Override
public <T> ApiResponse<T> execute(RequestParam param, Type returnType) throws ApiException {
    try {
        Call call = buildCall(param);
        log.info(call.request().toString());
        Response response = call.execute();
        T data = handleResponse(response, returnType);
        return new ApiResponse<>(response.code(), response.headers().toMultimap(), data);
    } catch (IOException e) {
        throw new ApiException(e);
    }
}
Also used : ApiResponse(com.hyq0719.mktapi.common.ApiResponse) IOException(java.io.IOException) ApiResponse(com.hyq0719.mktapi.common.ApiResponse) ApiException(com.hyq0719.mktapi.common.exception.ApiException)

Aggregations

ApiResponse (com.hyq0719.mktapi.common.ApiResponse)2 ApiException (com.hyq0719.mktapi.common.exception.ApiException)2 Pair (com.hyq0719.mktapi.common.executor.parameter.Pair)2 IOException (java.io.IOException)2 RequestParam (com.hyq0719.mktapi.common.executor.parameter.RequestParam)1 BasicHeader (org.apache.http.message.BasicHeader)1