本文整理汇总了Java中retrofit2.converter.moshi.MoshiConverterFactory类的典型用法代码示例。如果您正苦于以下问题:Java MoshiConverterFactory类的具体用法?Java MoshiConverterFactory怎么用?Java MoshiConverterFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MoshiConverterFactory类属于retrofit2.converter.moshi包,在下文中一共展示了MoshiConverterFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: SwapiModule
import retrofit2.converter.moshi.MoshiConverterFactory; //导入依赖的package包/类
@Inject
public SwapiModule(OkHttpClient okHttpClient, Moshi moshi) {
final Retrofit swapiRetrofit = new Retrofit.Builder().baseUrl(Swapi.BASE_URL)
.client(okHttpClient)
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(MoshiConverterFactory.create(moshi))
.build();
bind(Swapi.class).toInstance(swapiRetrofit.create(Swapi.class));
final Retrofit searchRetrofit = new Retrofit.Builder().baseUrl(CustomSearch.BASE_URL)
.client(okHttpClient)
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(MoshiConverterFactory.create(moshi))
.build();
bind(CustomSearch.class).toInstance(searchRetrofit.create(CustomSearch.class));
bind(SwapiListDataManager.class).singletonInScope();
}
示例2: IdService
import retrofit2.converter.moshi.MoshiConverterFactory; //导入依赖的package包/类
public IdService(HDWallet wallet, String baseUrl) {
this.wallet = wallet;
//final RxJavaCallAdapterFactory rxAdapter = RxJavaCallAdapterFactory.createWithScheduler(Schedulers.io());
this.client = new OkHttpClient.Builder();
addUserAgentHeader();
addSigningInterceptor();
addLogging();
final Moshi moshi = new Moshi.Builder().build();
final Retrofit retrofit = new Retrofit.Builder()
.baseUrl(baseUrl)
.addConverterFactory(MoshiConverterFactory.create(moshi))
//.addCallAdapterFactory(rxAdapter)
.client(client.build())
.build();
this.idInterface = retrofit.create(IdInterface.class);
}
示例3: BalanceService
import retrofit2.converter.moshi.MoshiConverterFactory; //导入依赖的package包/类
public BalanceService(HDWallet wallet, String baseUrl) {
//final RxJavaCallAdapterFactory rxAdapter = RxJavaCallAdapterFactory
// .createWithScheduler(Schedulers.io());
this.client = new OkHttpClient.Builder();
this.client.addInterceptor(new UserAgentInterceptor());
this.client.addInterceptor(new SigningInterceptor(wallet));
final HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(new LoggingInterceptor());
interceptor.setLevel(HttpLoggingInterceptor.Level.BASIC);
this.client.addInterceptor(interceptor);
final Moshi moshi = new Moshi.Builder()
.add(new BigIntegerAdapter())
.build();
final Retrofit retrofit = new Retrofit.Builder()
.baseUrl(baseUrl)
.addConverterFactory(MoshiConverterFactory.create(moshi))
.client(client.build())
.build();
this.balanceInterface = retrofit.create(BalanceInterface.class);
}
示例4: API
import retrofit2.converter.moshi.MoshiConverterFactory; //导入依赖的package包/类
API(Context context, Level apiLevel) {
this.apiLevel = apiLevel;
final Moshi moshi = new Moshi.Builder()
.add(Folder.class, new FolderTypeAdapter())
.add(Feed.class, new FeedTypeAdapter())
.add(Item.class, new ItemTypeAdapter())
.add(User.class, new UserTypeAdapter())
.add(Status.class, new StatusTypeAdapter())
.build();
converterFactory = MoshiConverterFactory.create(moshi);
errorJsonAdapter = moshi.adapter(NewsError.class);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
String username = Preferences.USERNAME.getString(sharedPreferences);
if (username != null) {
String password = Preferences.PASSWORD.getString(sharedPreferences);
String url = Preferences.URL.getString(sharedPreferences);
setupApi(new HttpManager(username, password, HttpUrl.parse(url)));
}
}
示例5: buildEthereumInterface
import retrofit2.converter.moshi.MoshiConverterFactory; //导入依赖的package包/类
private EthereumInterface buildEthereumInterface(final String baseUrl) {
final Moshi moshi = new Moshi.Builder()
.add(new BigIntegerAdapter())
.build();
final RxJavaCallAdapterFactory rxAdapter = RxJavaCallAdapterFactory
.createWithScheduler(Schedulers.io());
final Retrofit retrofit = new Retrofit.Builder()
.baseUrl(baseUrl)
.addConverterFactory(MoshiConverterFactory.create(moshi))
.addCallAdapterFactory(rxAdapter)
.client(this.client.build())
.build();
return retrofit.create(EthereumInterface.class);
}
示例6: IdService
import retrofit2.converter.moshi.MoshiConverterFactory; //导入依赖的package包/类
private IdService() {
final RxJavaCallAdapterFactory rxAdapter = RxJavaCallAdapterFactory.createWithScheduler(Schedulers.io());
final File cachePath = new File(BaseApplication.get().getCacheDir(), "idCache");
this.cache = new Cache(cachePath, 1024 * 1024 * 2);
this.client = new OkHttpClient
.Builder()
.cache(this.cache)
.addNetworkInterceptor(new ReadFromCacheInterceptor())
.addInterceptor(new OfflineCacheInterceptor());
addUserAgentHeader();
addSigningInterceptor();
addLogging();
final Moshi moshi = new Moshi.Builder()
.add(new RealmListAdapter())
.build();
final Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BaseApplication.get().getResources().getString(R.string.id_url))
.addConverterFactory(MoshiConverterFactory.create(moshi))
.addCallAdapterFactory(rxAdapter)
.client(client.build())
.build();
this.idInterface = retrofit.create(IdInterface.class);
}
示例7: DirectoryService
import retrofit2.converter.moshi.MoshiConverterFactory; //导入依赖的package包/类
private DirectoryService() {
final RxJavaCallAdapterFactory rxAdapter =
RxJavaCallAdapterFactory.createWithScheduler(Schedulers.io());
final File cachePath = new File(BaseApplication.get().getCacheDir(), "dirCache");
this.client = new OkHttpClient
.Builder()
.cache(new Cache(cachePath, 1024 * 1024 * 5))
.addNetworkInterceptor(new ReadFromCacheInterceptor())
.addInterceptor(new OfflineCacheInterceptor());
addUserAgentHeader();
addLogging();
final Moshi moshi = new Moshi.Builder()
.build();
final Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BaseApplication.get().getResources().getString(R.string.directory_url))
.addConverterFactory(MoshiConverterFactory.create(moshi))
.addCallAdapterFactory(rxAdapter)
.client(client.build())
.build();
this.directoryInterface = retrofit.create(DirectoryInterface.class);
}
示例8: ReputationService
import retrofit2.converter.moshi.MoshiConverterFactory; //导入依赖的package包/类
private ReputationService() {
final RxJavaCallAdapterFactory rxAdapter = RxJavaCallAdapterFactory
.createWithScheduler(Schedulers.io());
final File cachePath = new File(BaseApplication.get().getCacheDir(), "repCache");
this.client = new OkHttpClient
.Builder()
.cache(new Cache(cachePath, 1024 * 1024))
.addNetworkInterceptor(new ReadFromCacheInterceptor())
.addInterceptor(new OfflineCacheInterceptor());
addSigningInterceptor();
addUserAgentHeader();
addLogging();
final Moshi moshi = new Moshi
.Builder()
.build();
final Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BaseApplication.get().getResources().getString(R.string.rep_url))
.addConverterFactory(MoshiConverterFactory.create(moshi))
.addCallAdapterFactory(rxAdapter)
.client(client.build())
.build();
this.reputationInterface = retrofit.create(ReputationInterface.class);
}
示例9: CurrencyService
import retrofit2.converter.moshi.MoshiConverterFactory; //导入依赖的package包/类
private CurrencyService() {
final RxJavaCallAdapterFactory rxAdapter = RxJavaCallAdapterFactory
.createWithScheduler(Schedulers.io());
final File cachePath = new File(BaseApplication.get().getCacheDir(), "ratesCache");
this.client = new OkHttpClient
.Builder()
.cache(new Cache(cachePath, 1024 * 1024))
.addNetworkInterceptor(new ReadFromCacheInterceptor())
.addInterceptor(new OfflineCacheInterceptor());
addUserAgentHeader();
addLogging();
final Moshi moshi = new Moshi.Builder()
.add(new BigIntegerAdapter())
.add(new BigDecimalAdapter())
.build();
final Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BaseApplication.get().getResources().getString(R.string.currency_url))
.addConverterFactory(MoshiConverterFactory.create(moshi))
.addCallAdapterFactory(rxAdapter)
.client(client.build())
.build();
this.currencyInterface = retrofit.create(CurrencyInterface.class);
}
示例10: generateSignalInterface
import retrofit2.converter.moshi.MoshiConverterFactory; //导入依赖的package包/类
private ChatInterface generateSignalInterface() {
final RxJavaCallAdapterFactory rxAdapter = RxJavaCallAdapterFactory.createWithScheduler(Schedulers.io());
addUserAgentHeader();
addSigningInterceptor();
addLogging();
final Moshi moshi = new Moshi.Builder()
.build();
final Retrofit retrofit = new Retrofit.Builder()
.baseUrl(this.url)
.addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(MoshiConverterFactory.create(moshi))
.addCallAdapterFactory(rxAdapter)
.client(client.build())
.build();
return retrofit.create(ChatInterface.class);
}
示例11: initRetrofit
import retrofit2.converter.moshi.MoshiConverterFactory; //导入依赖的package包/类
private void initRetrofit() {
final Retrofit.Builder builder;
if (retrofit == null) {
builder = new Retrofit.Builder();
} else {
builder = retrofit.newBuilder();
}
retrofit = builder.baseUrl(ProxerUrls.apiBase())
.client(client)
.addCallAdapterFactory(new ProxerResponseCallAdapterFactory())
.addConverterFactory(MoshiConverterFactory.create(moshi))
.addConverterFactory(new EnumRetrofitConverterFactory())
.build();
}
示例12: createRetrofit
import retrofit2.converter.moshi.MoshiConverterFactory; //导入依赖的package包/类
private static Retrofit createRetrofit(String baseUrl, OkHttpClient okHttpClient) {
if (okHttpClient == null) {
okHttpClient = new OkHttpClient();
}
Moshi moshi = new Moshi.Builder()
.add(new StreamTypeAdapter())
.add(new StreamAdapter())
.add(new VideoSizeAdapter())
.build();
return new Retrofit.Builder()
.baseUrl(baseUrl)
.addConverterFactory(MoshiConverterFactory.create(moshi))
.client(okHttpClient)
.build();
}
示例13: onOptionsItemSelected
import retrofit2.converter.moshi.MoshiConverterFactory; //导入依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
Iron.chest().load(new Retrofit.Builder()
.baseUrl("https://api.github.com")
.addConverterFactory(MoshiConverterFactory.create())
.build()
.create(GitHubService.class)
.listRepos("fabianterhorst"), Repo.class);
return true;
}
return super.onOptionsItemSelected(item);
}
示例14: prepare
import retrofit2.converter.moshi.MoshiConverterFactory; //导入依赖的package包/类
@Before
public void prepare() throws IOException {
server = new MockWebServer();
server.start();
tokenStorage = new TestTokenStorage();
MethodCache.DefaultMethodCache<String> methodCache = new MethodCache.DefaultMethodCache<>();
AuthenticationHandler<String, String, String> authHandler =
new AuthenticationHandler<>(
methodCache,
Mockito.mock(OwnerManager.class),
tokenStorage,
new TestProvider(),
new TestTokenTypeFactory()
);
Retrofit retrofit = new Retroauth.Builder<>(authHandler)
.baseUrl(server.url("/"))
.enableLocking(true)
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.addConverterFactory(MoshiConverterFactory.create())
.build();
service = retrofit.create(TestInterface.class);
}
示例15: setUp
import retrofit2.converter.moshi.MoshiConverterFactory; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
final HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS);
final OkHttpClient okHttpClient = new OkHttpClient.Builder()
.addInterceptor(loggingInterceptor)
.build();
final Moshi moshi = new Moshi.Builder().add(new OAuthScopesAdapter()).build();
oAuth2Service = new Retrofit.Builder().baseUrl("http://localhost:" + wireMockRule.port())
.client(okHttpClient)
.addConverterFactory(MoshiConverterFactory.create(moshi))
.build()
.create(OAuth2Service.class);
}