use of io.salyangoz.apistartup.model.response.OAuthResponse in project Api-Startup-Android by salyangoz.
the class ApiClientProvider method getInstance.
public static ApiClient getInstance() {
if (apiClient == null) {
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
httpClient.addInterceptor(loggingInterceptor);
httpClient.addInterceptor(new HeaderInterceptor());
}
OAuthResponse oAuthResponse = OAuthResponse.get();
if (oAuthResponse != null && authInterceptor == null) {
authInterceptor = new AuthenticationInterceptor(oAuthResponse.getAccessToken());
// Add Bearer Authentication if Authentication Token Exists
if (!httpClient.interceptors().contains(authInterceptor)) {
httpClient.authenticator(new TokenAuthenticator());
httpClient.interceptors().add(authInterceptor);
}
}
builder.client(httpClient.build()).build();
retrofit = builder.build();
retrofit.responseBodyConverter(APIError.class, new Annotation[0]);
return retrofit.create(ApiClient.class);
}
Aggregations