2021-12-10 10:21:06 +00:00
|
|
|
package cc.pogoda.mobile.meteosystem.web;
|
2020-12-16 19:26:53 +00:00
|
|
|
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
import com.google.gson.GsonBuilder;
|
|
|
|
|
2021-10-16 20:41:14 +00:00
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
2021-12-10 10:21:06 +00:00
|
|
|
import cc.pogoda.mobile.meteosystem.type.CustomLocalDateTime;
|
|
|
|
import cc.pogoda.mobile.meteosystem.web.deserializer.CustomLocalDateTimeDeserializer;
|
2020-12-16 19:26:53 +00:00
|
|
|
import okhttp3.OkHttpClient;
|
2022-05-03 17:56:00 +00:00
|
|
|
import okhttp3.logging.HttpLoggingInterceptor;
|
2020-12-16 19:26:53 +00:00
|
|
|
import retrofit2.Retrofit;
|
|
|
|
import retrofit2.converter.gson.GsonConverterFactory;
|
|
|
|
|
|
|
|
public class RestClientConfig {
|
|
|
|
|
|
|
|
public Retrofit getWeatherStationClient() {
|
|
|
|
Retrofit out = null;
|
|
|
|
|
|
|
|
Gson gson = new GsonBuilder().registerTypeAdapter(CustomLocalDateTime.class, new CustomLocalDateTimeDeserializer()).setLenient().create();
|
|
|
|
|
2021-10-16 20:41:14 +00:00
|
|
|
OkHttpClient.Builder builder = new OkHttpClient.Builder();
|
|
|
|
|
|
|
|
builder.readTimeout(20, TimeUnit.SECONDS);
|
|
|
|
builder.writeTimeout(20, TimeUnit.SECONDS);
|
|
|
|
builder.connectTimeout(20, TimeUnit.SECONDS);
|
|
|
|
builder.callTimeout(20, TimeUnit.SECONDS);
|
|
|
|
|
2022-05-03 17:56:00 +00:00
|
|
|
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
|
|
|
|
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS);
|
|
|
|
|
|
|
|
OkHttpClient client = builder.addInterceptor(loggingInterceptor).build();//new OkHttpClient(builder);
|
2020-12-16 19:26:53 +00:00
|
|
|
|
|
|
|
out = new Retrofit.Builder().baseUrl("http://pogoda.cc:8080/").addConverterFactory(GsonConverterFactory.create(gson)).client(client).build();
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
}
|