Search in sources :

Example 1 with OkHttpPendingResult

use of com.google.maps.internal.OkHttpPendingResult in project google-maps-services-java by googlemaps.

the class OkHttpRequestHandler method handlePost.

@Override
public <T, R extends ApiResponse<T>> PendingResult<T> handlePost(String hostName, String url, String payload, String userAgent, String experienceIdHeaderValue, Class<R> clazz, FieldNamingPolicy fieldNamingPolicy, long errorTimeout, Integer maxRetries, ExceptionsAllowedToRetry exceptionsAllowedToRetry, RequestMetrics metrics) {
    RequestBody body = RequestBody.create(JSON, payload);
    Request.Builder builder = new Request.Builder().post(body).header("User-Agent", userAgent);
    if (experienceIdHeaderValue != null) {
        builder = builder.header(HttpHeaders.X_GOOG_MAPS_EXPERIENCE_ID, experienceIdHeaderValue);
    }
    Request req = builder.url(hostName + url).build();
    return new OkHttpPendingResult<>(req, client, clazz, fieldNamingPolicy, errorTimeout, maxRetries, exceptionsAllowedToRetry, metrics);
}
Also used : OkHttpPendingResult(com.google.maps.internal.OkHttpPendingResult) Request(okhttp3.Request) RequestBody(okhttp3.RequestBody)

Example 2 with OkHttpPendingResult

use of com.google.maps.internal.OkHttpPendingResult in project google-maps-services-java by googlemaps.

the class OkHttpRequestHandler method handle.

@Override
public <T, R extends ApiResponse<T>> PendingResult<T> handle(String hostName, String url, String userAgent, String experienceIdHeaderValue, Class<R> clazz, FieldNamingPolicy fieldNamingPolicy, long errorTimeout, Integer maxRetries, ExceptionsAllowedToRetry exceptionsAllowedToRetry, RequestMetrics metrics) {
    Request.Builder builder = new Request.Builder().get().header("User-Agent", userAgent);
    if (experienceIdHeaderValue != null) {
        builder = builder.header(HttpHeaders.X_GOOG_MAPS_EXPERIENCE_ID, experienceIdHeaderValue);
    }
    Request req = builder.url(hostName + url).build();
    return new OkHttpPendingResult<>(req, client, clazz, fieldNamingPolicy, errorTimeout, maxRetries, exceptionsAllowedToRetry, metrics);
}
Also used : OkHttpPendingResult(com.google.maps.internal.OkHttpPendingResult) Request(okhttp3.Request)

Aggregations

OkHttpPendingResult (com.google.maps.internal.OkHttpPendingResult)2 Request (okhttp3.Request)2 RequestBody (okhttp3.RequestBody)1