retrofit.converter.GsonConverter Java Examples

The following examples show how to use retrofit.converter.GsonConverter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: qvod   Author: zhao-mingjian   File: HttpUtils.java    License: MIT License 6 votes vote down vote up
private RestAdapter getRestAdapter(String HOST) {
    File cacheFile = new File(mContext.getApplicationContext().getCacheDir().getAbsolutePath(), "videoCache");
    int cacheSize = 10 * 1024 * 1024;
    Cache cache = new Cache(cacheFile, cacheSize);
    OkHttpClient.Builder okBuilder = new OkHttpClient.Builder();
    okBuilder.cache(cache);
    okBuilder.readTimeout(20, TimeUnit.SECONDS);//设置读取新连接超时
    okBuilder.connectTimeout(10, TimeUnit.SECONDS);//设置新连接的默认连接超时
    okBuilder.writeTimeout(20, TimeUnit.SECONDS);//设置默认为新连接编写超时
    OkHttpClient client = okBuilder.build();
    //
    RestAdapter.Builder restBuilder = new RestAdapter.Builder();
    restBuilder.setClient(new Ok3Client(client));
    restBuilder.setEndpoint(HOST);//URL_HOST
    restBuilder.setConverter(new GsonConverter(getGson()));//解析
    //
    RestAdapter videoRestAdapter = restBuilder.build();
    videoRestAdapter.setLogLevel(LOG_LEVEL);
    return videoRestAdapter;
}
 
Example #2
Source Project: DroidNubeKit   Author: jaumecornado   File: DroidNubeKit.java    License: MIT License 6 votes vote down vote up
/**
 * Initializes the CloudKit Service
 */
private DroidNubeKit() {

    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.registerTypeAdapter(new TypeToken<Map<String, DNKRecordField>>() {}.getType(), new DNKRecordFieldDeserializer());

    RequestInterceptor requestInterceptor = new RequestInterceptor() {
        @Override
        public void intercept(RequestInterceptor.RequestFacade request) {
            if(ckSession != null)
                request.addQueryParam("ckSession", ckSession);

        }
    };

    RestAdapter restAdapter = new RestAdapter.Builder()
            .setEndpoint(DroidNubeKitConstants.API_ENDPOINT)
            .setLogLevel(RestAdapter.LogLevel.FULL)
            .setConverter(new GsonConverter(gsonBuilder.create()))
            .setRequestInterceptor(requestInterceptor)
            .setErrorHandler(new DNKErrorHandler())
            .build();

    cloudKitService = restAdapter.create(CloudKitService.class);
}
 
Example #3
Source Project: wear-notify-for-reddit   Author: emmaguy   File: AppModule.java    License: Apache License 2.0 6 votes vote down vote up
@Provides @Singleton public RedditService provideRedditService(Gson gson, Resources resources,
                                                               UserStorage userStorage,
                                                               TokenStorage tokenStorage,
                                                               RedditAuthenticationService authService) {
    final GsonConverter gsonConverter = new GsonConverter(gson);

    final OkHttpClient okHttpClient = new OkHttpClient();

    RedditService authenticatedRedditService = new RestAdapter.Builder().setEndpoint(Constants.ENDPOINT_URL_OAUTH_REDDIT)
            .setClient(new OkClient(okHttpClient))
            .setConverter(new DelegatingConverter(gsonConverter,
                    new TokenConverter(gsonConverter),
                    new PostConverter(gsonConverter, resources, userStorage, new HtmlDecoder()),
                    new MarkAsReadConverter(),
                    new SubscriptionConverter(),
                    new CommentsConverter(gson, gsonConverter, resources, userStorage)))
            .build()
            .create(RedditService.class);

    okHttpClient.networkInterceptors()
            .add(new TokenRefreshInterceptor(tokenStorage, authService));
    okHttpClient.setRetryOnConnectionFailure(true);
    return authenticatedRedditService;
}
 
Example #4
Source Project: android-test-demo   Author: abdyer   File: DebugApiServiceModule.java    License: MIT License 6 votes vote down vote up
@Provides @Singleton
public ApiService provideApiService() {
    if(mockMode) {
        return new MockApiService();
    }
    else {
        Gson gson = new GsonBuilder()
                .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
                .create();
        return new RestAdapter.Builder()
                .setEndpoint(ApiService.API_URL)
                .setConverter(new GsonConverter(gson))
                .setLogLevel(RestAdapter.LogLevel.FULL).setLog(new AndroidLog("API"))
                .build()
                .create(ApiService.class);
    }
}
 
