Created
March 1, 2019 11:55
-
-
Save NinoDLC/2d7f79a63472a1c061036f3477ac2807 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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