retrofit2.adapter.rxjava.RxJavaCallAdapterFactory Java Examples

The following examples show how to use retrofit2.adapter.rxjava.RxJavaCallAdapterFactory. 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: ApiManage.java    From fvip with Apache License 2.0 6 votes vote down vote up
public PlatformListApi getVideoResourcesService() {
    if (switchApi == null) {
        synchronized (ApiManage.class) {
            if (switchApi == null) {
                switchApi = new Retrofit.Builder()
                        .baseUrl(Constant.BASE_URL)
                        .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                        .client(client)
                        .addConverterFactory(GsonConverterFactory.create())
                        .build().create(PlatformListApi.class);
            }
        }
    }

    return switchApi;
}
 
Example #2
Source File: NetService.java    From easyweather with MIT License 6 votes vote down vote up
public NetService init(String baseUrl) {
    synchronized (this) {
        if (baseUrl.charAt(baseUrl.length() - 1) != '/'){
            baseUrl = baseUrl + "/";
        }
        okHttpClient = new OkHttpClient.Builder().
                readTimeout(15, TimeUnit.SECONDS).
                writeTimeout(10, TimeUnit.SECONDS).
                connectTimeout(10, TimeUnit.SECONDS).
                addInterceptor(loggingInterceptor).
                build();

        retrofit = new Retrofit.Builder().
                addConverterFactory(ScalarsConverterFactory.create()).
                addConverterFactory(GsonConverterFactory.create()).
                addCallAdapterFactory(RxJavaCallAdapterFactory.create()).
                baseUrl(baseUrl).
                client(okHttpClient).
                build();
        downLoadService = create(IDownLoadService.class);

    }
    return this;
}
 
Example #3
Source File: RetrofitUtil.java    From LLApp with Apache License 2.0 6 votes vote down vote up
/**
     * 私有构造方法
     */
    private RetrofitUtil(){
        if (null == mOkHttpClient) {
            mOkHttpClient = OkHttp3Utils.getOkHttpClient();
        }
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        builder.connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS);
        mRetrofit = new Retrofit.Builder()
//                .client(builder.build())
                //设置使用okhttp网络请求
                .client(mOkHttpClient)
                .baseUrl(ApiConstant.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .build();
        mApiService = mRetrofit.create(ApiService.class);
    }
 
Example #4
Source File: Example9.java    From AnDevCon-RxPatterns with Apache License 2.0 6 votes vote down vote up
private void createDriveClient() {
    if (mDriveClient == null) {
        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        OkHttpClient client = new OkHttpClient.Builder()
                .addInterceptor(loggingInterceptor)
                .addInterceptor(chain ->
                        chain.proceed(chain.request().newBuilder().addHeader("Authorization",
                                "Bearer " + Secrets.ACCESS_TOKEN).build())).build();

        mDriveClient = new Retrofit.Builder()
                .addCallAdapterFactory(RxJavaCallAdapterFactory.createWithScheduler(Schedulers.io()))
                .addConverterFactory(GsonConverterFactory.create())
                .client(client)
                .baseUrl(DRIVE_BASE_URL)
                .build()
                .create(DriveClient.class);
    }
}
 
Example #5
Source File: ServiceModule.java    From kaif-android with Apache License 2.0 6 votes vote down vote up
@Provides
@Named("apiRetrofit")
@Singleton
RetrofitRetryStaleProxy provideApiRetrofit(Interceptor interceptor,
                                           ApiConfiguration apiConfiguration,
                                           OkHttpClient okHttpClient) {

  final Gson restApiGson = new GsonBuilder()
      .registerTypeHierarchyAdapter(Object.class, new ApiResponseDeserializer(new Gson()))
      .create();

  return new RetrofitRetryStaleProxy(new RetrofitRetryStaleProxy.RetrofitHolder(new Retrofit.Builder()
      .baseUrl(apiConfiguration.getEndPoint())
      .client(okHttpClient.newBuilder().addInterceptor(interceptor).build())
      .addConverterFactory(GsonConverterFactory.create(restApiGson))
      .addCallAdapterFactory(RxJavaCallAdapterFactory.createWithScheduler(Schedulers.io()))
      .build()));
}
 
