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


Java ScalarsConverterFactory类代码示例

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


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

示例1: setUp

import retrofit2.converter.scalars.ScalarsConverterFactory; //导入依赖的package包/类
@Before
public void setUp() throws IOException {
    mMockServer = new MockWebServer();
    mMockServer.start();
    Retrofit retrofit = (new Retrofit.Builder().baseUrl(mMockServer.url("").toString())
            .addConverterFactory(ScalarsConverterFactory.create())
            .addConverterFactory(GsonConverterFactory.create())).build();
    CivifyLoginService civifyLoginService = retrofit.create(CivifyLoginService.class);
    CivifyMeService civifyMeService = retrofit.create(CivifyMeService.class);
    SharedPreferences.Editor editor = mock(SharedPreferences.Editor.class);
    mSharedPreferences = mock(SharedPreferences.class);
    mLoginFinishedCallbackMock = mock(LoginFinishedCallback.class);
    when(mSharedPreferences.edit()).thenReturn(editor);
    mUser = new User("username", "name", "surname",
            "email", "password", "password");
    mLoginAdapter =
            new LoginAdapterImpl(civifyLoginService, civifyMeService, mSharedPreferences);
}
 
开发者ID:ArnauBlanch,项目名称:civify-app,代码行数:19,代码来源:LoginAdapterImplTest.java

示例2: provideCall

import retrofit2.converter.scalars.ScalarsConverterFactory; //导入依赖的package包/类
@Provides
@Singleton
Retrofit provideCall() {
    OkHttpOAuthConsumer consumer = new OkHttpOAuthConsumer(App.getTwitterKey(),
            App.getTwitterSecret());
    consumer.setTokenWithSecret(
            App.getApplicationInstance().getTwitterSession().getAuthToken().token,
            App.getApplicationInstance().getTwitterSession().getAuthToken().secret);

    Retrofit.Builder builder =
            new Retrofit.Builder()
                    .baseUrl(baseUrl)
                    .addConverterFactory(GsonConverterFactory.create())
                    .addConverterFactory(ScalarsConverterFactory.create())
                    .addCallAdapterFactory(RxJavaCallAdapterFactory.create());

    OkHttpClient client = new OkHttpClient.Builder()
            .addInterceptor(new SigningInterceptor(consumer))
            .addNetworkInterceptor(new StethoInterceptor())
            .build();

    return builder.client(client).build();
}
 
开发者ID:beraldofilippo,项目名称:TWStreaming,代码行数:24,代码来源:NetworkModule.java

示例3: dealApiReqest

import retrofit2.converter.scalars.ScalarsConverterFactory; //导入依赖的package包/类
public void dealApiReqest(BaseApi baseApi) {
//                创建一个OkHttpClient
                OkHttpClient.Builder builder = new OkHttpClient.Builder();
                CommonSubscriber commonSubscriber = new CommonSubscriber(baseApi, mOnNextListenerSoftReference, mRxAppCompatActivitySoftReference);
                builder.addInterceptor(new CacheInterceptor()).connectTimeout(baseApi.getConnectedTime(), TimeUnit.SECONDS)
                        .writeTimeout(baseApi.getWritedOutTime(), TimeUnit.SECONDS).addNetworkInterceptor(new CacheInterceptor())
                        .cache(new Cache(CustomApplication.getInstance().getCacheDir(), 10 * 1024 * 1024));
                Retrofit retrofit = new Retrofit.Builder().client(builder.build()).baseUrl(baseApi.getBaseUrl()).addConverterFactory(ScalarsConverterFactory.create())
                        .addCallAdapterFactory(RxJavaCallAdapterFactory.create()).build();
//                        .build();
//                这里原理是通过Java的动态代理创建接口的实例
                HttpService httpService = retrofit.create(HttpService.class);
                Observable observable = baseApi.getObservable(httpService);
                observable.retryWhen(new RetryWhenNetWorkException()).subscribeOn(Schedulers.io()).unsubscribeOn(Schedulers.io())
                        .observeOn(AndroidSchedulers.mainThread()).map(baseApi).subscribe(commonSubscriber);
        }
 
开发者ID:HelloChenJinJun,项目名称:TestChat,代码行数:17,代码来源:CommonHttpManager.java

示例4: start

import retrofit2.converter.scalars.ScalarsConverterFactory; //导入依赖的package包/类
public void start(final DownInfo info) {
//                如果消息实体为空,或正在下载,则返回
                if (info == null || mDownInfoMap.get(info.getUrl()) != null) return;
                DownLoadSubscriber<DownInfo> downLoadSubscriber = new DownLoadSubscriber<>(info);
                mDownInfoMap.put(info.getUrl(), downLoadSubscriber);
//                HttpService service;
//                增加一个拦截器,用于获取数据的进度回调
                DownLoadInterceptor interceptor = new DownLoadInterceptor(downLoadSubscriber);
                OkHttpClient.Builder builder = new OkHttpClient.Builder();
                builder.connectTimeout(info.getConnectedTime(), TimeUnit.SECONDS).addInterceptor(interceptor);
                Retrofit retrofit = new Retrofit.Builder().
                        addConverterFactory(ScalarsConverterFactory.create()).addCallAdapterFactory(RxJavaCallAdapterFactory.create()).
                        baseUrl(CommonUtils.getBaseUrl(info.getUrl())).client(builder.build()).build();
                HttpService service = retrofit.create(HttpService.class);
                info.setHttpService(service);
                service.download("bytes=" + info.getReadLength() + "-", info.getUrl()).subscribeOn(Schedulers.io())
                        .unsubscribeOn(Schedulers.io()).retryWhen(new RetryWhenNetWorkException()).map(new Func1<ResponseBody, DownInfo>() {
                        @Override
                        public DownInfo call(ResponseBody responseBody) {
                                FileUtil.writeToCache(responseBody, info.getSavedFilePath(), info.getReadLength(), info.getTotalLength());
//                                这里进行转化
                                return info;
                        }
                }).observeOn(AndroidSchedulers.mainThread()).subscribe(downLoadSubscriber);
        }
 
开发者ID:HelloChenJinJun,项目名称:TestChat,代码行数:26,代码来源:HttpDownLoadManager.java

示例5: HttpManager

import retrofit2.converter.scalars.ScalarsConverterFactory; //导入依赖的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

示例6: createService

import retrofit2.converter.scalars.ScalarsConverterFactory; //导入依赖的package包/类
/**
 * Create service
 * @param key OwO API key
 * @param endpoint Endpoint URL, defaults to {@link OwO#DEFAULT_ENDPOINT} when null
 * @param uploadUrl Upload URL, defaults to {@link OwO#DEFAULT_UPLOAD_URL} when null
 * @return service
 */
private static OwOService createService(@NotNull final String key, @Nullable String endpoint, @Nullable final String uploadUrl) {
    OkHttpClient client = new OkHttpClient.Builder().addInterceptor(new Interceptor() {
        @Override
        public Response intercept(Chain chain) throws IOException {
            Request request = chain.request();
            HttpUrl url = request.url().newBuilder().addQueryParameter("key", key).build();
            return chain.proceed(request.newBuilder().header("User-Agent", USER_AGENT).url(url).build());
        }
    }).build();

    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(endpoint == null ? DEFAULT_ENDPOINT : endpoint)
            .client(client)
            .addConverterFactory(ScalarsConverterFactory.create())
            .addConverterFactory(GsonConverterFactory.create(new GsonBuilder().registerTypeAdapter(OwOFile.class, new JsonDeserializer<OwOFile>() {
                @Override
                public OwOFile deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException {
                    return new Gson().fromJson(json.getAsJsonObject().get("files").getAsJsonArray().get(0), OwOFile.class).setFullUrl(uploadUrl == null ? DEFAULT_UPLOAD_URL : uploadUrl);
                }}).create()))
            .build();

    return retrofit.create(OwOService.class);
}
 
开发者ID:whats-this,项目名称:owo.java,代码行数:31,代码来源:OwO.java

示例7: getRetrofitService

import retrofit2.converter.scalars.ScalarsConverterFactory; //导入依赖的package包/类
/**
 * 获取retrofitService
 *
 * @param context
 * @param baseUrl
 * @return
 */
public static RetrofitHttpService getRetrofitService(Context context, String baseUrl) {
    if (TextUtils.isEmpty(baseUrl)) {
        throw new NullPointerException("BASE_URL can not be null");
    }

    OkHttpClient client = RequestAgent.getOkHttpClient(context.getApplicationContext(), baseUrl, null);

    Retrofit.Builder builder = new Retrofit.Builder();

    builder.addConverterFactory(ScalarsConverterFactory.create());

    if (!baseUrl.endsWith("/")) {
        baseUrl += "/";
    }

    Retrofit retrofit = builder
            .baseUrl(baseUrl)
            .client(client).build();

    return retrofit.create(RetrofitHttpService.class);
}
 
开发者ID:jingle1267,项目名称:AndroidRequest,代码行数:29,代码来源:RequestAgent.java

示例8: createDefaultAdapter

import retrofit2.converter.scalars.ScalarsConverterFactory; //导入依赖的package包/类
public void createDefaultAdapter() {
  Gson gson = new GsonBuilder()
    .setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
    .registerTypeAdapter(DateTime.class, new DateTimeTypeAdapter())
    .registerTypeAdapter(LocalDate.class, new LocalDateTypeAdapter())
    .create();

  okBuilder = new OkHttpClient.Builder();

  String baseUrl = "https://api.us-east-1.mbedcloud.com";
  if(!baseUrl.endsWith("/"))
    baseUrl = baseUrl + "/";

  adapterBuilder = new Retrofit
    .Builder()
    .baseUrl(baseUrl)
    .addConverterFactory(ScalarsConverterFactory.create())
    .addConverterFactory(GsonCustomConverterFactory.create(gson));
}
 
开发者ID:ARMmbed,项目名称:mbed-cloud-sdk-java,代码行数:20,代码来源:ApiClient.java

示例9: createDefaultAdapter

import retrofit2.converter.scalars.ScalarsConverterFactory; //导入依赖的package包/类
public void createDefaultAdapter() {
  Gson gson = new GsonBuilder()
    .setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
    .registerTypeAdapter(DateTime.class, new DateTimeTypeAdapter())
    .registerTypeAdapter(LocalDate.class, new LocalDateTypeAdapter())
    .create();

  okBuilder = new OkHttpClient.Builder();

  String baseUrl = "http://api.us-east-1.mbedcloud.com";
  if(!baseUrl.endsWith("/"))
    baseUrl = baseUrl + "/";

  adapterBuilder = new Retrofit
    .Builder()
    .baseUrl(baseUrl)
    .addConverterFactory(ScalarsConverterFactory.create())
    .addConverterFactory(GsonCustomConverterFactory.create(gson));
}
 
开发者ID:ARMmbed,项目名称:mbed-cloud-sdk-java,代码行数:20,代码来源:ApiClient.java

示例10: SlackReporter

import retrofit2.converter.scalars.ScalarsConverterFactory; //导入依赖的package包/类
private SlackReporter(String apiKey, boolean logEnabled) {
    mIsLogEnabled = logEnabled;
    mApiKey = apiKey;

    Retrofit.Builder builder = new Retrofit.Builder();
    builder.baseUrl("https://hooks.slack.com")
            .addConverterFactory(ScalarsConverterFactory.create())
            .addConverterFactory(GsonConverterFactory.create());

    if (mIsLogEnabled) {
        HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
        interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();
        builder.client(client);
    }

    Retrofit sRetrofit = builder.build();
    sService = sRetrofit.create(SlackMessageReportService.class);
}
 
开发者ID:suhanlee,项目名称:SlackMessage,代码行数:20,代码来源:SlackReporter.java

示例11: ServicesManager

