Advertisement
Guest User

CODING1

a guest
Dec 8th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. RestService restService;
  2. String baseUrl;
  3.  
  4. public static RestService instance;
  5.  
  6. public RetrofitHelper() {
  7. OkHttpClient.Builder okHttpClientBuilder = new OkHttpClient.Builder();
  8. okHttpClientBuilder.readTimeout(RestConstant.CONNECTION_TIMEOUT, TimeUnit.MINUTES);
  9. okHttpClientBuilder.connectTimeout(RestConstant.CONNECTION_TIMEOUT, TimeUnit.MINUTES);
  10. okHttpClientBuilder.writeTimeout(RestConstant.CONNECTION_TIMEOUT, TimeUnit.MINUTES);
  11.  
  12. HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
  13. logging.setLevel(HttpLoggingInterceptor.Level.BODY);
  14. okHttpClientBuilder.addInterceptor(logging);
  15.  
  16. OkHttpClient okHttpClient = new OkHttpClient.Builder()
  17. .addInterceptor(new Interceptor() {
  18. @Override
  19. public Response intercept(Chain chain) throws IOException {
  20. Request request = chain.request().newBuilder().addHeader("Authorization", "Basic c3RsdXNlcjphbGZhY2FydFNUTDIzNDIzNA==").build();
  21. return chain.proceed(request);
  22. }
  23. })
  24. .connectTimeout(RestConstant.CONNECTION_TIMEOUT, TimeUnit.MINUTES)
  25. .readTimeout(RestConstant.CONNECTION_TIMEOUT, TimeUnit.MINUTES)
  26. .build();
  27.  
  28. Gson gson = new GsonBuilder()
  29. .setLenient()
  30. .create();
  31. Retrofit retrofit = new Retrofit.Builder()
  32. .client(okHttpClient)
  33. .baseUrl(BuildConfig.HOST)
  34. .addConverterFactory(GsonConverterFactory.create())
  35. .build();
  36.  
  37. restService = retrofit.create(RestService.class);
  38. }
  39.  
  40. public RestService getService() {
  41. return restService;
  42. }
  43.  
  44. public String getBaseUrl() {
  45. return baseUrl;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement