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 File: TMDbClient.java    From Amphitheatre with 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 #2
Source File: HttpUtils.java    From qvod with 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 #3
Source File: DroidNubeKit.java    From DroidNubeKit with 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 #4
Source File: DebugApiServiceModule.java    From android-test-demo with 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 File: AppModule.java    From wear-notify-for-reddit with 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 #6
Source File: TapchatModule.java    From tapchat-android with Apache License 2.0 5 votes vote down vote up
@Provides @Singleton @Named(PUSH) RestAdapter providePushRestAdapter(Gson gson, OkHttpClient okHttpClient) {
    return new RestAdapter.Builder()
        .setEndpoint("https://tapchat.herokuapp.com:443")
        .setConverter(new GsonConverter(gson, "UTF-8"))
        .setClient(new OkClient(okHttpClient))
        .build();
}
 
Example #7
Source File: DaggerModule.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
/**
 * 提供全局的单例RestAdapter
 */
@Provides
@Singleton
public RestAdapter provideRestAdapter(Gson gson) {
    // give access to the rest api to the entire app
    return new RestAdapter.Builder().setEndpoint("https://www.okcoin.cn").setConverter(new GsonConverter(gson))
            .setLogLevel(RestAdapter.LogLevel.FULL).build();
}
 
Example #8
Source File: NumberContextQuery.java    From infobip-api-java-client with Apache License 2.0 5 votes vote down vote up
public NumberContextResponse execute(NumberContextRequest 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();
    NumberContextQueryService service = restAdapter.create(NumberContextQueryService.class);
    return service.execute(bodyObject);
}
 
Example #9
Source File: ShareRest.java    From xDrip with 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 #10
Source File: NetworkAPI.java    From example with Apache License 2.0 5 votes vote down vote up
public NetworkAPI() {
  OkHttpClient httpClient = new OkHttpClient();
  Gson gson = new GsonBuilder().create();

  RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint(WEBSERVICE)
      .setLogLevel(BuildConfig.DEBUG ? RestAdapter.LogLevel.FULL : RestAdapter.LogLevel.NONE)
      .setClient(new OkClient(httpClient))
      .setConverter(new GsonConverter(gson))
      .build();

  service = restAdapter.create(PratamaService.class);
}
 
Example #11
Source File: InstagramService.java    From example with Apache License 2.0 5 votes vote down vote up
public InstagramService() {
  OkHttpClient client = new OkHttpClient();
  Gson gson = new Gson();

  RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint(URL)
      .setLogLevel(BuildConfig.DEBUG ? RestAdapter.LogLevel.FULL : RestAdapter.LogLevel.NONE)
      .setClient(new OkClient(client))
      .setConverter(new GsonConverter(gson))
      .build();

  api = restAdapter.create(InstagramApi.class);
}
 
Example #12
Source File: ManageBulkStatus.java    From infobip-api-java-client with Apache License 2.0 5 votes vote down vote up
public BulkStatusResponse execute(String bulkId,UpdateStatusRequest 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();
    ManageBulkStatusService service = restAdapter.create(ManageBulkStatusService.class);
    return service.execute(bulkId, bodyObject);
}
 
Example #13
Source File: TapchatModule.java    From tapchat-android with Apache License 2.0 5 votes vote down vote up
@Provides @Singleton public RestAdapter provideRestAdapter(Gson gson, OkHttpClient okHttpClient, TapchatSession session, TapchatRequestInterceptor requestInterceptor) {
    return new RestAdapter.Builder()
        .setEndpoint(session)
        .setConverter(new GsonConverter(gson, "UTF-8"))
        .setClient(new OkClient(okHttpClient))
        .setRequestInterceptor(requestInterceptor)
        .build();
}
 
Example #14
Source File: GuessItClient.java    From Amphitheatre with Apache License 2.0 5 votes vote down vote up
private static GuessItService getService() {
    if (service == null) {
        RestAdapter restAdapter = new RestAdapter.Builder()
                .setConverter(new GsonConverter(new Gson()))
                .setEndpoint(ApiConstants.GUESS_IT_SERVER_URL)
                .build();
        service = restAdapter.create(GuessItService.class);
    }
    return service;
}
 
Example #15
Source File: AbstractWebManager.java    From divide with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example #16
Source File: ShareRest.java    From NightWatch with 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 #17
Source File: ShareRest.java    From xDrip with 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 #18
Source File: GetOMNIReports.java    From infobip-api-java-client with Apache License 2.0 5 votes vote down vote up
public OMNIReportsResponse execute(String bulkId, String messageId, Integer limit, String channel) {
    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();
    GetOMNIReportsService service = restAdapter.create(GetOMNIReportsService.class);
    return service.execute(bulkId, messageId, limit, channel);
}
 
