use of com.pushtorefresh.storio3.Interceptor in project Varis-Android by dkhmelenko.
the class TravisRestClient method getHttpClient.
private OkHttpClient getHttpClient() {
final String userAgent = String.format("TravisClient/%1$s", PackageUtils.getAppVersion());
return mOkHttpClient.newBuilder().addInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request original = chain.request();
Request.Builder request = original.newBuilder().header("User-Agent", userAgent).header("Accept", "application/vnd.travis-ci.2+json");
String accessToken = mAppSettings.getAccessToken();
if (!TextUtils.isEmpty(accessToken)) {
String headerValue = String.format("token %1$s", accessToken);
request.addHeader("Authorization", headerValue);
}
return chain.proceed(request.build());
}
}).build();
}
use of com.pushtorefresh.storio3.Interceptor in project run-wallet-android by runplay.
the class RunIotaAPICore method postConstruct.
/**
* added header for IRI
*/
private void postConstruct() {
boolean USE_AUTH = false;
// if(host.contains(".runplay.com") || host.contains(".runpg.com"))
// USE_AUTH=true;
final String nodeUrl = protocol + "://" + host + ":" + port;
if (USE_AUTH) {
// Log.e("IRI-CONNECT","Using Auth OK");
String creds = Base64.encodeToString((uname + ":" + upassword).getBytes(), false);
final OkHttpClient.Builder builder = new OkHttpClient.Builder();
OkHttpClient client = builder.readTimeout(5000, TimeUnit.SECONDS).addInterceptor(new Interceptor() {
@Override
public okhttp3.Response intercept(Chain chain) throws IOException {
Request request = chain.request();
Request newRequest;
newRequest = request.newBuilder().addHeader(X_IOTA_API_VERSION_HEADER_NAME, X_IOTA_API_VERSION_HEADER_VALUE).addHeader("Authorization", "Basic " + creds).build();
return chain.proceed(newRequest);
}
}).connectTimeout(5000, TimeUnit.SECONDS).build();
// use client to create Retrofit service
final Retrofit retrofit = new Retrofit.Builder().baseUrl(nodeUrl).addConverterFactory(GsonConverterFactory.create()).client(client).build();
service = retrofit.create(IotaAPIService.class);
} else {
// Log.e("IRI-CONNECT","NOOTTTTT Using Auth");
final OkHttpClient client = new OkHttpClient.Builder().readTimeout(5000, TimeUnit.SECONDS).addNetworkInterceptor(new Interceptor() {
@Override
public okhttp3.Response intercept(Chain chain) throws IOException {
final Buffer buffer = new Buffer();
chain.request().body().writeTo(buffer);
return chain.proceed(chain.request());
}
}).addInterceptor(new Interceptor() {
@Override
public okhttp3.Response intercept(Chain chain) throws IOException {
Request request = chain.request();
Request newRequest;
newRequest = request.newBuilder().addHeader(X_IOTA_API_VERSION_HEADER_NAME, X_IOTA_API_VERSION_HEADER_VALUE).build();
return chain.proceed(newRequest);
}
}).connectTimeout(5000, TimeUnit.SECONDS).build();
// use client to create Retrofit service
final Retrofit retrofit = new Retrofit.Builder().baseUrl(nodeUrl).addConverterFactory(GsonConverterFactory.create()).client(client).build();
service = retrofit.create(IotaAPIService.class);
}
// Create OkHttpBuilder
log.debug("Jota-API Java proxy pointing to node url: '{}'", nodeUrl);
}
use of com.pushtorefresh.storio3.Interceptor in project bugzy by cpunq.
the class HostSelectionInterceptorTest method init.
@Before
public void init() throws Exception {
mHostSelectionInterceptor = new HostSelectionInterceptor();
Interceptor testInterceptor = chain -> testRequest.apply(chain);
mOkHttpClient = new OkHttpClient().newBuilder().addInterceptor(mHostSelectionInterceptor).addInterceptor(testInterceptor).build();
}
use of com.pushtorefresh.storio3.Interceptor in project Retrofit-Android-Basic by basil2style.
the class ServiceGenerator method createService.
public static <S> S createService(Class<S> serviceClass, final String authToken) {
if (authToken != null) {
httpClient.interceptors().add(new Interceptor() {
@Override
public okhttp3.Response intercept(Interceptor.Chain chain) throws IOException {
Request original = chain.request();
// Request customization: add request headers
Request.Builder requestBuilder = original.newBuilder().header("Authorization", authToken).method(original.method(), original.body());
Request request = requestBuilder.build();
return chain.proceed(request);
}
});
}
OkHttpClient client = httpClient.build();
Retrofit retrofit = builder.client(client).build();
return retrofit.create(serviceClass);
}
use of com.pushtorefresh.storio3.Interceptor in project Mango by JellyCai1995.
the class OkHttpGlideModule method createInterceptor.
private static Interceptor createInterceptor(final ResponseProgressListener listener) {
return new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
Response response = chain.proceed(request);
return response.newBuilder().body(new OkHttpProgressResponseBody(request.url(), response.body(), listener)).build();
}
};
}
Aggregations