当前位置: 首页>>代码示例>>Java>>正文


Java RxJava2CallAdapterFactory类代码示例

本文整理汇总了Java中retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory的典型用法代码示例。如果您正苦于以下问题:Java RxJava2CallAdapterFactory类的具体用法?Java RxJava2CallAdapterFactory怎么用?Java RxJava2CallAdapterFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RxJava2CallAdapterFactory类属于retrofit2.adapter.rxjava2包,在下文中一共展示了RxJava2CallAdapterFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setUp

import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    Retrofit retrofit = new Retrofit.Builder()
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .baseUrl("https://api.shodan.io/")
            .build();

    MockRetrofit mockRetrofit = new MockRetrofit.Builder(retrofit)
            .networkBehavior(networkBehavior).build();

    BehaviorDelegate<ApiService> delegate = mockRetrofit.create(ApiService.class);
    apiRestMock = new ApiRestMock(delegate);
}
 
开发者ID:fooock,项目名称:jshodan,代码行数:15,代码来源:ApiServiceTest.java

示例2: buildApiService

import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //导入依赖的package包/类
public static ApiService buildApiService() {
    HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
    interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

    OkHttpClient clientOkHttp = new OkHttpClient.Builder()
            .addInterceptor(interceptor)
            .build();

    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl("https://jsonplaceholder.typicode.com")
            .client(clientOkHttp)
            .addConverterFactory(GsonConverterFactory.create(new GsonBuilder().create()))
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .build();

    return retrofit.create(ApiService.class);
}
 
开发者ID:playmoweb,项目名称:store2realm,代码行数:18,代码来源:ApiService.java

示例3: Api

import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //导入依赖的package包/类
private Api() {
    HttpLoggingInterceptor logInterceptor = new HttpLoggingInterceptor();
    logInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

    File cacheFile = new File(App.getAppContext().getCacheDir(), "cache");
    Cache cache = new Cache(cacheFile, 1024 * 1024 * 100); //100Mb

    OkHttpClient okHttpClient = new OkHttpClient.Builder()
            .readTimeout(7676, TimeUnit.MILLISECONDS)
            .connectTimeout(7676, TimeUnit.MILLISECONDS)
            .addInterceptor(headInterceptor)
            .addInterceptor(logInterceptor)
            .addNetworkInterceptor(new HttpCacheInterceptor())
            .cache(cache)
            .build();

    Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").serializeNulls().create();

    retrofit = new Retrofit.Builder()
            .client(okHttpClient)
            .addConverterFactory(GsonConverterFactory.create(gson))
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .baseUrl(C.BASE_URL)
            .build();
    service = retrofit.create(ApiService.class);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:27,代码来源:Api.java

示例4: create

import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //导入依赖的package包/类
private static Retrofit create() {
    OkHttpClient.Builder builder = new OkHttpClient().newBuilder();
    builder.readTimeout(10, TimeUnit.SECONDS);
    builder.connectTimeout(9, TimeUnit.SECONDS);
    builder.addNetworkInterceptor(new StethoInterceptor());

    if (BuildConfig.DEBUG) {
        HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
        interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        builder.addInterceptor(interceptor);
    }

    return new Retrofit.Builder().baseUrl(ENDPOINT)
            .client(builder.build())
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:RetrofitProvider.java

示例5: build

import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //导入依赖的package包/类
private static Retrofit build(){
    if(null == retrofitInstance){
        synchronized (Retrofit.class){
            if(null == retrofitInstance){ // 双重检验锁,仅第一次调用时实例化
                retrofitInstance = new Retrofit.Builder()
                        // baseUrl总是以/结束,@URL不要以/开头
                        .baseUrl(BuildConfig.API_SERVER_URL)
                        // 使用OkHttp Client
                        .client(buildOkHttpClient())
                        // 集成RxJava处理
                        .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                        // 集成Gson转换器
                        .addConverterFactory(buildGsonConverterFactory())
                        .build();
            }
        }
    }
    return retrofitInstance;
}
 
开发者ID:qiaop,项目名称:basicapp,代码行数:20,代码来源:RetrofitHelper.java

示例6: RetrofitClient

import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //导入依赖的package包/类
private RetrofitClient(){
    OkHttpClient.Builder builder = new OkHttpClient.Builder();
    builder.connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
            .sslSocketFactory(createSSLSocketFactory(),new TrustAllManager())//信任所有
            .addInterceptor(new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
                @Override
                public void log(String message) {
                    Log.i("okhttp32",message);
                }
            }).setLevel(HttpLoggingInterceptor.Level.BODY))
    ;

    mOkHttpClient = builder.build();
     mRetrofit = new Retrofit.Builder()
            .client(mOkHttpClient)
            .baseUrl(BASE_URL)
            .addConverterFactory(GsonConverterFactory.create(buildGson()))
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .build();
}
 
