Class: Spotted::Resources::Playlists::Tracks

Inherits:
Object
  • Object
show all
Defined in:
lib/spotted/resources/playlists/tracks.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Tracks

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Tracks.

Parameters:



151
152
153
# File 'lib/spotted/resources/playlists/tracks.rb', line 151

def initialize(client:)
  @client = client
end

Instance Method Details

#add(playlist_id, body_position: nil, body_uris: nil, request_options: {}) ⇒ Spotted::Models::Playlists::TrackAddResponse

Some parameter documentations has been truncated, see Models::Playlists::TrackAddParams for more details.

Add one or more items to a user’s playlist.

Parameters:

  • playlist_id (String)

    Path param: The [Spotify ID](/documentation/web-api/concepts/spotify-uris-ids) o

  • body_position (Integer)

    Body param: The position to insert the items, a zero-based index. For example, t

  • body_uris (Array<String>)

    Body param: A JSON array of the [Spotify URIs](/documentation/web-api/concepts/s

  • request_options (Spotted::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/spotted/resources/playlists/tracks.rb', line 106

def add(playlist_id, params = {})
  parsed, options = Spotted::Playlists::TrackAddParams.dump_request(params)
  query_params = [:query_position, :query_uris]
  @client.request(
    method: :post,
    path: ["playlists/%1$s/tracks", playlist_id],
    query: parsed.slice(*query_params).transform_keys(query_position: "position", query_uris: "uris"),
    body: parsed.except(*query_params),
    model: Spotted::Models::Playlists::TrackAddResponse,
    options: options
  )
end

#list(playlist_id, additional_types: nil, fields: nil, limit: nil, market: nil, offset: nil, request_options: {}) ⇒ Spotted::Internal::CursorURLPage<Spotted::Models::PlaylistTrackObject>

Some parameter documentations has been truncated, see Models::Playlists::TrackListParams for more details.

Get full details of the items of a playlist owned by a Spotify user.

Parameters:

  • playlist_id (String)

    The [Spotify ID](/documentation/web-api/concepts/spotify-uris-ids) of the playli

  • additional_types (String)

    A comma-separated list of item types that your client supports besides the defau

  • fields (String)

    Filters for the query: a comma-separated list of the

  • limit (Integer)

    The maximum number of items to return. Default: 20. Minimum: 1. Maximum: 100.

  • market (String)

    An [ISO 3166-1 alpha-2 country code](en.wikipedia.org/wiki/ISO_3166-1_al

  • offset (Integer)

    The index of the first item to return. Default: 0 (the first item). Use with lim

  • request_options (Spotted::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/spotted/resources/playlists/tracks.rb', line 76

def list(playlist_id, params = {})
  parsed, options = Spotted::Playlists::TrackListParams.dump_request(params)
  @client.request(
    method: :get,
    path: ["playlists/%1$s/tracks", playlist_id],
    query: parsed,
    page: Spotted::Internal::CursorURLPage,
    model: Spotted::PlaylistTrackObject,
    options: options
  )
end

#remove(playlist_id, tracks: , snapshot_id: nil, request_options: {}) ⇒ Spotted::Models::Playlists::TrackRemoveResponse

Some parameter documentations has been truncated, see Models::Playlists::TrackRemoveParams for more details.

Remove one or more items from a user’s playlist.

Parameters:

  • playlist_id (String)

    The [Spotify ID](/documentation/web-api/concepts/spotify-uris-ids) of the playli

  • tracks (Array<Spotted::Models::Playlists::TrackRemoveParams::Track>)

    An array of objects containing [Spotify URIs](/documentation/web-api/concepts/sp

  • snapshot_id (String)

    The playlist’s snapshot ID against which you want to make the changes.

  • request_options (Spotted::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



137
138
139
140
141
142
143
144
145
146
# File 'lib/spotted/resources/playlists/tracks.rb', line 137

def remove(playlist_id, params)
  parsed, options = Spotted::Playlists::TrackRemoveParams.dump_request(params)
  @client.request(
    method: :delete,
    path: ["playlists/%1$s/tracks", playlist_id],
    body: parsed,
    model: Spotted::Models::Playlists::TrackRemoveResponse,
    options: options
  )
end

#update(playlist_id, body_uris: nil, insert_before: nil, range_length: nil, range_start: nil, snapshot_id: nil, request_options: {}) ⇒ Spotted::Models::Playlists::TrackUpdateResponse

Some parameter documentations has been truncated, see Models::Playlists::TrackUpdateParams for more details.

Either reorder or replace items in a playlist depending on the request’s parameters. To reorder items, include ‘range_start`, `insert_before`, `range_length` and `snapshot_id` in the request’s body. To replace items, include ‘uris` as either a query parameter or in the request’s body. Replacing items in a playlist will overwrite its existing items. This operation can be used for replacing or clearing items in a playlist. <br/> Note: Replace and reorder are mutually exclusive operations which share the same endpoint, but have different parameters. These operations can’t be applied together in a single request.

Parameters:

  • playlist_id (String)

    Path param: The [Spotify ID](/documentation/web-api/concepts/spotify-uris-ids) o

  • body_uris (Array<String>)

    Body param:

  • insert_before (Integer)

    Body param: The position where the items should be inserted.<br/>To reorder the

  • range_length (Integer)

    Body param: The amount of items to be reordered. Defaults to 1 if not set.<br/>T

  • range_start (Integer)

    Body param: The position of the first item to be reordered.

  • snapshot_id (String)

    Body param: The playlist’s snapshot ID against which you want to make the change

  • request_options (Spotted::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/spotted/resources/playlists/tracks.rb', line 39

def update(playlist_id, params = {})
  parsed, options = Spotted::Playlists::TrackUpdateParams.dump_request(params)
  query_params = [:query_uris]
  @client.request(
    method: :put,
    path: ["playlists/%1$s/tracks", playlist_id],
    query: parsed.slice(*query_params).transform_keys(query_uris: "uris"),
    body: parsed.except(*query_params),
    model: Spotted::Models::Playlists::TrackUpdateResponse,
    options: options
  )
end