package network;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.concurrent.TimeUnit;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.converter.scalars.ScalarsConverterFactory;
public class ApiClient
{
private static final String BASE_URL="http://www.gkmaza.com/apps/gujarati_suvichar/";
private static Retrofit retrofit=null;
private static OkHttpClient client;
public static Retrofit getClient()
{
if(retrofit==null)
{
HttpLoggingInterceptor interceptor=new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
try
{
client = new OkHttpClient.Builder()
.followRedirects(true)
.followSslRedirects(true)
.sslSocketFactory(new TLSSocketFactory())
.retryOnConnectionFailure(true)
.addInterceptor(interceptor)
.connectTimeout(30, TimeUnit.MINUTES)
.readTimeout(30, TimeUnit.MINUTES)
.addInterceptor(interceptor)
.build();
}catch (KeyManagementException e)
{
e.printStackTrace();
}catch (NoSuchAlgorithmException e)
{
e.printStackTrace();
}
retrofit=new Retrofit.Builder()
.baseUrl(BASE_URL)
.client(client)
.addConverterFactory(new StringConverter())
.addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}
}
No comments:
Post a Comment