Search in sources :

Example 1 with AuthInterceptor

use of io.plaidapp.data.api.AuthInterceptor in project plaid by nickbutcher.

the class BaseDataManager method createProductHuntApi.

private void createProductHuntApi() {
    final OkHttpClient client = new OkHttpClient.Builder().addInterceptor(new AuthInterceptor(BuildConfig.PROCUCT_HUNT_DEVELOPER_TOKEN)).build();
    final Gson gson = new Gson();
    productHuntApi = new Retrofit.Builder().baseUrl(ProductHuntService.ENDPOINT).client(client).addConverterFactory(new DenvelopingConverter(gson)).addConverterFactory(GsonConverterFactory.create(gson)).build().create(ProductHuntService.class);
}
Also used : Retrofit(retrofit2.Retrofit) OkHttpClient(okhttp3.OkHttpClient) ProductHuntService(io.plaidapp.data.api.producthunt.ProductHuntService) AuthInterceptor(io.plaidapp.data.api.AuthInterceptor) Gson(com.google.gson.Gson) DenvelopingConverter(io.plaidapp.data.api.DenvelopingConverter)

Example 2 with AuthInterceptor

use of io.plaidapp.data.api.AuthInterceptor in project sbt-android by scala-android.

the class DribbbleLogin method showLoggedInUser.

private void showLoggedInUser() {
    Gson gson = new GsonBuilder().setDateFormat(DribbbleService.DATE_FORMAT).create();
    RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint(DribbbleService.ENDPOINT).setConverter(new GsonConverter(gson)).setRequestInterceptor(new AuthInterceptor(dribbblePrefs.getAccessToken())).build();
    DribbbleService dribbbleApi = restAdapter.create((DribbbleService.class));
    dribbbleApi.getAuthenticatedUser(new Callback<User>() {

        @Override
        public void success(User user, Response response) {
            dribbblePrefs.setLoggedInUser(user);
            Toast confirmLogin = new Toast(getApplicationContext());
            View v = LayoutInflater.from(DribbbleLogin.this).inflate(R.layout.toast_logged_in_confirmation, null, false);
            ((TextView) v.findViewById(R.id.name)).setText(user.name);
            // need to use app context here as the activity will be destroyed shortly
            Glide.with(getApplicationContext()).load(user.avatar_url).placeholder(R.drawable.ic_player).transform(new CircleTransform(getApplicationContext())).into((ImageView) v.findViewById(R.id.avatar));
            v.findViewById(R.id.scrim).setBackground(ScrimUtil.makeCubicGradientScrimDrawable(ContextCompat.getColor(DribbbleLogin.this, R.color.scrim), 5, Gravity.BOTTOM));
            confirmLogin.setView(v);
            confirmLogin.setGravity(Gravity.BOTTOM | Gravity.FILL_HORIZONTAL, 0, 0);
            confirmLogin.setDuration(Toast.LENGTH_LONG);
            confirmLogin.show();
        }

        @Override
        public void failure(RetrofitError error) {
        }
    });
}
Also used : GsonConverter(retrofit.converter.GsonConverter) User(io.plaidapp.data.api.dribbble.model.User) GsonBuilder(com.google.gson.GsonBuilder) GsonBuilder(com.google.gson.GsonBuilder) AuthInterceptor(io.plaidapp.data.api.AuthInterceptor) Gson(com.google.gson.Gson) CircleTransform(io.plaidapp.util.glide.CircleTransform) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) Response(retrofit.client.Response) DribbbleService(io.plaidapp.data.api.dribbble.DribbbleService) Toast(android.widget.Toast) ImageView(android.widget.ImageView) RestAdapter(retrofit.RestAdapter) RetrofitError(retrofit.RetrofitError)

Example 3 with AuthInterceptor

use of io.plaidapp.data.api.AuthInterceptor in project sbt-android by scala-android.

the class DribbbleShot method setupDribbble.

private void setupDribbble() {
    // setup the api object which captures the current access token
    dribbblePrefs = DribbblePrefs.get(this);
    Gson gson = new GsonBuilder().setDateFormat(DribbbleService.DATE_FORMAT).create();
    RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint(DribbbleService.ENDPOINT).setConverter(new GsonConverter(gson)).setRequestInterceptor(new AuthInterceptor(dribbblePrefs.getAccessToken())).build();
    dribbbleApi = restAdapter.create(DribbbleService.class);
}
Also used : GsonConverter(retrofit.converter.GsonConverter) DribbbleService(io.plaidapp.data.api.dribbble.DribbbleService) GsonBuilder(com.google.gson.GsonBuilder) GsonBuilder(com.google.gson.GsonBuilder) AuthInterceptor(io.plaidapp.data.api.AuthInterceptor) Gson(com.google.gson.Gson) RestAdapter(retrofit.RestAdapter)

Example 4 with AuthInterceptor

use of io.plaidapp.data.api.AuthInterceptor in project plaid by nickbutcher.

the class DribbblePrefs method createApi.

private void createApi() {
    final OkHttpClient client = new OkHttpClient.Builder().addInterceptor(new AuthInterceptor(getAccessToken())).build();
    final Gson gson = new GsonBuilder().setDateFormat(DribbbleService.DATE_FORMAT).create();
    api = new Retrofit.Builder().baseUrl(DribbbleService.ENDPOINT).client(client).addConverterFactory(new DenvelopingConverter(gson)).addConverterFactory(GsonConverterFactory.create(gson)).build().create((DribbbleService.class));
}
Also used : Retrofit(retrofit2.Retrofit) OkHttpClient(okhttp3.OkHttpClient) GsonBuilder(com.google.gson.GsonBuilder) GsonBuilder(com.google.gson.GsonBuilder) AuthInterceptor(io.plaidapp.data.api.AuthInterceptor) Gson(com.google.gson.Gson) DenvelopingConverter(io.plaidapp.data.api.DenvelopingConverter)

Aggregations

Gson (com.google.gson.Gson)4 AuthInterceptor (io.plaidapp.data.api.AuthInterceptor)4 GsonBuilder (com.google.gson.GsonBuilder)3 DenvelopingConverter (io.plaidapp.data.api.DenvelopingConverter)2 DribbbleService (io.plaidapp.data.api.dribbble.DribbbleService)2 OkHttpClient (okhttp3.OkHttpClient)2 RestAdapter (retrofit.RestAdapter)2 GsonConverter (retrofit.converter.GsonConverter)2 Retrofit (retrofit2.Retrofit)2 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 Toast (android.widget.Toast)1 User (io.plaidapp.data.api.dribbble.model.User)1 ProductHuntService (io.plaidapp.data.api.producthunt.ProductHuntService)1 CircleTransform (io.plaidapp.util.glide.CircleTransform)1 RetrofitError (retrofit.RetrofitError)1 Response (retrofit.client.Response)1