Search in sources :

Example 1 with AuthenticationInterceptor

use of com.example.networking.AuthenticationInterceptor in project Just-Another-Android-App by athkalia.

the class NetworkModule method provideOkHttpClient.

@Provides
@Singleton
public static OkHttpClient provideOkHttpClient(PropertiesManager propertiesManager, HttpLoggingInterceptor httpLoggingInterceptor, List<Interceptor> networkInterceptors, BaseUrlInterceptor baseUrlInterceptor) {
    final OkHttpClient.Builder okHttpBuilder = new OkHttpClient.Builder();
    // Logs network calls for debug builds
    okHttpBuilder.addInterceptor(httpLoggingInterceptor);
    // Adds authentication headers when required in network calls
    okHttpBuilder.addInterceptor(new AuthenticationInterceptor(propertiesManager));
    // Helps with changing base url of network calls in espresso tests to the MockWebServer base url.
    okHttpBuilder.addInterceptor(baseUrlInterceptor);
    // For release builds nothing is added, the list is empty. For debug builds Stetho interceptor is added.
    for (Interceptor networkInterceptor : networkInterceptors) {
        okHttpBuilder.addNetworkInterceptor(networkInterceptor);
    }
    return okHttpBuilder.build();
}
Also used : OkHttpClient(okhttp3.OkHttpClient) AuthenticationInterceptor(com.example.networking.AuthenticationInterceptor) Interceptor(okhttp3.Interceptor) AuthenticationInterceptor(com.example.networking.AuthenticationInterceptor) BaseUrlInterceptor(com.example.networking.BaseUrlInterceptor) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) Singleton(javax.inject.Singleton) Provides(dagger.Provides)

Aggregations

AuthenticationInterceptor (com.example.networking.AuthenticationInterceptor)1 BaseUrlInterceptor (com.example.networking.BaseUrlInterceptor)1 Provides (dagger.Provides)1 Singleton (javax.inject.Singleton)1 Interceptor (okhttp3.Interceptor)1 OkHttpClient (okhttp3.OkHttpClient)1 HttpLoggingInterceptor (okhttp3.logging.HttpLoggingInterceptor)1