Example #5
Source Project: Amphitheatre   Author: jerrellmardis   File: TMDbClient.java    License: Apache License 2.0 6 votes vote down vote up
private static TMDbService getService() {
    Gson gson = new GsonBuilder()
            .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
            .create();

    if (service == null) {
        RestAdapter restAdapter = new RestAdapter.Builder()
                .setConverter(new GsonConverter(gson))
                .setEndpoint(ApiConstants.TMDB_SERVER_URL)
                .setRequestInterceptor(new RequestInterceptor() {
                    @Override
                    public void intercept(RequestFacade request) {
                        request.addQueryParam("api_key", ApiConstants.TMDB_SERVER_API_KEY);
                    }
                })
                .build();
        service = restAdapter.create(TMDbService.class);
    }
    return service;
}
 
Example #6
Source Project: CatanArchitecture   Author: Guardiola31337   File: DropboxRestClient.java    License: Apache License 2.0 5 votes vote down vote up
DropboxRestClient() {
  Gson gson = new GsonBuilder().setDateFormat("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'SSS'Z'")
      .create();

  RestAdapter restAdapter = new RestAdapter.Builder().setLogLevel(RestAdapter.LogLevel.FULL)
      .setEndpoint(BASE_URL)
      .setConverter(new GsonConverter(gson))
      .build();

  apiService = restAdapter.create(DropboxAPI.class);
}
 
Example #7
Source Project: CatanArchitecture   Author: Guardiola31337   File: DropboxFoldersModuleTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test public void mockWebServerWorking() throws Exception {
  MockWebServer server = new MockWebServer();
  Gson gson = new GsonBuilder().setDateFormat("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'SSS'Z'").create();

  // Schedule some responses.
  server.enqueue(new MockResponse().addHeader("Content-Type", "application/json; charset=utf-8")
      .setBody(
          "{\"contents\":[{\"name\":\"Dropbox Foo\"},{\"name\":\"Dropbox test\"},{\"name\":\"Dropbox folDER\"}]}"));

  // Start the server.
  server.start();

  RestAdapter restAdapter = new RestAdapter.Builder().setExecutors(new Executor() {
    @Override public void execute(Runnable command) {
      command.run();
    }
  }, null)
      .setEndpoint(server.getUrl("/").toString())
      .setConverter(new GsonConverter(gson))
      .build();
  DropboxAPI apiService = restAdapter.create(DropboxAPI.class);

  EventsPort eventsPort = new InMemoryEventsAdapter();
  StoragePort storagePort = new DropboxStorageAdapter(eventsPort, apiService);
  FoldersModule foldersModule = new FoldersModule(storagePort, eventsPort);

  eventsPort.on(LoadFoldersFinished.class, new Callback<LoadFoldersFinished>() {
    @Override public void call(LoadFoldersFinished event) {
      assertEquals("Dropbox Foo", event.folders.get(0).obtainName());
      assertEquals("Dropbox test", event.folders.get(1).obtainName());
      assertEquals("Dropbox folDER", event.folders.get(2).obtainName());
    }
  });

  foldersModule.run();
  eventsPort.broadcast(new LoadFoldersCommand());

  // Shut down the server. Instances cannot be reused.
  server.shutdown();
}
 
Example #8
Source Project: thunderboard-android   Author: SiliconLabs   File: ShortenUrl.java    License: Apache License 2.0 5 votes vote down vote up
private ShortenUrl() {
    // Create a very simple REST adapter which points the API_URL endpoint.
    restAdapter = new RestAdapter.Builder()
            .setEndpoint(API_URL)
            .setConverter(new GsonConverter(getGsonBuilder().create()))
            .setLogLevel(BuildConfig.DEBUG ? RestAdapter.LogLevel.FULL : RestAdapter.LogLevel.NONE)
            .build();

    // Create an instance of our Shorten API interface.
    shorten = restAdapter.create(Shorten.class);
}
 
Example #9
Source Project: Leaderboards   Author: AlbertGrobas   File: RestClient.java    License: Apache License 2.0 5 votes vote down vote up
private void rebuildClient() {

        RestAdapter adapter = new RestAdapter.Builder()
            .setEndpoint("http://"+host)
            .setConverter(new GsonConverter(realmGson))
            .setLogLevel(RestAdapter.LogLevel.HEADERS)
            .setLog(new AndroidLog("wow-api"))
            .build();
        apiClient = adapter.create(BlizzardApiClient.class);
    }
 
Example #10
Source Project: GankDaily   Author: maoruibin   File: MainRetrofit.java    License: GNU General Public License v3.0 5 votes vote down vote up
MainRetrofit() {
    OkHttpClient client = new OkHttpClient();
    client.setReadTimeout(21, TimeUnit.SECONDS);
    RestAdapter restAdapter = new RestAdapter.Builder()
            .setClient(new OkClient(client))
            .setEndpoint(MainFactory.HOST)
            .setConverter(new GsonConverter(gson))
            .setLogLevel(RestAdapter.LogLevel.FULL)
            .build();
    mService = restAdapter.create(GuDong.class);
}
 
Example #11
Source Project: CourseraDemoApp   Author: richk   File: NetworkingModule.java    License: Apache License 2.0 5 votes vote down vote up
@Provides @Singleton
public RestAdapter provideRestAdapter() {
    return new RestAdapter.Builder()
            .setEndpoint(mBaseUrl)
            .setConverter(new GsonConverter(new Gson()))
            .setLogLevel((BuildConfig.DEBUG ?
                    RestAdapter.LogLevel.FULL : RestAdapter.LogLevel.NONE))
            .build();
}
 
Example #12
Source Project: NightWatch   Author: StephenBlackWasAlreadyTaken   File: ShareRest.java    License: GNU General Public License v3.0 5 votes vote down vote up
private RestAdapter.Builder authoirizeAdapterBuilder() {
    RestAdapter.Builder adapterBuilder = new RestAdapter.Builder();
    adapterBuilder
            .setClient(client)
            .setLogLevel(RestAdapter.LogLevel.FULL).setLog(new AndroidLog("SHAREREST"))
            .setEndpoint("https://share1.dexcom.com/ShareWebServices/Services")
            .setRequestInterceptor(authorizationRequestInterceptor)
            .setConverter(new GsonConverter(new GsonBuilder()
                    .excludeFieldsWithoutExposeAnnotation()
                    .create()));
    return adapterBuilder;
}
 
Example #13
Source Project: NightWatch   Author: StephenBlackWasAlreadyTaken   File: ShareRest.java    License: GNU General Public License v3.0 5 votes vote down vote up
private RestAdapter.Builder getBgAdapterBuilder() {
    RestAdapter.Builder adapterBuilder = new RestAdapter.Builder();
    adapterBuilder
            .setClient(client)
            .setLogLevel(RestAdapter.LogLevel.FULL).setLog(new AndroidLog("SHAREREST"))
            .setEndpoint("https://share1.dexcom.com/ShareWebServices/Services")
            .setRequestInterceptor(getBgRequestInterceptor)
            .setConverter(new GsonConverter(new GsonBuilder()
                    .excludeFieldsWithoutExposeAnnotation()
                    .create()));
    return adapterBuilder;
}
 
Example #14
Source Project: Gank-Veaer   Author: Veaer   File: LineRetrofit.java    License: GNU General Public License v3.0 5 votes vote down vote up
LineRetrofit() {
    OkHttpClient client = new OkHttpClient();
    client.setReadTimeout(12, TimeUnit.SECONDS);
    int cacheSize = 10 * 1024 * 1024; // 10 MiB
    cache = new Cache(FileUtils.getHttpCacheDir(), cacheSize);
    client.setCache(cache);
    client.networkInterceptors().add(new CacheInterceptor());

    RestAdapter restAdapter = new RestAdapter.Builder().setClient(new OkClient(client))
        .setEndpoint("http://gank.avosapps.com/api/")
        .setConverter(new GsonConverter(gson))
        .build();
    service = restAdapter.create(Line.class);
}
 
Example #15
Source Project: githot   Author: andyiac   File: DataModule.java    License: Apache License 2.0 5 votes vote down vote up
@Provides
    @Singleton
    RestAdapter provideRestAdapter(Gson gson, OkHttpClient okHttpClient, ErrorHandler errorHandler) {
        return new RestAdapter.Builder()
                .setErrorHandler(errorHandler)
                .setClient(new OkClient(okHttpClient))
                .setConverter(new GsonConverter(gson))
                .setLogLevel(RestAdapter.LogLevel.BASIC)
//                .setEndpoint("http://mock-api.com/TyTabSFqXNyqMpNw.mock")
                .setEndpoint("https://api.github.com")
                .build();
    }
 
