-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApiClient_im.java
49 lines (34 loc) · 1.36 KB
/
ApiClient_im.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.example.ajit.imageupload.apiBase;
import com.example.ajit.imageupload.util.Global;
import java.util.concurrent.TimeUnit;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
/**
* Created by PC-DESTOP on 9/25/2017.
*/
public class ApiClient {
private static Retrofit retrofit = null;
public static Retrofit getClient() {
if (retrofit == null) {
retrofit = new Retrofit.Builder()
.baseUrl(Global.url)
.addConverterFactory(GsonConverterFactory.create())
.client(getOkHttpClient())
.build();
}
return retrofit;
}
//get OkHttp instance
private static OkHttpClient getOkHttpClient() {
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder builder = new OkHttpClient.Builder();
// builder.interceptors().add(getHeadersForApis());
builder.interceptors().add(httpLoggingInterceptor);
builder.readTimeout(90, TimeUnit.SECONDS);
builder.connectTimeout(90, TimeUnit.SECONDS);
return builder.build();
}
}