Example #6
Source File: RetrofitDao.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
private RetrofitDao(IBuildPublicParams iBuildPublicParams, CookieJar cookieJar) {
    if (mRetrofit == null) {
        if (NetworkConfig.getBaseUrl() == null || NetworkConfig.getBaseUrl().trim().equals("")) {
            throw new RuntimeException("网络模块必须设置在Application处调用 请求的地址 调用方法:NetworkConfig.setBaseUrl(String url)");
        }
        OkHttpClient okHttpClient = new OkHttpClient.Builder()
                .connectTimeout(BuildConfig.CONNECT_TIMEOUT, TimeUnit.SECONDS)
                .writeTimeout(BuildConfig.WRITE_TIMEOUT, TimeUnit.SECONDS)
                .readTimeout(BuildConfig.READ_TIMEOUT, TimeUnit.SECONDS)
                .cookieJar(cookieJar)
                .addInterceptor(new HttpInterceptor(iBuildPublicParams))
                .addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
                .build();
        Gson gson = new GsonBuilder().setDateFormat(DATE_FORMAT).create();
        mRetrofit = new Retrofit.Builder()
                .baseUrl(NetworkConfig.getBaseUrl())
                .addConverterFactory(GsonConverterFactory.create(gson))
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .client(okHttpClient)
                .build();
    }
}
 
Example #7
Source File: KittensDataManager.java    From okuki with Apache License 2.0 6 votes vote down vote up
public KittensDataManager(OkHttpClient client, Gson gson, RxActivityLifecycleCallbacks lifecycle) {
    Retrofit retrofit = new Retrofit.Builder().baseUrl(GiphyApi.BASE_URL).client(client)
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .addConverterFactory(GsonConverterFactory.create(gson)).build();
    giphyApi = retrofit.create(GiphyApi.class);
    lifecycle.onSaveState()
            .filter(bundle -> bundle != null)
            .subscribe(
                    bundle -> bundle.putString(KEY, gson.toJson(getResults())),
                    Errors.log()
            );
    lifecycle.onLoadState()
            .filter(bundle -> bundle != null && bundle.containsKey(KEY))
            .subscribe(
                    bundle -> getResults().addAll(gson.fromJson(bundle.getString(KEY), LIST_TYPE)),
                    Errors.log()
            );


}
 
Example #8
Source File: RetrofitHelper.java    From CleanArch with MIT License 6 votes vote down vote up
public static SampleService getSampleService() {

        if (service == null) {

            synchronized (RetrofitHelper.class) {

                if (service == null) {
                    Retrofit retrofit = new Retrofit.Builder()
                            .baseUrl("http://gank.io/")
                            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                            .addConverterFactory(GsonConverterFactory.create())
                            .build();
                    service = retrofit.create(SampleService.class);
                }
            }
        }

        return service;
    }
 
Example #9
Source File: NetworkModule.java    From ZhihuDaily with Apache License 2.0 6 votes vote down vote up
@Provides
@PerApplication
Retrofit provideRetrofit(){
    String endpointUrl = "http://news.at.zhihu.com/api/4/";
    Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
    GsonConverterFactory gsonConverterFactory = GsonConverterFactory.create(gson);

    HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
    loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
    OkHttpClient client = new OkHttpClient.Builder()
            .cache(new Cache(FileUtils.getHttpCacheDir(mDailyApplication), Constants.Config.HTTP_CACHE_SIZE))
            .connectTimeout(Constants.Config.HTTP_CONNECT_TIMEOUT, TimeUnit.MILLISECONDS)
            .readTimeout(Constants.Config.HTTP_READ_TIMEOUT, TimeUnit.MILLISECONDS)
            .addInterceptor(new CacheInterceptor())
            .build();
    OkHttpClient newClient = client.newBuilder().addInterceptor(loggingInterceptor).build();

    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(endpointUrl)
            .client(newClient)
            .addConverterFactory(gsonConverterFactory)
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .build();
    return retrofit;
}
 
Example #10
Source File: RetrofitPrayerClient.java    From android with Apache License 2.0 6 votes vote down vote up
public RetrofitPrayerClient(OkHttpClient client) {
    Gson gson = new GsonBuilder()
            .registerTypeAdapter(PrayerData.class, new PrayerDataTypeAdapter())
            .create();

    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(MPT_URL)
            .client(client)
            .addConverterFactory(GsonConverterFactory.create(gson))
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .build();

    mRetrofit = retrofit;
    mApi = retrofit.create(PrayerApi.class);
    mErrorWrapper = new ErrorWrapper(retrofit);
}
 
Example #11
Source File: DroidKaigiClient.java    From droidkaigi2016 with Apache License 2.0 6 votes vote down vote up
@Inject
public DroidKaigiClient(OkHttpClient client) {
    Retrofit feedburnerRetrofit = new Retrofit.Builder()
            .client(client)
            .baseUrl("https://raw.githubusercontent.com")
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .addConverterFactory(GsonConverterFactory.create(createGson()))
            .build();
    service = feedburnerRetrofit.create(DroidKaigiService.class);

    Retrofit googleFormRetrofit = new Retrofit.Builder()
            .client(client)
            .baseUrl("https://docs.google.com/forms/d/")
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .addConverterFactory(GsonConverterFactory.create(createGson()))
            .build();
    googleFormService = googleFormRetrofit.create(GoogleFormService.class);

    Retrofit githubRetrofit = new Retrofit.Builder()
            .client(client)
            .baseUrl("https://api.github.com")
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .addConverterFactory(GsonConverterFactory.create(createGson()))
            .build();
    githubService = githubRetrofit.create(GithubService.class);
}
 
Example #12
Source File: BaseServiceCleanArch.java    From CleanArchitecturePlugin with Apache License 2.0 6 votes vote down vote up
public Retrofit getAdapter() {
    OkHttpClient client = new OkHttpClient.Builder()
            .connectTimeout(10, TimeUnit.SECONDS)
            .readTimeout(10, TimeUnit.SECONDS)
            .addInterceptor(new LoggingInterceptor())
            .build();

    Gson gson = new GsonBuilder()
            .excludeFieldsWithModifiers(Modifier.FINAL, Modifier.TRANSIENT, Modifier.STATIC)
            .serializeNulls()
            .create();

    return new Retrofit.Builder()
            .baseUrl(Constants.ENDPOINT)
            .client(client)
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .addConverterFactory(GsonConverterFactory.create(gson))
            .build();
}
 
Example #13
Source File: DroidKaigiClient.java    From droidkaigi2016 with Apache License 2.0 6 votes vote down vote up
@Inject
public DroidKaigiClient(OkHttpClient client) {
    Retrofit feedburnerRetrofit = new Retrofit.Builder()
            .client(client)
            .baseUrl("https://raw.githubusercontent.com")
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .addConverterFactory(GsonConverterFactory.create(createGson()))
            .build();
    service = feedburnerRetrofit.create(DroidKaigiService.class);

    Retrofit googleFormRetrofit = new Retrofit.Builder()
            .client(client)
            .baseUrl("https://docs.google.com/forms/d/")
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .addConverterFactory(GsonConverterFactory.create(createGson()))
            .build();
    googleFormService = googleFormRetrofit.create(GoogleFormService.class);

    Retrofit githubRetrofit = new Retrofit.Builder()
            .client(client)
            .baseUrl("https://api.github.com")
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .addConverterFactory(GsonConverterFactory.create(createGson()))
            .build();
    githubService = githubRetrofit.create(GithubService.class);
}
 
Example #14
Source File: NetworkModule.java    From Retrofit2RxjavaDemo with Apache License 2.0 5 votes vote down vote up
/**
 *  使用自定义Converter处理message在错误时返回在data字段
 * @param gson
 * @param okHttpClient
 * @return
 */
@Provides
@AppScope
@Named("custom_converter")
Retrofit provideCustomConverterRetrofit(Gson gson, @Named("cached") OkHttpClient okHttpClient) {
    return new Retrofit.Builder()
            .addConverterFactory(CustomGsonConverterFactory.create(gson))
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .client(okHttpClient)
            .baseUrl(mBaseUrl)
            .build();
}
 
Example #15
Source File: ServiceModule.java    From kaif-android with Apache License 2.0 5 votes vote down vote up
@Provides
@Named("oauthRetrofit")
@Singleton
Retrofit provideOauthRetrofit(ApiConfiguration apiConfiguration, OkHttpClient client) {
  return new Retrofit.Builder().baseUrl(apiConfiguration.getEndPoint())
      .client(client.newBuilder().build())
      .addConverterFactory(GsonConverterFactory.create())
      .addCallAdapterFactory(RxJavaCallAdapterFactory.createWithScheduler(Schedulers.io()))
      .build();
}
 
Example #16
Source File: ApiModule.java    From TouchNews with Apache License 2.0 5 votes vote down vote up
/**
 * @param baseUrl baseUrl
 * @return Retrofit 对象
 */
private Retrofit getApiService(@NonNull String baseUrl) {
    return new Retrofit.Builder()
        .addConverterFactory(GsonConverterFactory.create())
        .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
        .baseUrl(baseUrl)
        .build();
}
 
Example #17
Source File: TxRequest.java    From MicroReader with MIT License 5 votes vote down vote up
public static TxApi getTxApi() {
    synchronized (monitor){
        if (txApi == null) {
            txApi = new Retrofit.Builder()
                    .baseUrl("http://api.huceo.com")
                    .client(client)
                    .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                    .addConverterFactory(GsonConverterFactory.create())
                    .build().create(TxApi.class);
        }
        return txApi;
    }
}
 
Example #18
Source File: UtilRequest.java    From MicroReader with MIT License 5 votes vote down vote up
public static UtilApi getUtilApi() {
    synchronized (monitor) {
        if (utilApi == null) {
            utilApi = new Retrofit.Builder()
                    .baseUrl("http://www.baidu.com")
                    .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                    .build().create(UtilApi.class);
        }
        return utilApi;
    }
}
 
Example #19
Source File: RetrofitModule.java    From journaldev with MIT License 5 votes vote down vote up
@Provides
@ApplicationScope
Retrofit getRetrofit(OkHttpClient okHttpClient) {
    return new Retrofit.Builder()
            .baseUrl("https://api.coinmarketcap.com/v1/")
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .client(okHttpClient)
            .build();
}
 
Example #20
Source File: RetrofitHelper.java    From MoeQuest with Apache License 2.0 5 votes vote down vote up
/**
 * 煎蛋Api
 */
public static JianDanMeiziApi getJianDanApi() {

  Retrofit retrofit = new Retrofit.Builder()
      .baseUrl(BASE_JIANDAN_URL)
      .client(mOkHttpClient)
      .addConverterFactory(GsonConverterFactory.create())
      .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
      .build();

  return retrofit.create(JianDanMeiziApi.class);
}
 
Example #21
Source File: NetManager.java    From NiceRead with Apache License 2.0 5 votes vote down vote up
public <S> S create1(Class<S> service) {
    Retrofit retrofit = new Retrofit.Builder()
            .client(getOkHttpClient())
            .addConverterFactory(ScalarsConverterFactory.create())
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .baseUrl(getBaseUrl(service))
            .build();
    return retrofit.create(service);
}
 
Example #22
Source File: Dribble.java    From tribbble with Apache License 2.0 5 votes vote down vote up
private Dribble() {
  mEndpoints = new Retrofit.Builder()
      .baseUrl("https://api.dribbble.com/v1/")
      .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
      .addConverterFactory(GsonConverterFactory.create(mGson))
      .client(new OkHttpClient.Builder().addInterceptor(chain ->
          chain.proceed(chain.request().newBuilder()
              .addHeader("Authorization", "Bearer " + BuildConfig.DRIBBBLE_ACCESS_KEY)
              .build())
      ).build())
      .build()
      .create(Endpoints.class);
}
 
