Search in sources :

Example 1 with GsonConverter

use of retrofit.converter.GsonConverter 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));
}
Also used : GsonConverter(retrofit.converter.GsonConverter) RMPClient(com.tevinjeffrey.rmp.client.RMPClient) OkHttpClient(com.squareup.okhttp.OkHttpClient) ClientService(com.tevinjeffrey.rmp.client.ClientService) OkClient(retrofit.client.OkClient) RestAdapter(retrofit.RestAdapter) Singleton(javax.inject.Singleton) Provides(dagger.Provides)

Example 2 with GsonConverter

use of retrofit.converter.GsonConverter 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);
}
Also used : GsonConverter(retrofit.converter.GsonConverter) OkHttpClient(com.squareup.okhttp.OkHttpClient) OkClient(retrofit.client.OkClient) RestAdapter(retrofit.RestAdapter) Singleton(javax.inject.Singleton) Provides(dagger.Provides)

Example 3 with GsonConverter

use of retrofit.converter.GsonConverter in project divide by HiddenStage.

the class AbstractWebManager method createRestAdapter.

private RestAdapter createRestAdapter(Config config) {
    RestAdapter.Builder builder = new RestAdapter.Builder();
    builder.setClient(new OkClient(config.client)).setEndpoint(config.serverUrl).setLogLevel(RestAdapter.LogLevel.FULL).setLog(new RestAdapter.Log() {

        @Override
        public void log(String s) {
            retrologger.debug(s);
        }
    }).setConverter(new GsonConverter(new Gson())).setRequestInterceptor(new RequestInterceptor() {

        @Override
        public void intercept(RequestFacade requestFacade) {
            onRequest(requestFacade);
        }
    }).setProfiler(new Profiler() {

        @Override
        public Object beforeCall() {
            return null;
        }

        @Override
        public void afterCall(RequestInformation requestInformation, long l, int i, Object o) {
            retrologger.error("afterCall(" + requestInformation.getRelativePath() + ":" + requestInformation.getMethod() + ": " + i + " : " + o);
            requestEventPublisher.onNext(new RequestObject(requestInformation, l, i, o));
        }
    });
    return builder.build();
}
Also used : GsonConverter(retrofit.converter.GsonConverter) OkClient(retrofit.client.OkClient) Gson(com.google.gson.Gson) RequestInterceptor(retrofit.RequestInterceptor) RequestFacade(retrofit.RequestInterceptor.RequestFacade) Profiler(retrofit.Profiler) RestAdapter(retrofit.RestAdapter)

Aggregations

RestAdapter (retrofit.RestAdapter)3 OkClient (retrofit.client.OkClient)3 GsonConverter (retrofit.converter.GsonConverter)3 OkHttpClient (com.squareup.okhttp.OkHttpClient)2 Provides (dagger.Provides)2 Singleton (javax.inject.Singleton)2 Gson (com.google.gson.Gson)1 ClientService (com.tevinjeffrey.rmp.client.ClientService)1 RMPClient (com.tevinjeffrey.rmp.client.RMPClient)1 Profiler (retrofit.Profiler)1 RequestInterceptor (retrofit.RequestInterceptor)1 RequestFacade (retrofit.RequestInterceptor.RequestFacade)1