Example #16
Source Project: githot   Author: andyiac   File: DataModule.java    License: Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
FirService provideFirService(Gson gson, OkHttpClient okHttpClient, ErrorHandler errorHandler) {
    RestAdapter restAdapter = new RestAdapter.Builder()
            .setErrorHandler(errorHandler)
            .setClient(new OkClient(okHttpClient))
            .setConverter(new GsonConverter(gson))
            .setLogLevel(RestAdapter.LogLevel.BASIC)
            .setEndpoint("http://api.fir.im")
            .build();
    return restAdapter.create(FirService.class);
}
 
Example #17
Source Project: githot   Author: andyiac   File: DataModule.java    License: Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
ReposTrendingApiService provideTrendingApiService(Gson gson, OkHttpClient okHttpClient, ErrorHandler errorHandler) {
    RestAdapter restAdapter = new RestAdapter.Builder()
            .setErrorHandler(errorHandler)
            .setClient(new OkClient(okHttpClient))
            .setConverter(new GsonConverter(gson))
            .setLogLevel(RestAdapter.LogLevel.BASIC)
            .setEndpoint("http://trending.codehub-app.com")
            .build();
    return restAdapter.create(ReposTrendingApiService.class);
}
 
Example #18
Source Project: githot   Author: andyiac   File: DataModule.java    License: Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
OAuthGitHubWebFlow provideOAuthGitHubWebFlow(Gson gson, OkHttpClient okHttpClient, ErrorHandler errorHandler) {
    RestAdapter restAdapter = new RestAdapter.Builder()
            .setErrorHandler(errorHandler)
            .setClient(new OkClient(okHttpClient))
            .setConverter(new GsonConverter(gson))
            .setLogLevel(RestAdapter.LogLevel.BASIC)
            .setEndpoint("https://github.com")
            .build();
    return restAdapter.create(OAuthGitHubWebFlow.class);
}
 
Example #19
Source Project: Hews   Author: leavjenn   File: RetrofitHelper.java    License: MIT License 5 votes vote down vote up
public HackerNewsService getHackerNewsService() {
    RestAdapter restAdapter = new RestAdapter.Builder()
        .setEndpoint(Constants.KEY_API_URL)
        .setConverter(new GsonConverter(new GsonBuilder().create()))
        .setLogLevel(RestAdapter.LogLevel.BASIC)
        .build();

    return restAdapter.create(HackerNewsService.class);
}
 
Example #20
Source Project: Hews   Author: leavjenn   File: RetrofitHelper.java    License: MIT License 5 votes vote down vote up
public HackerNewsService getSearchService() {
    RestAdapter restAdapter = new RestAdapter.Builder()
        .setEndpoint(Constants.SEARCH_BASE_URL)
        .setConverter(new GsonConverter(new GsonBuilder().create()))
        .setLogLevel(RestAdapter.LogLevel.BASIC)
        .build();

    return restAdapter.create(HackerNewsService.class);
}
 
Example #21
Source Project: CodePolitan   Author: zetbaitsu   File: BenihServiceGenerator.java    License: Apache License 2.0 5 votes vote down vote up
public static <S> S createService(Class<S> serviceClass, String baseUrl)
{
    RestAdapter.Builder builder = new RestAdapter.Builder()
            .setLogLevel(RestAdapter.LogLevel.BASIC)
            .setConverter(new GsonConverter(Bson.pluck().getParser()))
            .setEndpoint(baseUrl);

    RestAdapter adapter = builder.build();

    return adapter.create(serviceClass);
}
 
Example #22
Source Project: Sky31Radio   Author: linroid   File: DataModule.java    License: Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
RestAdapter provideRestAdapter(Gson gson, OkHttpClient okHttpClient, ErrorHandler errorHandler){
    return new RestAdapter.Builder()
            .setErrorHandler(errorHandler)
            .setClient(new OkClient(okHttpClient))
            .setConverter(new GsonConverter(gson))
            .setLogLevel(RestAdapter.LogLevel.BASIC)
            .setEndpoint("http://radio.sky31.com/api")
            .build();
}
 
Example #23
Source Project: Sky31Radio   Author: linroid   File: DataModule.java    License: Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
FirService provideFirService(Gson gson, OkHttpClient okHttpClient, ErrorHandler errorHandler){
    RestAdapter restAdapter =  new RestAdapter.Builder()
            .setErrorHandler(errorHandler)
            .setClient(new OkClient(okHttpClient))
            .setConverter(new GsonConverter(gson))
            .setLogLevel(RestAdapter.LogLevel.BASIC)
            .setEndpoint("http://fir.im/api/v2")
            .build();
    return  restAdapter.create(FirService.class);
}
 
