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

Instance Method Summary collapse

Methods inherited from Resource

#==, attribute, #attributes=, from_search_result, #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



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/spotify_web/playlist.rb', line 47

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

#uriString

The unique URI representing this playlist in Spotify

Examples:

“spotify:user:benzelano:playlist:starred”

Returns:

  • (String)

    The URI for the resource



32
33
34
# File 'lib/spotify_web/playlist.rb', line 32

def uri
  @uri ||= uri_id && "spotify:user:#{user.username}:playlist:#{uri_id}"
end

#uri_idObject

:nodoc:



36
37
38
# File 'lib/spotify_web/playlist.rb', line 36

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