Class: Rdio::Playlist

Inherits:
PlaylistData show all
Defined in:
lib/rdio/types.rb

Overview


Represents a playlist on Rdio


Instance Attribute Summary collapse

Attributes inherited from PlaylistData

#base_icon, #embed_url, #icon, #last_updated, #length, #name, #owner, #owner_icon, #owner_key, #owner_url, #short_url, #type, #url

Attributes inherited from BaseObj

#key

Attributes inherited from ApiObj

#api

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseObj

#eql?, #to_k

Methods inherited from ApiObj

#fill

Constructor Details

#initialize(api) ⇒ Playlist

Returns a new instance of Playlist.



326
327
328
# File 'lib/rdio/types.rb', line 326

def initialize(api)
  super api
end

Instance Attribute Details

#big_iconObject

big icon



331
332
333
# File 'lib/rdio/types.rb', line 331

def big_icon
  @big_icon
end

#track_keysObject

track keys



334
335
336
# File 'lib/rdio/types.rb', line 334

def track_keys
  @track_keys
end

Class Method Details

.all(keys, extras = nil) ⇒ Object

Fetch one or more objects from Rdio of type Playlist.



372
373
374
# File 'lib/rdio/types.rb', line 372

def self.all(keys,extras=nil)
  Rdio::api.get keys,Playlist,extras
end

.create(name, description, tracks, extras = nil) ⇒ Object

Create a new playlist in the current user’s collection. The new playlist will be returned if the creation is successful, otherwise null will be returned.



362
363
364
# File 'lib/rdio/types.rb', line 362

def self.create(name,description,tracks,extras=nil)
  Rdio::api.createPlaylist name,description,tracks,extras
end

.from_short_code(short_code) ⇒ Object

Return the Playlist that the supplied Rdio short-code is a representation of, or null if the short-code is invalid.



384
385
386
# File 'lib/rdio/types.rb', line 384

def self.from_short_code(short_code)
  Rdio::api.getObjectFromShortCode short_code,Playlist
end

.from_url(url) ⇒ Object

Return the Playlist that the supplied Rdio url is a representation of, or null if the url doesn’t represent an object.



390
391
392
# File 'lib/rdio/types.rb', line 390

def self.from_url(url)
  Rdio::api.getObjectFromUrl url,Playlist
end

.get(key, extras = nil) ⇒ Object

Fetch one object from Rdio of type Playlist.



377
378
379
380
# File 'lib/rdio/types.rb', line 377

def self.get(key,extras=nil)
  arr = all [key],extras
  return (arr and not arr.empty?) ? arr[0] : nil
end

.search(query, never_or = nil, extras = nil, start = nil, count = nil) ⇒ Object

Returns an array of Playlist for the query and other params



349
350
351
352
# File 'lib/rdio/types.rb', line 349

def self.search(query,never_or=nil,extras=nil,start=nil,count=nil)
  extras = Rdio::add_to_array extras,'playlists'
  Search.search query,Playlist,never_or,extras,start,count
end

.top_chartsObject

Return the site-wide most popular items for Playlists



395
396
397
# File 'lib/rdio/types.rb', line 395

def self.top_charts
  Rdio::api.getTopCharts Playlist
end

Instance Method Details

#add_to_playlist(tracks) ⇒ Object

Add a track to a playlist.



355
356
357
# File 'lib/rdio/types.rb', line 355

def add_to_playlist(tracks)
  api.addToPlaylist self,tracks
end

#collaborating=(collaborating) ⇒ Object

Start or stop collaborating on this playlist.



400
401
402
# File 'lib/rdio/types.rb', line 400

def collaborating=(collaborating)
  Rdio::api.setPlaylistCollaborating self,collaborating
end

#collaboration_mode=(mode) ⇒ Object

Start or stop collaborating on this playlist.



405
406
407
# File 'lib/rdio/types.rb', line 405

def collaboration_mode=(mode)
  Rdio::api.setPlaylistCollaborationMode self,mode
end

#deleteObject

Delete a playlist.



367
368
369
# File 'lib/rdio/types.rb', line 367

def delete
  api.deletePlaylist self
end

#order=(tracks) ⇒ Object

Saves the given order of tracks in a given playlist. The new order must have the same tracks as the previous order (this method may not be used to add/remove tracks).



412
413
414
# File 'lib/rdio/types.rb', line 412

def order=(tracks)
  Rdio::api.setPlaylistOrder self,tracks
end

#remove(index, count, tracks) ⇒ Object

Remove an item from a playlist by its position in the playlist.



337
338
339
# File 'lib/rdio/types.rb', line 337

def remove(index,count,tracks)
  api.removeFromPlaylist self,index,count,tracks
end

#set_fields(name, description) ⇒ Object

Sets the name and description for a playlist.



417
418
419
# File 'lib/rdio/types.rb', line 417

def set_fields(name,description)
  Rdio::api.setPlaylistFields self,name,description
end

#tracksObject

Returns an array of tracks



342
343
344
345
346
# File 'lib/rdio/types.rb', line 342

def tracks
  ids = track_keys
  return [] if not ids
  return ids.map {|id| Track.get id}
end