use of retrofit2.Retrofit in project RxSample by Aload.
the class BasePresenterIml method onInit.
@Override
public void onInit() {
Retrofit retrofit = RequestManger.getRequestManager().getRetrofit(this);
handleNetRes(retrofit);
}
use of retrofit2.Retrofit in project graylog2-server by Graylog2.
the class RemoteInterfaceProvider method get.
public <T> T get(Node node, final String authorizationToken, Class<T> interfaceClass) {
final OkHttpClient okHttpClient = this.okHttpClient.newBuilder().addInterceptor(chain -> {
final Request original = chain.request();
Request.Builder builder = original.newBuilder().header(HttpHeaders.ACCEPT, MediaType.JSON_UTF_8.toString()).method(original.method(), original.body());
if (authorizationToken != null) {
builder = builder.header(HttpHeaders.AUTHORIZATION, authorizationToken).header(SessionAuthenticator.X_GRAYLOG_NO_SESSION_EXTENSION, "true");
}
return chain.proceed(builder.build());
}).build();
final Retrofit retrofit = new Retrofit.Builder().baseUrl(node.getTransportAddress()).addConverterFactory(JacksonConverterFactory.create(objectMapper)).client(okHttpClient).build();
return retrofit.create(interfaceClass);
}
use of retrofit2.Retrofit in project RxJavaSamples by rengwuxian.
the class Network method getGankApi.
public static GankApi getGankApi() {
if (gankApi == null) {
Retrofit retrofit = new Retrofit.Builder().client(okHttpClient).baseUrl("http://gank.io/api/").addConverterFactory(gsonConverterFactory).addCallAdapterFactory(rxJavaCallAdapterFactory).build();
gankApi = retrofit.create(GankApi.class);
}
return gankApi;
}
use of retrofit2.Retrofit in project RxJavaSamples by rengwuxian.
the class Network method getZhuangbiApi.
public static ZhuangbiApi getZhuangbiApi() {
if (zhuangbiApi == null) {
Retrofit retrofit = new Retrofit.Builder().client(okHttpClient).baseUrl("http://www.zhuangbi.info/").addConverterFactory(gsonConverterFactory).addCallAdapterFactory(rxJavaCallAdapterFactory).build();
zhuangbiApi = retrofit.create(ZhuangbiApi.class);
}
return zhuangbiApi;
}
use of retrofit2.Retrofit in project muzei by romannurik.
the class FiveHundredPxExampleArtSource method onTryUpdate.
@Override
protected void onTryUpdate(@UpdateReason int reason) throws RetryException {
String currentToken = (getCurrentArtwork() != null) ? getCurrentArtwork().getToken() : null;
OkHttpClient okHttpClient = new OkHttpClient.Builder().addInterceptor(new Interceptor() {
@Override
public Response intercept(final Chain chain) throws IOException {
Request request = chain.request();
HttpUrl url = request.url().newBuilder().addQueryParameter("consumer_key", Config.CONSUMER_KEY).build();
request = request.newBuilder().url(url).build();
return chain.proceed(request);
}
}).build();
Retrofit retrofit = new Retrofit.Builder().baseUrl("https://api.500px.com/").client(okHttpClient).addConverterFactory(GsonConverterFactory.create()).build();
FiveHundredPxService service = retrofit.create(FiveHundredPxService.class);
PhotosResponse response;
try {
response = service.getPopularPhotos().execute().body();
} catch (IOException e) {
Log.w(TAG, "Error reading 500px response", e);
throw new RetryException();
}
if (response == null || response.photos == null) {
throw new RetryException();
}
if (response.photos.size() == 0) {
Log.w(TAG, "No photos returned from API.");
scheduleUpdate(System.currentTimeMillis() + ROTATE_TIME_MILLIS);
return;
}
Random random = new Random();
Photo photo;
String token;
while (true) {
photo = response.photos.get(random.nextInt(response.photos.size()));
token = Integer.toString(photo.id);
if (response.photos.size() <= 1 || !TextUtils.equals(token, currentToken)) {
break;
}
}
publishArtwork(new Artwork.Builder().title(photo.name).byline(photo.user.fullname).imageUri(Uri.parse(photo.image_url)).token(token).viewIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("http://500px.com/photo/" + photo.id))).build());
scheduleUpdate(System.currentTimeMillis() + ROTATE_TIME_MILLIS);
}
Aggregations