Advertisement
Guest User

RetrofitClient

a guest
Oct 19th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.86 KB | None | 0 0
  1. package com.khibar.simaskes.apihelper;
  2.  
  3. import okhttp3.OkHttpClient;
  4. import okhttp3.logging.HttpLoggingInterceptor;
  5. import retrofit2.Retrofit;
  6. import retrofit2.converter.gson.GsonConverterFactory;
  7.  
  8. public class RetrofitClient {
  9.     private static Retrofit retrofit = null;
  10.  
  11.     public static Retrofit getClient(String baseUrl){
  12.         HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
  13.         interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
  14.         OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();
  15.  
  16.         if (retrofit == null ){
  17.             retrofit = new Retrofit.Builder()
  18.                     .baseUrl(baseUrl)
  19.                     .addConverterFactory(GsonConverterFactory.create())
  20.                     .client(client)
  21.                     .build();
  22.         }
  23.         return retrofit;
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement