Search in sources :

Example 1 with ApiRequest

use of com.yandex.money.api.net.ApiRequest in project yandex-money-sdk-java by yandex-money.

the class ShowcaseProcessTest method initShowcaseProcess.

private static ShowcaseProcess initShowcaseProcess() throws Exception {
    final ApiRequest<ShowcaseContext> resReq = new Showcase.Request(5551);
    final ApiClient client = getClient();
    final ShowcaseContext showcaseContext = client.execute(resReq);
    return new ShowcaseProcess(client, showcaseContext);
}
Also used : ShowcaseContext(com.yandex.money.api.model.showcase.ShowcaseContext) ApiRequest(com.yandex.money.api.net.ApiRequest) ApiClient(com.yandex.money.api.net.clients.ApiClient)

Example 2 with ApiRequest

use of com.yandex.money.api.net.ApiRequest in project yandex-money-sdk-java by yandex-money.

the class DefaultApiClient method prepareRequest.

private Request prepareRequest(ApiRequest<?> request) {
    checkNotNull(request, "request");
    Request.Builder builder = new Request.Builder().cacheControl(cacheControl).url(request.requestUrl(getHostsProvider())).addHeader(HttpHeaders.USER_AGENT, getUserAgent().getName()).addHeader(HttpHeaders.ACCEPT_LANGUAGE, getLanguage().iso6391Code);
    if (isAuthorized()) {
        builder.addHeader(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken);
    }
    for (Map.Entry<String, String> entry : request.getHeaders().entrySet()) {
        String value = entry.getValue();
        if (value != null) {
            builder.addHeader(entry.getKey(), value);
        }
    }
    ApiRequest.Method method = request.getMethod();
    if (method != ApiRequest.Method.GET) {
        RequestBody body = RequestBody.create(MediaType.parse(request.getContentType()), request.getBody());
        switch(method) {
            case POST:
                builder.post(body);
                break;
            case PUT:
                builder.put(body);
                break;
            case DELETE:
                builder.delete();
                break;
        }
    }
    return builder.build();
}
Also used : Request(okhttp3.Request) ApiRequest(com.yandex.money.api.net.ApiRequest) ApiRequest(com.yandex.money.api.net.ApiRequest) Map(java.util.Map) RequestBody(okhttp3.RequestBody)

Aggregations

ApiRequest (com.yandex.money.api.net.ApiRequest)2 ShowcaseContext (com.yandex.money.api.model.showcase.ShowcaseContext)1 ApiClient (com.yandex.money.api.net.clients.ApiClient)1 Map (java.util.Map)1 Request (okhttp3.Request)1 RequestBody (okhttp3.RequestBody)1