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

se.michaelthelin.spotify.requests.data.tracks.GetAudioFeaturesForSeveralTracksRequest Maven / Gradle / Ivy

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

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.apache.hc.core5.http.ParseException;
import se.michaelthelin.spotify.exceptions.SpotifyWebApiException;
import se.michaelthelin.spotify.model_objects.specification.AudioFeatures;
import se.michaelthelin.spotify.requests.data.AbstractDataRequest;

import java.io.IOException;

/**
 * Get audio features for multiple tracks based on their Spotify IDs.
 */
@JsonDeserialize(builder = GetAudioFeaturesForSeveralTracksRequest.Builder.class)
public class GetAudioFeaturesForSeveralTracksRequest extends AbstractDataRequest {

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

  /**
   * Get audio features for several tracks.
   *
   * @return Multiple {@link AudioFeatures} objects.
   * @throws IOException            In case of networking issues.
   * @throws SpotifyWebApiException The Web API returned an error further specified in this exception's root cause.
   */
  public AudioFeatures[] execute() throws
    IOException,
    SpotifyWebApiException,
    ParseException {
    return new AudioFeatures.JsonUtil().createModelObjectArray(getJson(), "audio_features");
  }

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

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

    /**
     * The track IDs setter.
     *
     * @param ids Required. A comma-separated list of the Spotify IDs for the tracks. Maximum: 100 IDs.
     * @return A {@link GetAudioFeaturesForSeveralTracksRequest.Builder}.
     * @see Spotify: URIs & IDs
     */
    public Builder ids(final String ids) {
      assert (ids != null);
      assert (ids.split(",").length <= 100);
      return setQueryParameter("ids", ids);
    }

    /**
     * The request build method.
     *
     * @return A custom {@link GetAudioFeaturesForSeveralTracksRequest}.
     */
    @Override
    public GetAudioFeaturesForSeveralTracksRequest build() {
      setPath("/v1/audio-features");
      return new GetAudioFeaturesForSeveralTracksRequest(this);
    }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy