本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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();
}
示例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;
}
示例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();
}
示例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();
}
示例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);
});
}
示例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();
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}
示例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();
}