com.lajospolya.spotifyapiwrapper.request.AbstractSpotifyRequest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spotify-api-wrapper Show documentation
Show all versions of spotify-api-wrapper Show documentation
This project wraps the Spotify public API in order to allow users to intuitively use it
package com.lajospolya.spotifyapiwrapper.request;
import com.lajospolya.spotifyapiwrapper.internal.ISpotifyRequest;
import com.lajospolya.spotifyapiwrapper.spotifyexception.SpotifyRequestBuilderException;
/**
* This is the base class for all Spotify Requests.
* The SpotifyApiClient uses private methods on this field to authorize and built the request
* @author Lajos Polya
* @param the type of the Response Body
*/
public abstract class AbstractSpotifyRequest
{
static final String SPOTIFY_V1_API_URI = "https://api.spotify.com/v1/";
private SpotifyRequestBuilder requestBuilder;
private String accessToken;
AbstractSpotifyRequest(SpotifyRequestBuilder requestBuilder)
{
this.requestBuilder = requestBuilder;
}
/**
* The SpotifyApiClient uses IReflectiveSpotifyClientService to call this method via reflection to build the
* request. In the near future this will be abstracted to an Http Request which doesn't couple Java 11's
* HttpRequest.
* This method is private to simplify the interface for end users.
* @return ISpotifyRequest the built request
*/
private ISpotifyRequest reflectiveBuildRequest()
{
if(accessToken == null)
{
throw new SpotifyRequestBuilderException("Cannot Build a request with a null access token");
}
return this.requestBuilder
.build();
}
/**
* The SpotifyApiClient uses IReflectiveSpotifyClientService to call this method via reflection to set the
* authorization header of the request.
* This method is private to simplify the interface for end users.
*/
private void reflectiveSetAccessToken(String accessToken)
{
this.accessToken = accessToken;
requestBuilder.authorization(this.accessToken);
}
}