Example #19
Source File: CommentsConverter.java    From wear-notify-for-reddit with Apache License 2.0 5 votes vote down vote up
public CommentsConverter(Gson gson, GsonConverter gsonConverter, Resources resources,
                         UserStorage userStorage) {
    mGson = gson;
    mOriginalConverter = gsonConverter;
    mResources = resources;
    mUserStorage = userStorage;
}
 
Example #20
Source File: SendAdvancedOmniMessage.java    From infobip-api-java-client with Apache License 2.0 5 votes vote down vote up
public OmniResponse execute(OmniAdvancedRequest 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();
    SendAdvancedOmniMessageService service = restAdapter.create(SendAdvancedOmniMessageService.class);
    return service.execute(bodyObject);
}
 
Example #21
Source File: LogEndTag.java    From infobip-api-java-client with Apache License 2.0 5 votes vote down vote up
public EndTagResponse execute(String messageId) {
    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();
    LogEndTagService service = restAdapter.create(LogEndTagService.class);
    return service.execute(messageId);
}
 
Example #22
Source File: UpdateScenario.java    From infobip-api-java-client with Apache License 2.0 5 votes vote down vote up
public Scenario execute(String scenarioKey,Scenario 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();
    UpdateScenarioService service = restAdapter.create(UpdateScenarioService.class);
    return service.execute(scenarioKey, bodyObject);
}
 
Example #23
Source File: GetSentSmsLogs.java    From infobip-api-java-client with Apache License 2.0 5 votes vote down vote up
public SMSLogsResponse execute(String from, String to, String[] bulkId, String[] messageId, String generalStatus, FormattedDate sentSince, FormattedDate sentUntil, Integer limit, String mcc, String mnc) {
    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();
    GetSentSmsLogsService service = restAdapter.create(GetSentSmsLogsService.class);
    return service.execute(from, to, bulkId, messageId, generalStatus, sentSince, sentUntil, limit, mcc, mnc);
}
 
Example #24
Source File: GetReceivedMessages.java    From infobip-api-java-client with Apache License 2.0 5 votes vote down vote up
public MOReportResponse execute(Integer limit) {
    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();
    GetReceivedMessagesService service = restAdapter.create(GetReceivedMessagesService.class);
    return service.execute(limit);
}
 
Example #25
Source File: SendMultipleTextualSmsAdvanced.java    From infobip-api-java-client with Apache License 2.0 5 votes vote down vote up
public SMSResponse execute(SMSAdvancedTextualRequest 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();
    SendMultipleTextualSmsAdvancedService service = restAdapter.create(SendMultipleTextualSmsAdvancedService.class);
    return service.execute(bodyObject);
}
 
Example #26
Source File: SendMultipleSmsBinaryAdvanced.java    From infobip-api-java-client with Apache License 2.0 5 votes vote down vote up
public SMSResponse execute(SMSAdvancedBinaryRequest 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();
    SendMultipleSmsBinaryAdvancedService service = restAdapter.create(SendMultipleSmsBinaryAdvancedService.class);
    return service.execute(bodyObject);
}
 
Example #27
Source File: GetScenarios.java    From infobip-api-java-client with Apache License 2.0 5 votes vote down vote up
public ScenariosResponse execute(Boolean isDefault, Integer limit, Integer page) {
    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();
    GetScenariosService service = restAdapter.create(GetScenariosService.class);
    return service.execute(isDefault, limit, page);
}
 
Example #28
Source File: GetNumberContextLogs.java    From infobip-api-java-client with Apache License 2.0 5 votes vote down vote up
public NumberContextLogsResponse execute(String to, String[] bulkId, String[] messageId, String generalStatus, FormattedDate sentSince, FormattedDate sentUntil, Integer limit, String mcc, String mnc) {
    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();
    GetNumberContextLogsService service = restAdapter.create(GetNumberContextLogsService.class);
    return service.execute(to, bulkId, messageId, generalStatus, sentSince, sentUntil, limit, mcc, mnc);
}
 
Example #29
Source File: GetCampaigns.java    From infobip-api-java-client with Apache License 2.0 5 votes vote down vote up
public CampaignsResponse execute(Integer limit, Integer page) {
    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();
    GetCampaignsService service = restAdapter.create(GetCampaignsService.class);
    return service.execute(limit, page);
}
 
Example #30
Source File: GetCampaignDetails.java    From infobip-api-java-client with Apache License 2.0 5 votes vote down vote up
public Campaign execute(String campaignKey) {
    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();
    GetCampaignDetailsService service = restAdapter.create(GetCampaignDetailsService.class);
    return service.execute(campaignKey);
}