All Downloads are FREE. Search and download functionalities are using the official Maven repository.

se.michaelthelin.spotify.requests.data.artists.GetArtistsAlbumsRequest Maven / Gradle / Ivy

There is a newer version: 9.0.0-RC1
Show newest version
package se.michaelthelin.spotify.requests.data.artists;

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.AlbumSimplified;
import se.michaelthelin.spotify.model_objects.specification.Paging;
import se.michaelthelin.spotify.requests.data.AbstractDataPagingRequest;
import se.michaelthelin.spotify.requests.data.AbstractDataRequest;

import java.io.IOException;

/**
 * Get Spotify catalog information about an artist’s albums. Optional parameters can be specified in the query string to
 * filter and sort the response.
 */
@JsonDeserialize(builder = GetArtistsAlbumsRequest.Builder.class)
public class GetArtistsAlbumsRequest extends AbstractDataRequest> {

  /**
   * The private {@link GetArtistsAlbumsRequest} constructor.
   *
   * @param builder A {@link GetArtistsAlbumsRequest.Builder}.
   */
  private GetArtistsAlbumsRequest(final Builder builder) {
    super(builder);
  }

  /**
   * Get the {@link AlbumSimplified} objects.
   *
   * @return An {@link AlbumSimplified} paging.
   * @throws IOException            In case of networking issues.
   * @throws SpotifyWebApiException The Web API returned an error further specified in this exception's root cause.
   */
  public Paging execute() throws
    IOException,
    SpotifyWebApiException,
    ParseException {
    return new AlbumSimplified.JsonUtil().createModelObjectPaging(getJson());
  }

  /**
   * Builder class for building a {@link GetArtistsAlbumsRequest}.
   */
  public static final class Builder extends AbstractDataPagingRequest.Builder {

    /**
     * Create a new {@link GetArtistsAlbumsRequest.Builder} instance.
     *
     * @param accessToken Required. A valid access token from the Spotify Accounts service.
     */
    public Builder(final String accessToken) {
      super(accessToken);
    }

    /**
     * The artist ID setter.
     *
     * @param id The Spotify ID for the artist.
     * @return A {@link GetArtistsAlbumsRequest.Builder}.
     * @see Spotify URIs & IDs
     */
    public Builder id(final String id) {
      assert (id != null);
      assert (!id.equals(""));
      return setPathParameter("id", id);
    }

    /**
     * The album type filter setter.
     *
     * @param album_type Optional. A comma-separated list of keywords that will be used to filter the response. If not
     *                   supplied, all album types will be returned. Valid values are: {@code album}, {@code single},
     *                   {@code appears_on} and {@code compilation}.
     * @return A {@link GetArtistsAlbumsRequest.Builder}.
     */
    public Builder album_type(final String album_type) {
      assert (album_type != null);
      assert (album_type.matches("((^|,)(single|album|appears_on|compilation))+$"));
      return setQueryParameter("album_type", album_type);
    }

    /**
     * The market filter setter.
     *
     * @param market Optional. An ISO 3166-1 alpha-2 country code. Supply this parameter to limit the response to one
     *               particular geographical market.
     * @return A {@link GetArtistsAlbumsRequest.Builder}.
     * @see Wikipedia: ISO 3166-1 alpha-2 country codes
     */
    public Builder market(final CountryCode market) {
      assert (market != null);
      return setQueryParameter("market", market);
    }

    /**
     * The limit setter.
     *
     * @param limit Optional. The number of album objects to return. Default: 20. Minimum: 1. Maximum: 50.
     * @return A {@link GetArtistsAlbumsRequest.Builder}.
     */
    @Override
    public Builder limit(final Integer limit) {
      assert (1 <= limit && limit <= 50);
      return setQueryParameter("limit", limit);
    }

    /**
     * The offset setter.
     *
     * @param offset Optional. The index of the first album to return. Default: 0 (i.e., the first album). Use with
     *               {@link #limit(Integer)} to get the next set of albums.
     * @return A {@link GetArtistsAlbumsRequest.Builder}.
     */
    @Override
    public Builder offset(final Integer offset) {
      assert (offset >= 0);
      return setQueryParameter("offset", offset);
    }

    /**
     * The request build method.
     *
     * @return A custom {@link GetArtistsAlbumsRequest}.
     */
    @Override
    public GetArtistsAlbumsRequest build() {
      setPath("/v1/artists/{id}/albums");
      return new GetArtistsAlbumsRequest(this);
    }

    @Override
    protected Builder self() {
      return this;
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy