Class: Spotify::PlaylistsResource

Inherits:
Resource
  • Object
show all
Defined in:
lib/spotify/resources/playlists.rb

Instance Attribute Summary

Attributes inherited from Resource

#client

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from Spotify::Resource

Instance Method Details

#add_tracks(id:, uris:, position: nil) ⇒ Object



17
18
19
20
21
22
# File 'lib/spotify/resources/playlists.rb', line 17

def add_tracks(id:, uris:, position: nil)
  body = { uris: uris.split(",") }
  body[:position] = position if position
  response = post_request("playlists/#{id}/tracks", body: body)
  Snapshot.new response.body
end

#create(user:, name:, **params) ⇒ Object



31
32
33
34
35
# File 'lib/spotify/resources/playlists.rb', line 31

def create(user:, name:, **params)
  attrs = { name: name }
  response = post_request("users/#{user}/playlists", body: attrs.merge(params))
  Playlist.new response.body
end

#get(id:, **params) ⇒ Object



3
4
5
6
# File 'lib/spotify/resources/playlists.rb', line 3

def get(id:, **params)
  response = get_request("playlists/#{id}", params: params)
  Playlist.new response.body
end

#remove_tracks(id:, uris:, snapshot_id: nil) ⇒ Object



24
25
26
27
28
29
# File 'lib/spotify/resources/playlists.rb', line 24

def remove_tracks(id:, uris:, snapshot_id: nil)
  body = { tracks: uris.split(",").map { |uri| { uri: uri } } }
  body[:snapshot_id] = snapshot_id if snapshot_id
  response = delete_request("playlists/#{id}/tracks", body: body)
  Snapshot.new response.body
end

#tracks(id:, **params) ⇒ Object



12
13
14
15
# File 'lib/spotify/resources/playlists.rb', line 12

def tracks(id:, **params)
  response = get_request("playlists/#{id}/tracks", params: params)
  Collection.from_response(response, type: Track, key: "items")
end

#update(id:, **attrs) ⇒ Object



8
9
10
# File 'lib/spotify/resources/playlists.rb', line 8

def update(id:, **attrs)
  put_request("playlists/#{id}", body: attrs)
end