import retrofit2.converter.scalars.ScalarsConverterFactory; //导入依赖的package包/类
private ServicesManager() {
    OkHttpClient.Builder builder = new OkHttpClient.Builder();
    builder.connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS);

    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(Constants.WEATHER_BASE_URL)
            .client(builder.build())
            .addConverterFactory(ScalarsConverterFactory.create())
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .build();
    weatherInfoService = retrofit.create(WeatherInfoService.class);

    mNameMap.put("CN10101", "北京");
    mNameMap.put("CN10102", "上海");
    mNameMap.put("CN10103", "天津");
    mNameMap.put("CN10104", "重庆");
    mNameMap.put("CN10132", "香港");
    mNameMap.put("CN10133", "澳门");
}
 
开发者ID:ZeusChan,项目名称:LittleFreshWeather,代码行数:21,代码来源:ServicesManager.java

示例12: createNetEasyService

import retrofit2.converter.scalars.ScalarsConverterFactory; //导入依赖的package包/类
private static NetEasyApi createNetEasyService() {

        OkHttpClient client = new OkHttpClient.Builder()
                .connectTimeout(TIME_OUT, TimeUnit.SECONDS)
                .readTimeout(TIME_OUT, TimeUnit.SECONDS)
                .writeTimeout(TIME_OUT, TimeUnit.SECONDS)
                .addInterceptor(new HttpLoggingInterceptor()
                .setLevel(HttpLoggingInterceptor.Level.BODY))
                .build();

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(NETEASY_BASE_URL)
                .client(client)
                .addConverterFactory(ScalarsConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .build();
        return retrofit.create(NetEasyApi.class);
    }
 
开发者ID:huyongli,项目名称:TigerVideo,代码行数:19,代码来源:RetrofitFactory.java

示例13: createTtKbService

import retrofit2.converter.scalars.ScalarsConverterFactory; //导入依赖的package包/类
private static TtKbApi createTtKbService() {

        OkHttpClient client = new OkHttpClient.Builder()
                .connectTimeout(TIME_OUT, TimeUnit.SECONDS)
                .readTimeout(TIME_OUT, TimeUnit.SECONDS)
                .writeTimeout(TIME_OUT, TimeUnit.SECONDS)
                .addInterceptor(new HttpLoggingInterceptor()
                .setLevel(HttpLoggingInterceptor.Level.BODY))
                .build();

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(TTKB_BASE_URL)
                .client(client)
                .addConverterFactory(ScalarsConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .build();
        return retrofit.create(TtKbApi.class);
    }
 
开发者ID:huyongli,项目名称:TigerVideo,代码行数:19,代码来源:RetrofitFactory.java

示例14: createIFengService

import retrofit2.converter.scalars.ScalarsConverterFactory; //导入依赖的package包/类
private static IFengApi createIFengService() {

        OkHttpClient client = new OkHttpClient.Builder()
                .connectTimeout(TIME_OUT, TimeUnit.SECONDS)
                .readTimeout(TIME_OUT, TimeUnit.SECONDS)
                .writeTimeout(TIME_OUT, TimeUnit.SECONDS)
                .addInterceptor(new HttpLoggingInterceptor()
                .setLevel(HttpLoggingInterceptor.Level.BODY))
                .build();

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(IFENG_BASE_URL)
                .client(client)
                .addConverterFactory(ScalarsConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .build();
        return retrofit.create(IFengApi.class);
    }
 
开发者ID:huyongli,项目名称:TigerVideo,代码行数:19,代码来源:RetrofitFactory.java

示例15: onCreate

import retrofit2.converter.scalars.ScalarsConverterFactory; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_retrofit1);
    ButterKnife.bind(this);
    //01:获取Retrofit对象
    mRetrofit = new Retrofit.Builder()
            //02采用链式结构绑定Base url
            .baseUrl(ApiStores.API_SERVER_URL)
            // 注意:字符创解析器要放在Gson解析器前面,不然无法解析字符串
            //使用工厂模式创建字符串解析器
            .addConverterFactory(ScalarsConverterFactory.create())
            //使用工厂模式创建Gson的解析器
            .addConverterFactory(GsonConverterFactory.create())
            .build();
    //04获取API接口的实现类的实例对象
    mApiStores = mRetrofit.create(ApiStores.class);

}
 
开发者ID:sdwfqin,项目名称:AndroidSamples,代码行数:20,代码来源:Retrofit1Activity.java


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