de.sonallux.spotify.api.http.AuthorizedApiCall Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spotify-web-api-java Show documentation
Show all versions of spotify-web-api-java Show documentation
A Java wrapper for Spotify's Web API
The newest version!
package de.sonallux.spotify.api.http;
import com.fasterxml.jackson.core.type.TypeReference;
import de.sonallux.spotify.api.authorization.ApiAuthorizationProvider;
import lombok.AllArgsConstructor;
import java.io.IOException;
public class AuthorizedApiCall extends ApiCall {
private final ApiAuthorizationProvider authProvider;
public AuthorizedApiCall(ApiAuthorizationProvider authProvider, ApiClient apiClient, Request request, TypeReference responseType) {
super(apiClient, request, responseType);
this.authProvider = authProvider;
}
@Override
protected Response parseResponse(okhttp3.Response rawResponse) throws IOException {
if (rawResponse.code() == 401) { //Unauthorized
if (authProvider.refreshAccessToken()) {
rawResponse = getRawCall().clone().execute();
}
}
return super.parseResponse(rawResponse);
}
@AllArgsConstructor
public static class Factory extends ApiCall.Factory {
private final ApiAuthorizationProvider authProvider;
@Override
public ApiCall createApiCall(ApiClient apiClient, Request request, TypeReference responseType) {
return new AuthorizedApiCall<>(authProvider, apiClient, request, responseType);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy