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);
}
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();
}
Aggregations