Search in sources :

Example 21 with Call

use of okhttp3.Call in project Pokemap by omkarmoghe.

the class GoogleManager method refreshToken.

public void refreshToken(String refreshToken, final RefreshListener listener) {
    HttpUrl url = HttpUrl.parse(OAUTH_TOKEN_ENDPOINT).newBuilder().addQueryParameter("client_id", CLIENT_ID).addQueryParameter("client_secret", SECRET).addQueryParameter("refresh_token", refreshToken).addQueryParameter("grant_type", "refresh_token").build();
    Callback<GoogleService.TokenResponse> googleCallback = new Callback<GoogleService.TokenResponse>() {

        @Override
        public void onResponse(Call<GoogleService.TokenResponse> call, Response<GoogleService.TokenResponse> response) {
            if (response != null && response.body() != null) {
                listener.refreshSuccessful(response.body().getIdToken(), response.body().getRefreshToken());
            } else {
                listener.refreshFailed("Failed on requesting the id token");
            }
        }

        @Override
        public void onFailure(Call<GoogleService.TokenResponse> call, Throwable t) {
            t.printStackTrace();
            listener.refreshFailed("Failed on requesting the id token");
        }
    };
    if (mGoogleService != null) {
        Call<GoogleService.TokenResponse> call = mGoogleService.requestToken(url.toString());
        call.enqueue(googleCallback);
    }
}
Also used : Response(retrofit2.Response) Call(retrofit2.Call) Callback(retrofit2.Callback) HttpUrl(okhttp3.HttpUrl)

Example 22 with Call

use of okhttp3.Call in project Pokemap by omkarmoghe.

the class NianticManager method loginPTC.

private void loginPTC(final String username, final String password, NianticService.LoginValues values, final LoginListener loginListener) {
    HttpUrl url = HttpUrl.parse(LOGIN_URL).newBuilder().addQueryParameter("lt", values.getLt()).addQueryParameter("execution", values.getExecution()).addQueryParameter("_eventId", "submit").addQueryParameter("username", username).addQueryParameter("password", password).build();
    OkHttpClient client = mClient.newBuilder().followRedirects(false).followSslRedirects(false).build();
    NianticService service = new Retrofit.Builder().baseUrl(BASE_URL).addConverterFactory(GsonConverterFactory.create()).client(client).build().create(NianticService.class);
    Callback<NianticService.LoginResponse> loginCallback = new Callback<NianticService.LoginResponse>() {

        @Override
        public void onResponse(Call<NianticService.LoginResponse> call, Response<NianticService.LoginResponse> response) {
            String location = response.headers().get("location");
            if (location != null && location.split("ticket=").length > 0) {
                String ticket = location.split("ticket=")[1];
                requestToken(ticket, loginListener);
            } else {
                Log.e(TAG, "PTC login failed via loginPTC(). There was no location header in response.");
                loginListener.authFailed("Pokemon Trainer Club Login Failed");
            }
        }

        @Override
        public void onFailure(Call<NianticService.LoginResponse> call, Throwable t) {
            t.printStackTrace();
            Log.e(TAG, "PTC login failed via loginPTC(). loginCallback.onFailure() threw: " + t.getMessage());
            loginListener.authFailed("Pokemon Trainer Club Login Failed");
        }
    };
    Call<NianticService.LoginResponse> call = service.login(url.toString());
    call.enqueue(loginCallback);
}
Also used : Call(retrofit2.Call) OkHttpClient(okhttp3.OkHttpClient) HttpUrl(okhttp3.HttpUrl) Response(retrofit2.Response) Retrofit(retrofit2.Retrofit) Callback(retrofit2.Callback)

Example 23 with Call

use of okhttp3.Call in project zipkin by openzipkin.

the class ElasticsearchHttpStorage method flush.

/** This is a blocking call, only used in tests. */
static void flush(HttpCall.Factory factory, String index) throws IOException {
    Request flushRequest = new Request.Builder().url(factory.baseUrl.newBuilder().addPathSegment(index).addPathSegment("_flush").build()).post(RequestBody.create(APPLICATION_JSON, "")).tag("flush-index").build();
    factory.execute(flushRequest, b -> null);
}
Also used : Request(okhttp3.Request)

Example 24 with Call

use of okhttp3.Call in project realm-java by realm.

the class OkHttpAuthenticationServer method logout.

private LogoutResponse logout(URL logoutUrl, String requestBody) throws Exception {
    Request request = new Request.Builder().url(logoutUrl).addHeader("Content-Type", "application/json").addHeader("Accept", "application/json").post(RequestBody.create(JSON, requestBody)).build();
    Call call = client.newCall(request);
    Response response = call.execute();
    return LogoutResponse.from(response);
}
Also used : Response(okhttp3.Response) Call(okhttp3.Call) Request(okhttp3.Request)

Example 25 with Call

use of okhttp3.Call in project scribejava by scribejava.

the class OkHttpHttpClient method createCall.

private Call createCall(String userAgent, Map<String, String> headers, Verb httpVerb, String completeUrl, BodyType bodyType, Object bodyContents) {
    final Request.Builder requestBuilder = new Request.Builder();
    requestBuilder.url(completeUrl);
    final String method = httpVerb.name();
    // prepare body
    final RequestBody body;
    if (bodyContents != null && HttpMethod.permitsRequestBody(method)) {
        final MediaType mediaType = headers.containsKey(CONTENT_TYPE) ? MediaType.parse(headers.get(CONTENT_TYPE)) : DEFAULT_CONTENT_TYPE_MEDIA_TYPE;
        body = bodyType.createBody(mediaType, bodyContents);
    } else {
        body = null;
    }
    // fill HTTP method and body
    requestBuilder.method(method, body);
    // fill headers
    for (Map.Entry<String, String> header : headers.entrySet()) {
        requestBuilder.addHeader(header.getKey(), header.getValue());
    }
    if (userAgent != null) {
        requestBuilder.header(OAuthConstants.USER_AGENT_HEADER_NAME, userAgent);
    }
    // create a new call
    return client.newCall(requestBuilder.build());
}
Also used : Request(okhttp3.Request) OAuthRequest(com.github.scribejava.core.model.OAuthRequest) MediaType(okhttp3.MediaType) HashMap(java.util.HashMap) Map(java.util.Map) RequestBody(okhttp3.RequestBody)

Aggregations

ResponseBody (okhttp3.ResponseBody)532 DateTimeRfc1123 (com.microsoft.rest.DateTimeRfc1123)332 DateTime (org.joda.time.DateTime)332 Test (org.junit.Test)236 Request (okhttp3.Request)199 ServiceCall (com.microsoft.rest.ServiceCall)140 Response (okhttp3.Response)124 MockResponse (okhttp3.mockwebserver.MockResponse)119 Call (okhttp3.Call)116 Response (retrofit2.Response)104 Observable (rx.Observable)96 ServiceResponse (com.microsoft.rest.ServiceResponse)92 IOException (java.io.IOException)82 PagedList (com.microsoft.azure.PagedList)80 ServiceResponseWithHeaders (com.microsoft.rest.ServiceResponseWithHeaders)78 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)72 List (java.util.List)63 RequestBody (okhttp3.RequestBody)57 Callback (okhttp3.Callback)41 OkHttpClient (okhttp3.OkHttpClient)34