Skip to content

Instantly share code, notes, and snippets.

@NinoDLC
Created March 1, 2019 11:55
Show Gist options
  • Save NinoDLC/2d7f79a63472a1c061036f3477ac2807 to your computer and use it in GitHub Desktop.
Save NinoDLC/2d7f79a63472a1c061036f3477ac2807 to your computer and use it in GitHub Desktop.
private NYTimesService() {
HttpLoggingInterceptor loggerInterceptor = new HttpLoggingInterceptor();
loggerInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(loggerInterceptor)
.addInterceptor(new Interceptor() {
@NonNull
@Override
public Response intercept(@NonNull Chain chain) throws IOException {
Request request = chain.request();
HttpUrl urlWithApiKey = request.url()
.newBuilder()
.addQueryParameter(PARAM_NAME_APIKEY, APIKEY)
.build();
request = request.newBuilder()
.url(urlWithApiKey)
.build();
return chain.proceed(request);
}
})
.build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create(new GsonBuilder().setDateFormat(DATE_FORMAT)
.create()))
.client(client)
.build();
mService = retrofit.create(NYTimesApi.class);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment