Search in sources :

Example 1 with Url

use of retrofit2.http.Url 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 2 with Url

use of retrofit2.http.Url 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 3 with Url

use of retrofit2.http.Url in project muzei by romannurik.

the class FiveHundredPxExampleArtSource method onTryUpdate.

@Override
protected void onTryUpdate(@UpdateReason int reason) throws RetryException {
    String currentToken = (getCurrentArtwork() != null) ? getCurrentArtwork().getToken() : null;
    OkHttpClient okHttpClient = new OkHttpClient.Builder().addInterceptor(new Interceptor() {

        @Override
        public Response intercept(final Chain chain) throws IOException {
            Request request = chain.request();
            HttpUrl url = request.url().newBuilder().addQueryParameter("consumer_key", Config.CONSUMER_KEY).build();
            request = request.newBuilder().url(url).build();
            return chain.proceed(request);
        }
    }).build();
    Retrofit retrofit = new Retrofit.Builder().baseUrl("https://api.500px.com/").client(okHttpClient).addConverterFactory(GsonConverterFactory.create()).build();
    FiveHundredPxService service = retrofit.create(FiveHundredPxService.class);
    PhotosResponse response;
    try {
        response = service.getPopularPhotos().execute().body();
    } catch (IOException e) {
        Log.w(TAG, "Error reading 500px response", e);
        throw new RetryException();
    }
    if (response == null || response.photos == null) {
        throw new RetryException();
    }
    if (response.photos.size() == 0) {
        Log.w(TAG, "No photos returned from API.");
        scheduleUpdate(System.currentTimeMillis() + ROTATE_TIME_MILLIS);
        return;
    }
    Random random = new Random();
    Photo photo;
    String token;
    while (true) {
        photo = response.photos.get(random.nextInt(response.photos.size()));
        token = Integer.toString(photo.id);
        if (response.photos.size() <= 1 || !TextUtils.equals(token, currentToken)) {
            break;
        }
    }
    publishArtwork(new Artwork.Builder().title(photo.name).byline(photo.user.fullname).imageUri(Uri.parse(photo.image_url)).token(token).viewIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("http://500px.com/photo/" + photo.id))).build());
    scheduleUpdate(System.currentTimeMillis() + ROTATE_TIME_MILLIS);
}
Also used : OkHttpClient(okhttp3.OkHttpClient) Artwork(com.google.android.apps.muzei.api.Artwork) Request(okhttp3.Request) Photo(com.example.muzei.examplesource500px.FiveHundredPxService.Photo) Intent(android.content.Intent) IOException(java.io.IOException) HttpUrl(okhttp3.HttpUrl) Retrofit(retrofit2.Retrofit) Random(java.util.Random) PhotosResponse(com.example.muzei.examplesource500px.FiveHundredPxService.PhotosResponse) Interceptor(okhttp3.Interceptor)

Example 4 with Url

use of retrofit2.http.Url in project retrofit by square.

the class RequestBuilderTest method getWithUrlAbsoluteSameHost.

@Test
public void getWithUrlAbsoluteSameHost() {
    class Example {

        @GET
        Call<ResponseBody> method(@Url String url) {
            return null;
        }
    }
    Request request = buildRequest(Example.class, "http://example.com/foo/bar/");
    assertThat(request.method()).isEqualTo("GET");
    assertThat(request.headers().size()).isZero();
    assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/");
    assertThat(request.body()).isNull();
}
Also used : Request(okhttp3.Request) Url(retrofit2.http.Url) HttpUrl(okhttp3.HttpUrl) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 5 with Url

use of retrofit2.http.Url in project YourAppIdea by Michenux.

the class MongolabPlaceServiceFactory method create.

public static MongolabPlaceService create(Context context) {
    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.registerTypeAdapter(Timestamp.class, new TimestampDeserializer());
    gsonBuilder.registerTypeAdapter(Location.class, new LocationDeserializer());
    OkHttpClient client = new OkHttpClient.Builder().addInterceptor(new LoggingInterceptor()).build();
    String url = context.getString(R.string.aroundme_placeremoteprovider_url);
    Retrofit retrofit = new Retrofit.Builder().baseUrl(url).client(client).addConverterFactory(GsonConverterFactory.create(gsonBuilder.create())).addCallAdapterFactory(RxJavaCallAdapterFactory.create()).build();
    return retrofit.create(MongolabPlaceService.class);
}
Also used : Retrofit(retrofit2.Retrofit) OkHttpClient(okhttp3.OkHttpClient) LoggingInterceptor(org.michenux.drodrolib.network.okhttp.LoggingInterceptor) TimestampDeserializer(org.michenux.drodrolib.network.gson.TimestampDeserializer) GsonBuilder(com.google.gson.GsonBuilder) GsonBuilder(com.google.gson.GsonBuilder) LocationDeserializer(org.michenux.drodrolib.network.gson.LocationDeserializer)

Aggregations

HttpUrl (okhttp3.HttpUrl)15 ResponseBody (okhttp3.ResponseBody)14 Request (okhttp3.Request)11 Test (org.junit.Test)10 Url (retrofit2.http.Url)10 Response (retrofit2.Response)9 OkHttpClient (okhttp3.OkHttpClient)6 Call (retrofit2.Call)6 Callback (retrofit2.Callback)6 Intent (android.content.Intent)4 View (android.view.View)3 TextView (android.widget.TextView)3 BindView (butterknife.BindView)3 Retrofit (retrofit2.Retrofit)3 ValueAnimator (android.animation.ValueAnimator)2 Application (android.app.Application)2 Context (android.content.Context)2 Uri (android.net.Uri)2 Build (android.os.Build)2 AlertDialog (android.support.v7.app.AlertDialog)2