Search in sources :

Example 1 with InfoInterceptor

use of com.eveningoutpost.dexdrip.tidepool.InfoInterceptor in project xDrip by NightscoutFoundation.

the class NightscoutFollow method getRetrofitInstance.

// TODO make reusable
public static Retrofit getRetrofitInstance() throws IllegalArgumentException {
    if (retrofit == null) {
        final String url = getUrl();
        if (emptyString(url)) {
            UserError.Log.d(TAG, "Empty url - cannot create instance");
            return null;
        }
        final HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
        if (D) {
            httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        }
        final OkHttpClient client = enableTls12OnPreLollipop(new OkHttpClient.Builder()).addInterceptor(httpLoggingInterceptor).addInterceptor(new InfoInterceptor(TAG)).addInterceptor(new GzipRequestInterceptor()).build();
        final Gson gson = new GsonBuilder().registerTypeAdapterFactory(UNRELIABLE_INTEGER_FACTORY).create();
        retrofit = new retrofit2.Retrofit.Builder().baseUrl(url).client(client).addConverterFactory(GsonConverterFactory.create(gson)).build();
    }
    return retrofit;
}
Also used : Retrofit(retrofit2.Retrofit) OkHttpClient(okhttp3.OkHttpClient) GsonBuilder(com.google.gson.GsonBuilder) InfoInterceptor(com.eveningoutpost.dexdrip.tidepool.InfoInterceptor) Gson(com.google.gson.Gson) JoH.emptyString(com.eveningoutpost.dexdrip.Models.JoH.emptyString) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor)

Example 2 with InfoInterceptor

use of com.eveningoutpost.dexdrip.tidepool.InfoInterceptor in project xDrip-plus by jamorham.

the class WebDeposit method getRetrofitInstance.

static Retrofit getRetrofitInstance() {
    if (retrofit == null) {
        final HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
        if (D) {
            httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        }
        final OkHttpClient client = enableTls12OnPreLollipop(new OkHttpClient.Builder()).addInterceptor(httpLoggingInterceptor).addInterceptor(new InfoInterceptor(TAG)).readTimeout(600, TimeUnit.SECONDS).connectTimeout(30, TimeUnit.SECONDS).build();
        retrofit = new retrofit2.Retrofit.Builder().baseUrl(getUrl()).client(client).addConverterFactory(GsonConverterFactory.create()).build();
    }
    return retrofit;
}
Also used : Retrofit(retrofit2.Retrofit) OkHttpClient(okhttp3.OkHttpClient) InfoInterceptor(com.eveningoutpost.dexdrip.tidepool.InfoInterceptor) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor)

Example 3 with InfoInterceptor

use of com.eveningoutpost.dexdrip.tidepool.InfoInterceptor 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 4 with InfoInterceptor

use of com.eveningoutpost.dexdrip.tidepool.InfoInterceptor in project xDrip by NightscoutFoundation.

the class WebDeposit method getRetrofitInstance.

static Retrofit getRetrofitInstance() {
    if (retrofit == null) {
        final HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
        if (D) {
            httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        }
        final OkHttpClient client = enableTls12OnPreLollipop(new OkHttpClient.Builder()).addInterceptor(httpLoggingInterceptor).addInterceptor(new InfoInterceptor(TAG)).readTimeout(600, TimeUnit.SECONDS).connectTimeout(30, TimeUnit.SECONDS).build();
        retrofit = new retrofit2.Retrofit.Builder().baseUrl(getUrl()).client(client).addConverterFactory(GsonConverterFactory.create()).build();
    }
    return retrofit;
}
Also used : Retrofit(retrofit2.Retrofit) OkHttpClient(okhttp3.OkHttpClient) InfoInterceptor(com.eveningoutpost.dexdrip.tidepool.InfoInterceptor) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor)

Example 5 with InfoInterceptor

use of com.eveningoutpost.dexdrip.tidepool.InfoInterceptor 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

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