Search in sources :

Example 1 with OAuthResponse

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);
}
Also used : OAuthResponse(io.salyangoz.apistartup.model.response.OAuthResponse) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor)

Aggregations

OAuthResponse (io.salyangoz.apistartup.model.response.OAuthResponse)1 HttpLoggingInterceptor (okhttp3.logging.HttpLoggingInterceptor)1