开发者ID:nowandfurure,项目名称:richeditor,代码行数:21,代码来源:RetrofitClient.java

示例7: beforeEachTest

import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //导入依赖的package包/类
@Before public void beforeEachTest() {

        server = new MockWebServer();

        NumbersWebService numberAPI =
                new Retrofit.Builder()
                        .baseUrl(server.url("/").toString())
                        .addConverterFactory(GsonConverterFactory.create())
                        .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                        .build()
                        .create(NumbersWebService.class);

        infrastructure = new TriviaInfrastructure(
                numberAPI,
                new TriviaGenerator(),
                new PayloadMapper(),
                new PayloadValidator(),
                Schedulers.trampoline() // non-concurrent integration on tests
        );
    }
 
开发者ID:ubiratansoares,项目名称:reactive-architectures-playground,代码行数:21,代码来源:TriviaInfrastructureTests.java

示例8: provideRetrofit

import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //导入依赖的package包/类
/**
 * @param builder
 * @param client
 * @param httpUrl
 * @return
 * @author: jess
 * @date 8/30/16 1:15 PM
 * @description:提供retrofit
 */
@Singleton
@Provides
Retrofit provideRetrofit(Application application, @Nullable RetrofitConfiguration configuration, Retrofit.Builder builder, OkHttpClient client
        , HttpUrl httpUrl, Gson gson) {
    builder
            .baseUrl(httpUrl)//域名
            .client(client);//设置okhttp

    if (configuration != null)
        configuration.configRetrofit(application, builder);

    builder
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())//使用rxjava
            .addConverterFactory(GsonConverterFactory.create(gson));//使用Gson
    return builder.build();
}
 
开发者ID:devzwy,项目名称:NeiHanDuanZiTV,代码行数:26,代码来源:ClientModule.java

示例9: provideAuthRetrofit

import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //导入依赖的package包/类
@Override
public Single<RetrofitWrapper> provideAuthRetrofit() {
    return Single.fromCallable(() -> {

        OkHttpClient.Builder builder = new OkHttpClient.Builder()
                .readTimeout(30, TimeUnit.SECONDS)
                .addInterceptor(HttpLogger.DEFAULT_LOGGING_INTERCEPTOR);

        ProxyUtil.applyProxyConfig(builder, proxySettings.getActiveProxy());
        Gson gson = new GsonBuilder().create();

        final Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("https://oauth.vk.com/")
                .addConverterFactory(GsonConverterFactory.create(gson))
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .client(builder.build())
                .build();

        return RetrofitWrapper.wrap(retrofit, false);
    });
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:22,代码来源:OtherVkRetrofitProvider.java

示例10: provideRetrofit

import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //导入依赖的package包/类
@Singleton
@Provides
Retrofit provideRetrofit(@Nullable RetrofitConfiguration configuration,
                         Retrofit.Builder builder, OkHttpClient client, HttpUrl httpUrl) {
    builder
            //domain name
            .baseUrl(httpUrl)
            //Set okhttp
            .client(client)
            //TODO: to use use LiveData
            //.addCallAdapterFactory(new LiveDataCallAdapterFactory())
            //use rxjava
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            //use Gson
            .addConverterFactory(GsonConverterFactory.create());
    if (configuration != null)
        configuration.configRetrofit(mApplication, builder);
    return builder.build();
}
 
开发者ID:goutham106,项目名称:GmArchMvvm,代码行数:20,代码来源:ClientModule.java

示例11: RetrofitUtils

import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //导入依赖的package包/类
/**
 * 实际由getInstance() 进行调用创建
 */
private RetrofitUtils() {
    // 创建 OKHttpClient
    OkHttpClient.Builder builder = new OkHttpClient.Builder();
    builder.connectTimeout(this.DEFAULT_TIME_OUT, TimeUnit.SECONDS)//设置全局请求的连接超时时间,默认为15s
            .writeTimeout(this.DEFAULT_READ_TIME_OUT, TimeUnit.SECONDS)//写操作 超时时间
            .readTimeout(this.DEFAULT_READ_TIME_OUT, TimeUnit.SECONDS);//设置全局请求的数据读取超时时间,默认为30s
    // 向okhttp中添加公共参数拦截器
    builder.addInterceptor(mBaseInterceptor != null ? mBaseInterceptor : BaseInterceptor.getDefault());
    //创建okhttp实例
    OkHttpClient client = builder.build();
    //配置你的Gson,在不同环境下gson对Data的转化可能不一样,这里使用统一的格式
    Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd hh:mm:ss").create();

    // 创建Retrofit,将gson和okhttp加入进来
    mRetrofit = new Retrofit.Builder().baseUrl(this.BASE_URL)//设置基础域名。网络请求由此拼接(注意:需要/结尾,且此处与单独有相同路径时会智能纠错:www/api/+api/xxx会纠错为www/api/xxx)
            .addConverterFactory(GsonConverterFactory.create(gson))//设置json返回消息的解析库(这里使用gson)
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())//此在与RxJava联用时才使用
            .client(client)//配置okhttp配置。可无(为空时,retrofit会使用默认配置)
            .build();
}
 
