Class: RSpotify::Playlist

Inherits:
Base
  • Object
show all
Defined in:
lib/rspotify/playlist.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#external_urls, #href, #id, #type, #uri

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#method_missing, #respond_to?

Constructor Details

#initialize(options = {}) ⇒ Playlist

Returns a new instance of Playlist.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rspotify/playlist.rb', line 34

def initialize(options = {})
  @collaborative = options['collaborative']
  @description   = options['description']
  @followers     = options['followers']
  @images        = options['images']
  @name          = options['name']
  @public        = options['public']

  @owner = if options['owner']
    User.new options['owner']
  end

  @tracks = if options['tracks'] && options['tracks']['items']
    options['tracks']['items'].map { |t| Track.new t['track'] }
  end

  super(options)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RSpotify::Base

Instance Attribute Details

#collaborativeBoolean

true if the owner allows other users to modify the playlist

Returns:

  • (Boolean)

    the current value of collaborative



11
12
13
# File 'lib/rspotify/playlist.rb', line 11

def collaborative
  @collaborative
end

#descriptionString

The playlist description

Returns:

  • (String)

    the current value of description



11
12
13
# File 'lib/rspotify/playlist.rb', line 11

def description
  @description
end

#followersHash

Information about the followers of the playlist

Returns:

  • (Hash)

    the current value of followers



11
12
13
# File 'lib/rspotify/playlist.rb', line 11

def followers
  @followers
end

#imagesArray<Hash>

The playlist images

Returns:

  • (Array<Hash>)

    the current value of images



11
12
13
# File 'lib/rspotify/playlist.rb', line 11

def images
  @images
end

#nameString

The name of the playlist

Returns:

  • (String)

    the current value of name



11
12
13
# File 'lib/rspotify/playlist.rb', line 11

def name
  @name
end

#ownerUser

The user who owns the playlist

Returns:

  • (User)

    the current value of owner



11
12
13
# File 'lib/rspotify/playlist.rb', line 11

def owner
  @owner
end

#publicBoolean

true if the playlist is not marked as secret

Returns:

  • (Boolean)

    the current value of public



11
12
13
# File 'lib/rspotify/playlist.rb', line 11

def public
  @public
end

#tracksArray<Track>

The tracks of the playlist

Returns:

  • (Array<Track>)

    the current value of tracks



11
12
13
# File 'lib/rspotify/playlist.rb', line 11

def tracks
  @tracks
end

Class Method Details

.find(user_id, id) ⇒ Playlist

Returns Playlist object with user_id and id provided

Examples:

playlist = RSpotify::Playlist.find('wizzler', '00wHcTN0zQiun4xri9pmvX')
playlist.class #=> RSpotify::Playlist
playlist.name  #=> "Movie Soundtrack Masterpieces"

Parameters:

  • user_id (String)
  • id (String)

Returns:



23
24
25
26
# File 'lib/rspotify/playlist.rb', line 23

def self.find(user_id, id)
  json = RSpotify.auth_get("users/#{user_id}/playlists/#{id}")
  Playlist.new json
end

.searchObject

Spotify does not support search for playlists. Prints warning and returns false



29
30
31
32
# File 'lib/rspotify/playlist.rb', line 29

def self.search(*)
  warn 'Spotify API does not support search for playlists'
  false
end

Instance Method Details

#complete!Object

Note:

It is seldom necessary to use this method explicitly, since RSpotify takes care of it automatically when needed (see Base#method_missing)

When an object is obtained undirectly, Spotify usually returns a simplified version of it. This method updates it into a full object, with all attributes filled.

Examples:

playlist = user.playlists.first
playlist.instance_variable_get("@description") #=> nil
playlist.complete!
playlist.instance_variable_get("@description") #=> "Iconic soundtracks..."


63
64
65
# File 'lib/rspotify/playlist.rb', line 63

def complete!
  initialize RSpotify.auth_get("users/#{@owner.id}/playlists/#{@id}")
end