Search in sources :

Example 1 with GzipRequestInterceptor

use of com.eveningoutpost.dexdrip.cgm.nsfollow.GzipRequestInterceptor in project xDrip by NightscoutFoundation.

the class RetrofitBase method getRetrofitInstance.

// TODO make fully reusable
public static Retrofit getRetrofitInstance(final String TAG, final String url, boolean useGzip) throws IllegalArgumentException {
    Retrofit instance = instances.get(TAG);
    if (instance == null || !urls.get(TAG).equals(url)) {
        synchronized (instances) {
            if (emptyString(url)) {
                UserError.Log.d(TAG, "Empty url - cannot create instance");
                return null;
            }
            UserError.Log.d(TAG, "Creating new instance for: " + url);
            final OkHttpClient.Builder httpClient = enableTls12OnPreLollipop(new OkHttpClient.Builder()).addInterceptor(new InfoInterceptor(TAG)).addInterceptor(useGzip ? new GzipRequestInterceptor() : new NullInterceptor());
            if (UserError.ExtraLogTags.shouldLogTag(TAG, android.util.Log.VERBOSE)) {
                UserError.Log.v(TAG, "Enable logging of request and response lines and their respective headers and bodies.");
                final HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
                httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
                httpLoggingInterceptor.redactHeader("Authorization");
                httpLoggingInterceptor.redactHeader("Cookie");
                httpClient.addInterceptor(httpLoggingInterceptor);
            }
            instances.put(TAG, instance = new retrofit2.Retrofit.Builder().baseUrl(url).client(httpClient.build()).addConverterFactory(createGsonConverter(Dex_Constants.TREND_ARROW_VALUES.class, new ShareTrendDeserializer())).build());
            // save creation url for quick search
            urls.put(TAG, url);
        }
    }
    return instance;
}
Also used : Retrofit(retrofit2.Retrofit) OkHttpClient(okhttp3.OkHttpClient) GzipRequestInterceptor(com.eveningoutpost.dexdrip.cgm.nsfollow.GzipRequestInterceptor) InfoInterceptor(com.eveningoutpost.dexdrip.tidepool.InfoInterceptor) GsonBuilder(com.google.gson.GsonBuilder) Dex_Constants(com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.Dex_Constants) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor)

Example 2 with GzipRequestInterceptor

use of com.eveningoutpost.dexdrip.cgm.nsfollow.GzipRequestInterceptor in project xDrip-plus by jamorham.

the class RetrofitBase method getRetrofitInstance.

// TODO make fully reusable
public static Retrofit getRetrofitInstance(final String TAG, final String url, boolean useGzip) throws IllegalArgumentException {
    Retrofit instance = instances.get(TAG);
    if (instance == null || !urls.get(TAG).equals(url)) {
        synchronized (instances) {
            if (emptyString(url)) {
                UserError.Log.d(TAG, "Empty url - cannot create instance");
                return null;
            }
            UserError.Log.d(TAG, "Creating new instance for: " + url);
            final OkHttpClient.Builder httpClient = enableTls12OnPreLollipop(new OkHttpClient.Builder()).addInterceptor(new InfoInterceptor(TAG)).addInterceptor(useGzip ? new GzipRequestInterceptor() : new NullInterceptor());
            if (UserError.ExtraLogTags.shouldLogTag(TAG, android.util.Log.VERBOSE)) {
                UserError.Log.v(TAG, "Enable logging of request and response lines and their respective headers and bodies.");
                final HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
                httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
                httpLoggingInterceptor.redactHeader("Authorization");
                httpLoggingInterceptor.redactHeader("Cookie");
                httpClient.addInterceptor(httpLoggingInterceptor);
            }
            instances.put(TAG, instance = new retrofit2.Retrofit.Builder().baseUrl(url).client(httpClient.build()).addConverterFactory(createGsonConverter(Dex_Constants.TREND_ARROW_VALUES.class, new ShareTrendDeserializer())).build());
            // save creation url for quick search
            urls.put(TAG, url);
        }
    }
    return instance;
}
Also used : Retrofit(retrofit2.Retrofit) OkHttpClient(okhttp3.OkHttpClient) GzipRequestInterceptor(com.eveningoutpost.dexdrip.cgm.nsfollow.GzipRequestInterceptor) InfoInterceptor(com.eveningoutpost.dexdrip.tidepool.InfoInterceptor) GsonBuilder(com.google.gson.GsonBuilder) Dex_Constants(com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.Dex_Constants) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor)

Aggregations

Dex_Constants (com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.Dex_Constants)2 GzipRequestInterceptor (com.eveningoutpost.dexdrip.cgm.nsfollow.GzipRequestInterceptor)2 InfoInterceptor (com.eveningoutpost.dexdrip.tidepool.InfoInterceptor)2 GsonBuilder (com.google.gson.GsonBuilder)2 OkHttpClient (okhttp3.OkHttpClient)2 HttpLoggingInterceptor (okhttp3.logging.HttpLoggingInterceptor)2 Retrofit (retrofit2.Retrofit)2