开发者ID:JJS-CN,项目名称:JBase,代码行数:24,代码来源:RetrofitUtils.java

示例12: init

import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //导入依赖的package包/类
private void init() {
    HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor()
            .setLevel(HttpLoggingInterceptor.Level.BODY);

    OkHttpClient client = new OkHttpClient()
            .newBuilder()
            .addInterceptor(interceptor)
            .build();

    service = new Retrofit.Builder()
            .baseUrl("https://api.github.com/")
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .client(client)
            .build()
            .create(GitHubService.class);
}
 
开发者ID:qingmei2,项目名称:RxFamilyUsage-Android,代码行数:18,代码来源:GitHubServiceManager.java

示例13: onRefresh

import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //导入依赖的package包/类
@Override
public void onRefresh() {
    String baseUrl = "http://gank.io/api/";
    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(baseUrl)
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .build();

    ApiService apiService = retrofit.create(ApiService.class);
    apiService.getClassifyData("福利", 1)
            .map(new BaseResFunc<List<Gank>>())
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(mObserver);

}
 
开发者ID:wheat7,项目名称:Cashew,代码行数:18,代码来源:GirlFragment.java

示例14: HttpManager

import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //导入依赖的package包/类
private HttpManager() {

        OkHttpClient.Builder okHttpClientBuild = new OkHttpClient.Builder()
                .connectTimeout(30, TimeUnit.SECONDS);

        OkHttpClient okHttpClient = okHttpClientBuild.build();

        mApi = new Retrofit.Builder()
                .baseUrl("http://image.baidu.com/")
                .client(okHttpClient)
                .addCallAdapterFactory(RxJava2WithProgressCallAdapterFactory.createAsync())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.createAsync())
                .addConverterFactory(ScalarsConverterFactory.create())
                .addConverterFactory(FileConverterFactory.create())
                .build()
                .create(Api.class);

    }
 
开发者ID:imfms,项目名称:retrofit-rxjava-request-with-progress,代码行数:19,代码来源:HttpManager.java

示例15: initWithBaseUrl

import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory; //导入依赖的package包/类
private void initWithBaseUrl(String baseUrl){
    HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
    loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

    OkHttpClient client = new OkHttpClient.Builder()
            .connectTimeout(5000, TimeUnit.MILLISECONDS)
            .readTimeout(5000, TimeUnit.MILLISECONDS)
            .writeTimeout(5000, TimeUnit.MILLISECONDS)
            .addInterceptor(loggingInterceptor)
            .build();

    retrofit = new Retrofit.Builder()
            .baseUrl(baseUrl)
            .addConverterFactory(GsonConverterFactory.create())
            .client(client)
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .build();
}
 
开发者ID:TORU0239,项目名称:ViperUsage,代码行数:19,代码来源:ApiBase.java


注:本文中的retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。