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

se.michaelthelin.spotify.requests.data.library.GetUsersSavedTracksRequest Maven / Gradle / Ivy

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

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

import java.io.IOException;

/**
 * Get a list of the songs saved in the current Spotify user’s "Your Music" library.
 */
@JsonDeserialize(builder = GetUsersSavedTracksRequest.Builder.class)
public class GetUsersSavedTracksRequest extends AbstractDataRequest> {

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

  /**
   * Get the songs from the current users "Your Music" library.
   *
   * @return A {@link SavedTrack} 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 SavedTrack.JsonUtil().createModelObjectPaging(getJson());
  }

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

    /**
     * Create a new {@link GetUsersSavedTracksRequest.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 limit setter. * * @param limit Optional. The maximum number of objects to return. Default: 20. Minimum: 1. Maximum: 50. * @return A {@link GetUsersSavedTracksRequest.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 object to return. Default: 0 (i.e., the first object). Use with * {@link #limit(Integer)} to get the next set of objects. * @return A {@link GetUsersSavedTracksRequest.Builder}. */ @Override public Builder offset(final Integer offset) { assert (offset >= 0); return setQueryParameter("offset", offset); } /** * 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 GetUsersSavedTracksRequest.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 request build method. * * @return A custom {@link GetUsersSavedTracksRequest}. */ @Override public GetUsersSavedTracksRequest build() { setPath("/v1/me/tracks"); return new GetUsersSavedTracksRequest(this); } @Override protected Builder self() { return this; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy