Class: SpotifyWeb::Playlist

Inherits:
Resource show all
Defined in:
lib/spotify_web/playlist.rb

Overview

Represents a collection of songs

Constant Summary

Constants inherited from Resource

Resource::BASE62_CHARS

Instance Attribute Summary collapse

Attributes inherited from Resource

#gid, #id, #uri

Instance Method Summary collapse

Methods inherited from Resource

#==, attribute, #attributes=, #hash, #initialize, #load_metadata, #loaded?, #metadata=, #metadata_uri, #pretty_print, #pretty_print_instance_variables

Methods included from Assertions

#assert_valid_keys, #assert_valid_values

Constructor Details

This class inherits a constructor from SpotifyWeb::Resource

Instance Attribute Details

#nameObject (readonly)

:nodoc:



16
# File 'lib/spotify_web/playlist.rb', line 16

attribute :name

#songsArray<SpotifyWeb::Song> (readonly)

The songs that have been added to this playlist

Returns:



20
21
22
# File 'lib/spotify_web/playlist.rb', line 20

attribute :songs do |songs|
  ResourceCollection.new(client, songs.map {|song| Song.new(client, :uri => song.uri)})
end

#userSpotifyWeb::User (readonly)

The user this playlist is managed by

Returns:



12
# File 'lib/spotify_web/playlist.rb', line 12

attribute :user, :load => false

Instance Method Details

#loadObject

Loads the attributes for this playlist



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/spotify_web/playlist.rb', line 33

def load
  path = uri_id == 'starred' ? uri_id : "playlist/#{uri_id}"
  response = api('request',
    :uri => "hm://playlist/user/#{user.username}/#{path}?from=0&length=100",
    :response_schema => Schema::Playlist4::SelectedListContent
  )
  result = response['result']

  attributes = result.attributes.to_hash
  attributes[:songs] = result.contents.items
  self.attributes = attributes

  super
end

#uri_idObject

:nodoc:



28
29
30
# File 'lib/spotify_web/playlist.rb', line 28

def uri_id #:nodoc:
  @uri_id ||= @uri ? @uri.split(':')[4] : super
end