retrofit2.converter.moshi.MoshiConverterFactory Java Examples
The following examples show how to use
retrofit2.converter.moshi.MoshiConverterFactory.
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: InfluxDBImpl.java From influxdb-java with MIT License | 6 votes |
InfluxDBImpl(final String url, final String username, final String password, final OkHttpClient.Builder client, final InfluxDBService influxDBService, final JsonAdapter<QueryResult> adapter) { super(); this.messagePack = false; this.hostName = parseHost(url); this.loggingInterceptor = new HttpLoggingInterceptor(); setLogLevel(LOG_LEVEL); this.gzipRequestInterceptor = new GzipRequestInterceptor(); OkHttpClient.Builder clonedBuilder = client.build().newBuilder() .addInterceptor(loggingInterceptor) .addInterceptor(gzipRequestInterceptor) .addInterceptor(new BasicAuthInterceptor(username, password)); this.client = clonedBuilder.build(); this.retrofit = new Retrofit.Builder().baseUrl(url) .client(this.client) .addConverterFactory(MoshiConverterFactory.create()).build(); this.influxDBService = influxDBService; chunkProccesor = new JSONChunkProccesor(adapter); }
Example #2
Source File: HttpModule.java From auth with MIT License | 6 votes |
public RedditAuthApi getAuthApiService() { if (authService == null) { synchronized (this) { if (authService == null) { MoshiConverterFactory converterFactory = MoshiConverterFactory.create(provideMoshi()); authService = new Retrofit.Builder() .client(provideOkHttp()) .addConverterFactory(converterFactory) .addCallAdapterFactory(RxJava2CallAdapterFactory.createAsync()) .baseUrl("https://www.reddit.com/api/") .build() .create(RedditAuthApi.class); } } } return authService; }
Example #3
Source File: SwapiModule.java From okuki with Apache License 2.0 | 6 votes |
@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(); }
Example #4
Source File: OAuth2ServiceTest.java From rides-java-sdk with MIT License | 6 votes |
@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); }
Example #5
Source File: ImgurApi.java From RxPalette with Apache License 2.0 | 6 votes |
/** * Constructs a new ImgurApi with the specified clientId. * * @param clientId The client id. */ public ImgurApi(final String clientId) { OkHttpClient okHttpClient = new OkHttpClient.Builder() .addInterceptor(new Interceptor() { @Override public Response intercept(Interceptor.Chain chain) throws IOException { Request request = chain.request(); request = request.newBuilder().addHeader("Authorization", "Client-ID " + clientId).build(); return chain.proceed(request); } }) .build(); albumService = new Retrofit.Builder() .baseUrl("https://api.imgur.com/3/") .client(okHttpClient) .addConverterFactory(MoshiConverterFactory.create()) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .build() .create(AlbumService.class); }
Example #6
Source File: MainActivity.java From Iron with Apache License 2.0 | 6 votes |
@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); }
Example #7
Source File: MavenCentral.java From osstrich with Apache License 2.0 | 5 votes |
public MavenCentral() { Retrofit retrofit = new Retrofit.Builder() .baseUrl(HttpUrl.parse("https://search.maven.org/")) .addConverterFactory(MoshiConverterFactory.create()) .build(); this.mavenDotOrg = retrofit.create(MavenDotOrg.class); }
Example #8
Source File: ApiModule.java From u2020 with Apache License 2.0 | 5 votes |
@Provides @Singleton Retrofit provideRetrofit(HttpUrl baseUrl, @Named("Api") OkHttpClient client, Moshi moshi) { return new Retrofit.Builder() // .client(client) // .baseUrl(baseUrl) // .addConverterFactory(MoshiConverterFactory.create(moshi)) // .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) // .build(); }
Example #9
Source File: ApiModule.java From u2020-mvp with Apache License 2.0 | 5 votes |
@Provides @ApplicationScope Retrofit provideRetrofit(HttpUrl baseUrl, @Named("Api") OkHttpClient client, Moshi moshi) { return new Retrofit.Builder() // .client(client) // .baseUrl(baseUrl) // .addConverterFactory(MoshiConverterFactory.create(moshi)) // .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) // .build(); }
Example #10
Source File: NetworkModule.java From MovieGuide with MIT License | 5 votes |
@Singleton @Provides Retrofit retrofit(OkHttpClient okHttpClient) { return new Retrofit .Builder() .baseUrl(BuildConfig.TMDB_BASE_URL) .addConverterFactory(MoshiConverterFactory.create()) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .client(okHttpClient) .build(); }
Example #11
Source File: RidesServiceTest.java From rides-java-sdk with MIT License | 5 votes |
@Before public void setUp() throws Exception { Moshi moshi = new Moshi.Builder().add(new BigDecimalAdapter()).build(); service = new Retrofit.Builder() .addConverterFactory(MoshiConverterFactory.create(moshi)) .client(new OkHttpClient.Builder() .addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)) .build()) .baseUrl("http://localhost:" + wireMockRule.port()) .build() .create(RidesService.class); }
Example #12
Source File: UberRidesApi.java From rides-java-sdk with MIT License | 5 votes |
Retrofit createRetrofit(OkHttpClient client, Session session) { Moshi moshi = new Moshi.Builder().add(new BigDecimalAdapter()).build(); return new Retrofit.Builder() .addConverterFactory(MoshiConverterFactory.create(moshi)) .baseUrl(session.getAuthenticator().getSessionConfiguration().getEndpointHost()) .client(client) .build(); }
Example #13
Source File: AccessTokenAuthenticator.java From rides-java-sdk with MIT License | 5 votes |
static OAuth2Service createOAuthService(String baseUrl) { final Moshi moshi = new Moshi.Builder().add(new OAuthScopesAdapter()).build(); return new Retrofit.Builder() .baseUrl(baseUrl) .addConverterFactory(MoshiConverterFactory.create(moshi)) .build() .create(OAuth2Service.class); }
Example #14
Source File: RideRequestButtonControllerTest.java From rides-android-sdk with MIT License | 5 votes |
@Before public void setUp() throws Exception { rideParameters = new RideParameters.Builder() .setProductId(PRODUCT_ID) .setDropoffLocation(valueOf(DROP_OFF_LATITUDE), valueOf(DROP_OFF_LONGITUDE), DROP_OFF_NICKNAME, DROP_OFF_ADDRESS) .setPickupLocation(valueOf(PICKUP_LATITUDE), valueOf(PICKUP_LONGITUDE), PICKUP_NICKNAME, PICKUP_ADDRESS) .build(); Moshi moshi = new Moshi.Builder() .add(new BigDecimalAdapter()) .build(); okHttpClient = new OkHttpClient.Builder() .addInterceptor(new HttpLoggingInterceptor() .setLevel(HttpLoggingInterceptor.Level.BODY)) .readTimeout(1, TimeUnit.SECONDS) .retryOnConnectionFailure(false) .build(); countDownLatch = new CountDownLatch(2); service = new Retrofit.Builder() .addConverterFactory(MoshiConverterFactory.create(moshi)) .callbackExecutor(new Executor() { @Override public void execute(@Nonnull Runnable command) { command.run(); countDownLatch.countDown(); } }) .client(okHttpClient) .baseUrl("http://localhost:" + wireMockRule.port()) .build() .create(RidesService.class); controller = new RideRequestButtonController(view, service, callback); }
Example #15
Source File: AppCenterServiceFactory.java From appcenter-plugin with MIT License | 5 votes |
public AppCenterService createAppCenterService() { final HttpUrl baseHttpUrl = HttpUrl.get(baseUrl); final OkHttpClient.Builder builder = createHttpClientBuilder(baseHttpUrl) .addInterceptor(chain -> { final Request request = chain.request(); final Headers newHeaders = request.headers().newBuilder() .add("Accept", "application/json") .add("Content-Type", "application/json") .add("X-API-Token", Secret.toString(apiToken)) .build(); final Request newRequest = request.newBuilder() .headers(newHeaders) .build(); return chain.proceed(newRequest); }); final Retrofit retrofit = new Retrofit.Builder() .baseUrl(baseHttpUrl) .client(builder.build()) .addConverterFactory(MoshiConverterFactory.create()) .build(); return retrofit.create(AppCenterService.class); }
Example #16
Source File: IclusionApiMain.java From hmftools with GNU General Public License v3.0 | 5 votes |
@NotNull private static IclusionApi buildIclusionApi(@NotNull OkHttpClient httpClient, @NotNull String iClusionEndpoint) { MoshiConverterFactory moshiConverterFactory = MoshiConverterFactory.create(new Moshi.Builder().add(new IclusionResponseAdapter()).build()); Retrofit retrofit = new Retrofit.Builder().baseUrl(iClusionEndpoint) .addConverterFactory(moshiConverterFactory) .addCallAdapterFactory(RxJava2CallAdapterFactory.createAsync()) .client(httpClient) .build(); return retrofit.create(IclusionApi.class); }
Example #17
Source File: ApiModule.java From droidconat-2016 with Apache License 2.0 | 5 votes |
@Provides @Singleton Retrofit provideRetrofit(OkHttpClient client, Moshi moshi, ApiEndpoint endpoint) { return new Retrofit.Builder() .client(client) .baseUrl(endpoint.url) .addConverterFactory(MoshiConverterFactory.create(moshi)) .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) .build(); }
Example #18
Source File: ApiClient.java From andela-crypto-app with Apache License 2.0 | 5 votes |
public static Retrofit getClient() { if (retrofit == null) { retrofit = new Retrofit.Builder() .baseUrl(URLs.BASE_URL) .client(getOkClient()) .addConverterFactory(MoshiConverterFactory.create(getMoshi())) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .build(); } return retrofit; }
Example #19
Source File: KitsuRestApi.java From .samples with GNU General Public License v3.0 | 5 votes |
private KitsuRestApi() { final Retrofit retrofit = (new Retrofit.Builder()) .baseUrl("https://kitsu.io/api/edge/") .addConverterFactory(MoshiConverterFactory.create()) .build(); kitsuApi = retrofit.create(KitsuSpecApi.class); }
Example #20
Source File: HttpModule.java From auth with MIT License | 5 votes |
public RedditApi getApiService() { if (apiService == null) { synchronized (this) { if (apiService == null) { OAuthAccountManager authenticator = app.getAccountManager(); final OkHttpClient okHttpClient = provideOkHttp() .newBuilder() // add authenticators only here to prevent deadlocks when // (re-)authenticating .authenticator(new RequestRetryAuthenticator(authenticator)) .addInterceptor(new RequestAuthInterceptor(authenticator)) .build(); MoshiConverterFactory converterFactory = MoshiConverterFactory.create(provideMoshi()); apiService = new Retrofit.Builder() .client(okHttpClient) .addConverterFactory(converterFactory) .addCallAdapterFactory(RxJava2CallAdapterFactory.createAsync()) .baseUrl("https://oauth.reddit.com/api/") .build() .create(RedditApi.class); } } } return apiService; }
Example #21
Source File: BackendConnector.java From radiance with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static List<Track> doTrackSearch(String releaseId) throws IOException { Retrofit retrofit = new Retrofit.Builder() .baseUrl(MusicBrainzService.API_URL) .client(getHttpClient()) .addConverterFactory(MoshiConverterFactory.create()) .build(); MusicBrainzService service = retrofit.create(MusicBrainzService.class); Response<Release> releaseResponse = service.getRelease(releaseId).execute(); Release release = releaseResponse.body(); return release.media.get(0).tracks; }
Example #22
Source File: ConfigHelper.java From in-app-payments-android-quickstart with Apache License 2.0 | 5 votes |
public static Retrofit createRetrofitInstance() { return new Retrofit .Builder() .baseUrl(ConfigHelper.CHARGE_SERVER_URL) .addConverterFactory(MoshiConverterFactory.create()) .build(); }
Example #23
Source File: AppCenterServiceFactory.java From appcenter-plugin with MIT License | 5 votes |
public UploadService createUploadService(@Nonnull final String uploadUrl) { final HttpUrl httpUploadUrl = HttpUrl.get(uploadUrl); final HttpUrl baseUrl = HttpUrl.get(String.format("%1$s://%2$s/", httpUploadUrl.scheme(), httpUploadUrl.host())); final Retrofit retrofit = new Retrofit.Builder() .baseUrl(baseUrl) .client(createHttpClientBuilder(baseUrl).build()) .addConverterFactory(MoshiConverterFactory.create()) .build(); return retrofit.create(UploadService.class); }
Example #24
Source File: DataModule.java From android with Apache License 2.0 | 4 votes |
@Provides @Singleton Converter.Factory provideConverterFactory(Moshi moshi) { return MoshiConverterFactory.create(moshi); }
Example #25
Source File: TektonProxyClient.java From secrets-proxy with Apache License 2.0 | 4 votes |
/** * Initial client setup to get TrustStore, OkHttpClient and Retrofit * * @param domain * @throws GeneralSecurityException */ public void setup(String domain) throws GeneralSecurityException { log.info("Initialize setup for Tekton Proxy Client"); /* Get the configuration properties for Tekton only for given domain*/ Optional<ClientsAuthConfig.ClientsAuthDomain> clientAuth = clientsConfig.getAuthClients(domain); Moshi moshi = new Moshi.Builder().add(new DateAdapter()).build(); HttpLoggingInterceptor logIntcp = new HttpLoggingInterceptor(s -> log.info(s)); logIntcp.setLevel(BASIC); TrustManager[] trustManagers = ProxyClientUtil.getTrustManagers(config); SSLSocketFactory socketFactory = ProxyClientUtil.getSocketfactory(trustManagers); int timeout = clientsConfig.getExpiresInSec(); OkHttpClient okhttp = new OkHttpClient() .newBuilder() .sslSocketFactory(socketFactory, (X509TrustManager) trustManagers[0]) .connectionSpecs(singletonList(ConnectionSpec.MODERN_TLS)) .followSslRedirects(false) .retryOnConnectionFailure(true) .connectTimeout(timeout, SECONDS) .readTimeout(timeout, SECONDS) .writeTimeout(timeout, SECONDS) .addNetworkInterceptor(logIntcp) .addInterceptor( chain -> { Request.Builder reqBuilder = chain.request().newBuilder().addHeader("Content-Type", "application/json"); reqBuilder.addHeader( SecretsConstants.TEKTON_AUTH_HEADER, clientAuth.get().getAuth().getToken()); return chain.proceed(reqBuilder.build()); }) .build(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(clientAuth.get().getUrl()) .client(okhttp) .addConverterFactory(MoshiConverterFactory.create(moshi)) .build(); this.tektonProxy = retrofit.create(TektonProxy.class); errResConverter = retrofit.responseBodyConverter(ErrorRes.class, new Annotation[0]); }
Example #26
Source File: MSProxyClient.java From secrets-proxy with Apache License 2.0 | 4 votes |
/** * Initial client setup to get TrustStore, OkHttpClient and Retrofit * * @param domain * @throws GeneralSecurityException */ public void setup(String domain) throws GeneralSecurityException { log.info("Initialize setup for MS Proxy Client"); /* Get the clients configuration for MS*/ Optional<ClientsAuthConfig.ClientsAuthDomain> clientAuth = clientsConfig.getAuthClients(SecretsConstants.MS + domain); Moshi moshi = new Moshi.Builder().add(new DateAdapter()).build(); HttpLoggingInterceptor logIntcp = new HttpLoggingInterceptor(s -> log.info(s)); logIntcp.setLevel(BASIC); TrustManager[] trustManagers = ProxyClientUtil.getTrustManagers(config); SSLSocketFactory socketFactory = ProxyClientUtil.getSocketfactory(trustManagers); int timeout = clientsConfig.getExpiresInSec(); OkHttpClient okhttp = new OkHttpClient() .newBuilder() .sslSocketFactory(socketFactory, (X509TrustManager) trustManagers[0]) .connectionSpecs(singletonList(ConnectionSpec.MODERN_TLS)) .followSslRedirects(false) .retryOnConnectionFailure(true) .connectTimeout(timeout, SECONDS) .readTimeout(timeout, SECONDS) .writeTimeout(timeout, SECONDS) .addNetworkInterceptor(logIntcp) .addInterceptor( chain -> { Request.Builder reqBuilder = chain.request().newBuilder().addHeader("Content-Type", "application/json"); reqBuilder.addHeader( SecretsConstants.MS_AUTH_HEADER, clientAuth.get().getAuth().getToken()); return chain.proceed(reqBuilder.build()); }) .build(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(clientAuth.get().getUrl()) .client(okhttp) .addConverterFactory(MoshiConverterFactory.create(moshi)) .build(); this.msProxy = retrofit.create(MSProxy.class); errResConverter = retrofit.responseBodyConverter(ErrorRes.class, new Annotation[0]); }
Example #27
Source File: InfluxDBImpl.java From influxdb-java with MIT License | 4 votes |
/** * Constructs a new {@code InfluxDBImpl}. * * @param url * The InfluxDB server API URL * @param username * The InfluxDB user name * @param password * The InfluxDB user password * @param okHttpBuilder * The OkHttp Client Builder * @param retrofitBuilder * The Retrofit Builder * @param responseFormat * The {@code ResponseFormat} to use for response from InfluxDB * server */ public InfluxDBImpl(final String url, final String username, final String password, final OkHttpClient.Builder okHttpBuilder, final Retrofit.Builder retrofitBuilder, final ResponseFormat responseFormat) { this.messagePack = ResponseFormat.MSGPACK.equals(responseFormat); this.hostName = parseHost(url); this.loggingInterceptor = new HttpLoggingInterceptor(); setLogLevel(LOG_LEVEL); this.gzipRequestInterceptor = new GzipRequestInterceptor(); OkHttpClient.Builder clonedOkHttpBuilder = okHttpBuilder.build().newBuilder() .addInterceptor(loggingInterceptor) .addInterceptor(gzipRequestInterceptor); if (username != null && password != null) { clonedOkHttpBuilder.addInterceptor(new BasicAuthInterceptor(username, password)); } Factory converterFactory = null; switch (responseFormat) { case MSGPACK: clonedOkHttpBuilder.addInterceptor(chain -> { Request request = chain.request().newBuilder().addHeader("Accept", APPLICATION_MSGPACK).build(); return chain.proceed(request); }); converterFactory = MessagePackConverterFactory.create(); chunkProccesor = new MessagePackChunkProccesor(); break; case JSON: default: converterFactory = MoshiConverterFactory.create(); Moshi moshi = new Moshi.Builder().build(); JsonAdapter<QueryResult> adapter = moshi.adapter(QueryResult.class); chunkProccesor = new JSONChunkProccesor(adapter); break; } this.client = clonedOkHttpBuilder.build(); Retrofit.Builder clonedRetrofitBuilder = retrofitBuilder.baseUrl(url).build().newBuilder(); this.retrofit = clonedRetrofitBuilder.client(this.client) .addConverterFactory(converterFactory).build(); this.influxDBService = this.retrofit.create(InfluxDBService.class); }
Example #28
Source File: BackendConnector.java From radiance with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static List<SearchResultRelease> doAlbumSearch(String artistId, String artistName) throws IOException { Retrofit retrofit = new Retrofit.Builder() .baseUrl(MusicBrainzService.API_URL) .client(getHttpClient()) .addConverterFactory(MoshiConverterFactory.create()) .build(); MusicBrainzService service = retrofit.create(MusicBrainzService.class); Response<ReleaseList> releaseResponse = service.getReleases(artistId).execute(); ReleaseList releases = releaseResponse.body(); List<SearchResultRelease> result = new ArrayList<>(); for (SearchResultRelease release : releases.releases) { if ((release.asin == null) || release.asin.isEmpty()) { continue; } if ((release.releaseEvents == null) || release.releaseEvents.isEmpty()) { continue; } boolean foundUsRelease = false; for (ReleaseEvent releaseEvent : release.releaseEvents) { if (releaseEvent.area == null) { continue; } if (!"United States".equals(releaseEvent.area.name)) { continue; } if ((releaseEvent.date == null) || releaseEvent.date.isEmpty()) { continue; } foundUsRelease = true; break; } if (!foundUsRelease) { continue; } // do we already have one? boolean isDuplicate = false; for (SearchResultRelease present : result) { if (present.asin.equals(release.asin) || present.title.equals(release.title)) { isDuplicate = true; break; } } if (isDuplicate) { continue; } release.artist = artistName; result.add(release); } return result; }