se.michaelthelin.spotify.requests.data.library.CheckUsersSavedEpisodesRequest Maven / Gradle / Ivy
Show all versions of spotify-web-api-java Show documentation
package se.michaelthelin.spotify.requests.data.library;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.google.gson.Gson;
import com.google.gson.JsonParser;
import org.apache.hc.core5.http.ParseException;
import se.michaelthelin.spotify.exceptions.SpotifyWebApiException;
import se.michaelthelin.spotify.requests.data.AbstractDataRequest;
import java.io.IOException;
/**
* Check if one or more episodes is already saved in the current Spotify user's 'Your Episodes' library.
*/
@JsonDeserialize(builder = CheckUsersSavedEpisodesRequest.Builder.class)
public class CheckUsersSavedEpisodesRequest extends AbstractDataRequest {
/**
* The private {@link CheckUsersSavedEpisodesRequest} constructor.
*
* @param builder A {@link CheckUsersSavedEpisodesRequest.Builder}.
*/
private CheckUsersSavedEpisodesRequest(final CheckUsersSavedEpisodesRequest.Builder builder) {
super(builder);
}
/**
* Check if one or more episodes is already saved in the current Spotify user's 'Your Episodes' library.
*
* @return Whether an episode is present in the current user's "Your Music" library.
* @throws IOException In case of networking issues.
* @throws SpotifyWebApiException The Web API returned an error further specified in this exception's root cause.
*/
@Override
public Boolean[] execute() throws
IOException,
SpotifyWebApiException,
ParseException {
return new Gson().fromJson(JsonParser.parseString(getJson()).getAsJsonArray(), Boolean[].class);
}
/**
* Builder class for building a {@link CheckUsersSavedEpisodesRequest}.
*/
public static final class Builder extends AbstractDataRequest.Builder {
/**
* Create a new {@link CheckUsersSavedEpisodesRequest.Builder} instance.
*
* The {@code user-library-read} scope must have been authorized by the user.
*
* @param accessToken Required. A valid access token from the Spotify Accounts service.
* @see Spotify: Scopes
*/
public Builder(final String accessToken) {
super(accessToken);
}
/**
* The episode IDs setter.
*
* @param ids Required. A comma-separated list of the Spotify IDs for the episodes. Maximum: 50 IDs.
* @return A {@link CheckUsersSavedEpisodesRequest.Builder}.
* @see Spotify: URIs & IDs
*/
public CheckUsersSavedEpisodesRequest.Builder ids(final String ids) {
assert (ids != null);
assert (ids.split(",").length <= 50);
return setQueryParameter("ids", ids);
}
/**
* The request build method.
*
* @return A custom {@link CheckUsersSavedEpisodesRequest}.
*/
@Override
public CheckUsersSavedEpisodesRequest build() {
setPath("/v1/me/episodes/contains");
return new CheckUsersSavedEpisodesRequest(this);
}
@Override
protected CheckUsersSavedEpisodesRequest.Builder self() {
return this;
}
}
}