se.michaelthelin.spotify.requests.data.library.CheckUsersSavedAlbumsRequest 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 albums is already saved in the current Spotify user’s "Your Music" library.
*/
@JsonDeserialize(builder = CheckUsersSavedAlbumsRequest.Builder.class)
public class CheckUsersSavedAlbumsRequest extends AbstractDataRequest {
/**
* The private {@link CheckUsersSavedAlbumsRequest} constructor.
*
* @param builder A {@link CheckUsersSavedAlbumsRequest.Builder}.
*/
private CheckUsersSavedAlbumsRequest(final Builder builder) {
super(builder);
}
/**
* Check whether an album is present in the current user's "Your Music" library.
*
* @return Whether an album 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.
*/
public Boolean[] execute() throws
IOException,
SpotifyWebApiException,
ParseException {
return new Gson().fromJson(JsonParser.parseString(getJson()).getAsJsonArray(), Boolean[].class);
}
/**
* Builder class for building a {@link CheckUsersSavedAlbumsRequest}.
*/
public static final class Builder extends AbstractDataRequest.Builder {
/**
* Create a new {@link CheckUsersSavedAlbumsRequest.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: Using Scopes
*/
public Builder(final String accessToken) {
super(accessToken);
}
/**
* The album IDs setter.
*
* @param ids Required. A comma-separated list of the Spotify IDs for the albums. Maximum: 50 IDs.
* @return A {@link CheckUsersSavedAlbumsRequest.Builder}.
* @see Spotify: URIs & IDs
*/
public 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 CheckUsersSavedAlbumsRequest}.
*/
@Override
public CheckUsersSavedAlbumsRequest build() {
setPath("/v1/me/albums/contains");
return new CheckUsersSavedAlbumsRequest(this);
}
@Override
protected Builder self() {
return this;
}
}
}