use of retrofit.client.OkClient in project remusic by aa112901.
the class RestServiceFactory method create.
public static <T> T create(final Context context, String baseUrl, Class<T> clazz) {
final OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.setCache(new Cache(context.getApplicationContext().getCacheDir(), CACHE_SIZE));
okHttpClient.setConnectTimeout(40, TimeUnit.SECONDS);
RequestInterceptor interceptor = new RequestInterceptor() {
@Override
public void intercept(RequestFacade request) {
// 7-days cache
request.addHeader("Cache-Control", String.format("max-age=%d,max-stale=%d", Integer.valueOf(60 * 60 * 24 * 7), Integer.valueOf(31536000)));
request.addHeader("Connection", "keep-alive");
}
};
RestAdapter.Builder builder = new RestAdapter.Builder().setEndpoint(baseUrl).setRequestInterceptor(interceptor).setClient(new OkClient(okHttpClient));
return builder.build().create(clazz);
}
use of retrofit.client.OkClient in project android by testpress.
the class TestpressService method getRestAdapter.
private RestAdapter getRestAdapter() {
if (authToken != null) {
OkHttpClient client = new OkHttpClient();
Interceptor interceptor = new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request.Builder header = chain.request().newBuilder();
header.addHeader("Authorization", getAuthToken());
return chain.proceed(header.build());
}
};
client.networkInterceptors().add(interceptor);
restAdapter.setClient(new OkClient(client));
}
return restAdapter.build();
}
use of retrofit.client.OkClient in project Timber by naman14.
the class RestServiceFactory method createStatic.
public static <T> T createStatic(final Context context, String baseUrl, Class<T> clazz) {
final OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.setCache(new Cache(context.getApplicationContext().getCacheDir(), CACHE_SIZE));
okHttpClient.setConnectTimeout(40, TimeUnit.SECONDS);
RequestInterceptor interceptor = new RequestInterceptor() {
PreferencesUtility prefs = PreferencesUtility.getInstance(context);
@Override
public void intercept(RequestFacade request) {
// 7-days cache
request.addHeader("Cache-Control", String.format("max-age=%d,%smax-stale=%d", Integer.valueOf(60 * 60 * 24 * 7), prefs.loadArtistAndAlbumImages() ? "" : "only-if-cached,", Integer.valueOf(31536000)));
request.addHeader("Connection", "keep-alive");
}
};
RestAdapter.Builder builder = new RestAdapter.Builder().setEndpoint(baseUrl).setRequestInterceptor(interceptor).setClient(new OkClient(okHttpClient));
return builder.build().create(clazz);
}
use of retrofit.client.OkClient in project Rutgers-Course-Tracker by tevjef.
the class ClientModule method providesRMPClient.
@Provides
@Singleton
public RMPClient providesRMPClient(OkHttpClient client, Gson gson) {
OkHttpClient okClient = client.clone();
okClient.setConnectTimeout(CONNECT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
okClient.setReadTimeout(READ_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint("http://rutgersapp.tevindev.me:8080/").setLogLevel(RestAdapter.LogLevel.FULL).setConverter(new GsonConverter(gson)).setClient(new OkClient(okClient)).build();
return new RMPClient(restAdapter.create(ClientService.class));
}
use of retrofit.client.OkClient in project Rutgers-Course-Tracker by tevjef.
the class RetroRutgersModule method providesRutgersRestAdapter.
@Provides
@Singleton
public RetroRutgersService providesRutgersRestAdapter(OkHttpClient client, Gson gson) {
OkHttpClient okClient = client.clone();
okClient.networkInterceptors().add(getCacheControlInterceptor(TimeUnit.SECONDS.toMillis(5)));
return new RestAdapter.Builder().setEndpoint("http://sis.rutgers.edu/soc/").setLogLevel(RestAdapter.LogLevel.HEADERS_AND_ARGS).setErrorHandler(new MyErrorHandler()).setClient(new OkClient(okClient)).setConverter(new GsonConverter(gson)).build().create(RetroRutgersService.class);
}
Aggregations