andreluizreis
11/28/2017 - 8:51 PM

Retrofit with Interceptor and Authenticator

Retrofit with Interceptor and Authenticator.

/**
 * Init Retrofit
 */
private void initRetrofit() {
    mOkHttpClient = new OkHttpClient.Builder()
        .addInterceptor(new AuthenticationInterceptor())
        .authenticator(new TokenAuthenticator())
        .build();

    // Create Gson instance to serialize Nulls
    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.serializeNulls();
    Gson gson = gsonBuilder.create();

    mRetrofit = new Retrofit.Builder()
        .baseUrl(BuildConfig.APP_API_URL)
        .addConverterFactory(GsonConverterFactory.create(gson))
        .client(mOkHttpClient)
        .build();
}