Example #24
Source Project: particle-android   Author: particle-iot   File: ApiFactory.java    License: Apache License 2.0 5 votes vote down vote up
private RestAdapter.Builder buildCommonRestAdapterBuilder(Gson gson, OkHttpClient client) {
    return new RestAdapter.Builder()
            .setClient(new OkClient(client))
            .setConverter(new GsonConverter(gson))
            .setEndpoint(getApiUri().toString())
            .setLogLevel(httpLogLevel);
}
 
Example #25
Source Project: Mortar-Flow-Dagger2-demo   Author: lukaspili   File: RestClient.java    License: MIT License 5 votes vote down vote up
@Inject
public RestClient() {

    Gson gson = new GsonBuilder().create();

    RestAdapter restAdapter = new RestAdapter.Builder()
            .setLogLevel(RestAdapter.LogLevel.BASIC)
            .setEndpoint("http://jsonplaceholder.typicode.com/")
            .setConverter(new GsonConverter(gson))
            .build();

    service = restAdapter.create(Service.class);
}
 
Example #26
Source Project: infobip-api-java-client   Author: infobip   File: GetBulkStatus.java    License: Apache License 2.0 5 votes vote down vote up
public BulkStatusResponse execute(String bulkId) {
    RestAdapter restAdapter = new RestAdapter.Builder()
            .setEndpoint(configuration.getBaseUrl())
            .setRequestInterceptor(getRequestInterceptor())
            .setConverter(new GsonConverter(new GsonBuilder()
            						.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
            						.create()))
            .setClient(new TimeoutClientProvider(configuration))
            .build();
    GetBulkStatusService service = restAdapter.create(GetBulkStatusService.class);
    return service.execute(bulkId);
}
 
Example #27
Source Project: infobip-api-java-client   Author: infobip   File: SendMultipleBinarySms.java    License: Apache License 2.0 5 votes vote down vote up
public SMSResponse execute(SMSMultiBinaryRequest bodyObject) {
    RestAdapter restAdapter = new RestAdapter.Builder()
            .setEndpoint(configuration.getBaseUrl())
            .setRequestInterceptor(getRequestInterceptor())
            .setConverter(new GsonConverter(new GsonBuilder()
            						.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
            						.create()))
            .setClient(new TimeoutClientProvider(configuration))
            .build();
    SendMultipleBinarySmsService service = restAdapter.create(SendMultipleBinarySmsService.class);
    return service.execute(bodyObject);
}
 
Example #28
Source Project: infobip-api-java-client   Author: infobip   File: RescheduleBulk.java    License: Apache License 2.0 5 votes vote down vote up
public BulkResponse execute(String bulkId,BulkRequest bodyObject) {
    RestAdapter restAdapter = new RestAdapter.Builder()
            .setEndpoint(configuration.getBaseUrl())
            .setRequestInterceptor(getRequestInterceptor())
            .setConverter(new GsonConverter(new GsonBuilder()
            						.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
            						.create()))
            .setClient(new TimeoutClientProvider(configuration))
            .build();
    RescheduleBulkService service = restAdapter.create(RescheduleBulkService.class);
    return service.execute(bulkId, bodyObject);
}
 
Example #29
Source Project: infobip-api-java-client   Author: infobip   File: SendSingleTextualSms.java    License: Apache License 2.0 5 votes vote down vote up
public SMSResponse execute(SMSTextualRequest bodyObject) {
    RestAdapter restAdapter = new RestAdapter.Builder()
            .setEndpoint(configuration.getBaseUrl())
            .setRequestInterceptor(getRequestInterceptor())
            .setConverter(new GsonConverter(new GsonBuilder()
            						.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
            						.create()))
            .setClient(new TimeoutClientProvider(configuration))
            .build();
    SendSingleTextualSmsService service = restAdapter.create(SendSingleTextualSmsService.class);
    return service.execute(bodyObject);
}
 
Example #30
Source Project: infobip-api-java-client   Author: infobip   File: GetBulks.java    License: Apache License 2.0 5 votes vote down vote up
public BulkResponse execute(String bulkId) {
    RestAdapter restAdapter = new RestAdapter.Builder()
            .setEndpoint(configuration.getBaseUrl())
            .setRequestInterceptor(getRequestInterceptor())
            .setConverter(new GsonConverter(new GsonBuilder()
            						.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
            						.create()))
            .setClient(new TimeoutClientProvider(configuration))
            .build();
    GetBulksService service = restAdapter.create(GetBulksService.class);
    return service.execute(bulkId);
}