Example #23
Source File: RetrofitManager.java    From ESeal with Apache License 2.0 5 votes vote down vote up
public RetrofitManager(PathType pathType) {
    if (freightTrackWebService == null) {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(getPath(pathType))
                .addConverterFactory(XMLGsonConverterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .build();
        freightTrackWebService = retrofit.create(FreightTrackWebService.class);
    }
}
 
Example #24
Source File: Example8.java    From AnDevCon-RxPatterns with Apache License 2.0 5 votes vote down vote up
private void createTwilioClient() {
    if (mTwilioInterface == null) {
        mTwilioInterface = new Retrofit.Builder()
                .addCallAdapterFactory(RxJavaCallAdapterFactory.createWithScheduler(Schedulers.io()))
                .client(new OkHttpClient.Builder().addInterceptor(mLoggingInterceptor)
                        .addInterceptor(chain ->
                                chain.proceed(chain.request().newBuilder().addHeader("Authorization",
                                        Credentials.basic(Secrets.twilio_accountsid, Secrets.twilio_authtoken))
                                        .build())).build())
                .addConverterFactory(GsonConverterFactory.create(new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create()))
                .baseUrl(TWILIO_BASE_URL)
                .build()
                .create(TwilioInterface.class);
    }
}
 
Example #25
Source File: RetrofitHelper.java    From HeroVideo-master with Apache License 2.0 5 votes vote down vote up
/**
 * 根据传入的baseUrl,和api创建retrofit
 *
 * @param clazz
 * @param baseUrl
 * @param <T>
 * @return
 */
private static <T> T createApi(Class<T> clazz, String baseUrl)
{

    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(baseUrl)
            .client(mOkHttpClient)
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .addConverterFactory(GsonConverterFactory.create())
            .build();

    return retrofit.create(clazz);
}
 
Example #26
Source File: MyRetrofit.java    From chaoli-forum-for-android-2 with GNU General Public License v3.0 5 votes vote down vote up
public synchronized static ChaoliService getService(){
    if (service == null) {
        Gson gson = new GsonBuilder().registerTypeAdapter(Integer.class, new IntegerTypeAdapter()).create();
        retrofit = new Retrofit.Builder()
                .baseUrl(Constants.BASE_BASE_URL)
                .addConverterFactory(GsonConverterFactory.create(gson))
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .client(MyOkHttp.getClient())
                .build();
        service = retrofit.create(ChaoliService.class);
    }
    return service;
}
 
Example #27
Source File: ServiceFactory.java    From ReadMark with Apache License 2.0 5 votes vote down vote up
public static <T> T createService(String baseUrl, Class<T> serviceClazz) {
    Retrofit retrofit = new Retrofit.Builder()
            .client(getOkHttpClient())
            .baseUrl(baseUrl)
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .build();

    return retrofit.create(serviceClazz);
}
 
Example #28
Source File: RetrofitHelper.java    From MoeQuest with Apache License 2.0 5 votes vote down vote up
/**
 * 淘女郎Api
 */
public static TaoFemaleaApi getTaoFemaleApi() {

  Retrofit retrofit = new Retrofit.Builder()
      .baseUrl(BASE_HUABAN_URL)
      .client(mOkHttpClient)
      .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
      .addConverterFactory(GsonConverterFactory.create())
      .build();

  return retrofit.create(TaoFemaleaApi.class);
}
 
Example #29
Source File: NetworkManager.java    From DoingDaily with Apache License 2.0 5 votes vote down vote up
/**
 * 干货集中营api
 * @return
 */
public static GankApi getGankAPI() {
    if (gankApi == null) {
        Retrofit retrofit = new Retrofit.Builder()
                .client(createOkHttp2(ConstantValues.HTTP_CACHE_ENABLE))
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .baseUrl(ConstantValues.BASE_URL_GANK)
                .build();
        gankApi = retrofit.create(GankApi.class);
    }
    return gankApi;
}
 
Example #30
Source File: DataModule.java    From vb-android-app-quality with Apache License 2.0 5 votes vote down vote up
/**
 * Return the REST API implementation used by this app.
 *
 * @param context is used to resolve string.
 * @param client the OkHttpClient to use.
 * @return the REST API implementation used by this app.
 */
@Provides
@Singleton
public ApiInterface provideApi(Context context, OkHttpClient client) {
    return new Retrofit.Builder()
            .baseUrl(context.getString(R.string.url))
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .client(client)
            .build()
            .create(ApiInterface.class);
}