Search in sources :

Example 1 with PersistentCookieStore

use of com.zimincom.mafiaonline.PersistentCookieStore in project 2017-01-HUDI-MAC-CHAR by NHNNEXT.

the class ServiceGenerator method createService.

public static <S> S createService(Class<S> serviceClass, Context context) {
    HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
    if (BuildConfig.DEBUG) {
        logging.setLevel(HttpLoggingInterceptor.Level.BODY);
    } else {
        logging.setLevel(HttpLoggingInterceptor.Level.NONE);
    }
    PersistentCookieStore cookieStore = new PersistentCookieStore(context);
    java.net.CookieManager cookieManager = new java.net.CookieManager(cookieStore, CookiePolicy.ACCEPT_ALL);
    OkHttpClient.Builder httpClient = new OkHttpClient.Builder().cookieJar(new JavaNetCookieJar(cookieManager)).addInterceptor(logging).addNetworkInterceptor(new StethoInterceptor());
    Gson gson = new GsonBuilder().setLenient().create();
    Retrofit retorfit = new Retrofit.Builder().baseUrl(MafiaRemoteService.BASE_URL).addConverterFactory(GsonConverterFactory.create(gson)).client(httpClient.build()).build();
    return retorfit.create(serviceClass);
}
Also used : PersistentCookieStore(com.zimincom.mafiaonline.PersistentCookieStore) JavaNetCookieJar(okhttp3.internal.JavaNetCookieJar) OkHttpClient(okhttp3.OkHttpClient) GsonBuilder(com.google.gson.GsonBuilder) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) Retrofit(retrofit2.Retrofit) StethoInterceptor(com.facebook.stetho.okhttp3.StethoInterceptor) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor)

Aggregations

StethoInterceptor (com.facebook.stetho.okhttp3.StethoInterceptor)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 PersistentCookieStore (com.zimincom.mafiaonline.PersistentCookieStore)1 OkHttpClient (okhttp3.OkHttpClient)1 JavaNetCookieJar (okhttp3.internal.JavaNetCookieJar)1 HttpLoggingInterceptor (okhttp3.logging.HttpLoggingInterceptor)1 Retrofit (retrofit2.Retrofit)1