se.michaelthelin.spotify.requests.data.playlists.GetPlaylistRequest Maven / Gradle / Ivy
Show all versions of spotify-web-api-java Show documentation
package se.michaelthelin.spotify.requests.data.playlists;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.neovisionaries.i18n.CountryCode;
import org.apache.hc.core5.http.ParseException;
import se.michaelthelin.spotify.exceptions.SpotifyWebApiException;
import se.michaelthelin.spotify.model_objects.specification.Playlist;
import se.michaelthelin.spotify.requests.data.AbstractDataRequest;
import java.io.IOException;
/**
* Get a playlist owned by a Spotify user.
*/
@JsonDeserialize(builder = GetPlaylistRequest.Builder.class)
public class GetPlaylistRequest extends AbstractDataRequest {
/**
* The private {@link GetPlaylistRequest} constructor.
*
* @param builder A {@link GetPlaylistRequest.Builder}.
*/
private GetPlaylistRequest(final Builder builder) {
super(builder);
}
/**
* Get a playlist.
*
* @return A {@link Playlist}.
* @throws IOException In case of networking issues.
* @throws SpotifyWebApiException The Web API returned an error further specified in this exception's root cause.
*/
public Playlist execute() throws
IOException,
SpotifyWebApiException,
ParseException {
return new Playlist.JsonUtil().createModelObject(getJson());
}
/**
* Builder class for building a {@link GetPlaylistRequest}.
*/
public static final class Builder extends AbstractDataRequest.Builder {
/**
* Create a new {@link GetPlaylistRequest.Builder}.
*
* Both Public and Private playlists belonging to any user are retrievable on provision of a valid access token.
*
* @param accessToken Required. A valid access token from the Spotify Accounts service.
*/
public Builder(final String accessToken) {
super(accessToken);
}
/**
* The playlist ID setter.
*
* @param playlist_id The Spotify ID for the playlist.
* @return A {@link GetPlaylistRequest.Builder}.
* @see Spotify: URIs & IDs
*/
public Builder playlist_id(final String playlist_id) {
assert (playlist_id != null);
assert (!playlist_id.equals(""));
return setPathParameter("playlist_id", playlist_id);
}
/**
* The fields filter setter.
*
* @param fields Optional. Filters for the query: a comma-separated list of the fields to return.
* If omitted, all fields are returned.
* @return A {@link GetPlaylistRequest.Builder}.
* @see
* Spotify: More Details on Playlist Fields
*/
public Builder fields(final String fields) {
assert (fields != null);
assert (!fields.equals(""));
return setQueryParameter("fields", fields);
}
/**
* The market country code setter.
*
* @param market Optional. An ISO 3166-1 alpha-2 country code. Provide this
* parameter if you want to apply Track Relinking.
* @return A {@link GetPlaylistRequest.Builder}.
* @see Wikipedia: ISO 3166-1 alpha-2 country codes
* @see Spotify: Track Relinking Guide
*/
public Builder market(final CountryCode market) {
assert (market != null);
return setQueryParameter("market", market);
}
/**
* The additional types setter.
*
* @param additionalTypes Optional. A comma-separated list of item types that your client supports
* besides the default track type. Valid types are: {@code track} and {@code episode}.
* An unsupported type in the response is expected to be represented as {@code null} value in the {@code item} field.
* @return A {@link GetPlaylistRequest.Builder}.
*/
public Builder additionalTypes(final String additionalTypes) {
assert (additionalTypes != null);
assert (additionalTypes.matches("((^|,)(episode|track))+$"));
return setQueryParameter("additional_types", additionalTypes);
}
/**
* The request build method.
*
* @return A custom {@link GetPlaylistRequest}.
*/
@Override
public GetPlaylistRequest build() {
setPath("/v1/playlists/{playlist_id}");
return new GetPlaylistRequest(this);
}
@Override
protected Builder self() {
return this;
}
}
}