Class: Soundcloud::Models::Playlist

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

Overview

Note: At the moment, you can’t create or delete playlists or change their permissions via Soundcloud API

SC API Attributes (as of 26/05/09):

  • created_at

  • description

  • genre

  • id

  • permalink

  • title

  • user_id

  • permalink_url

  • uri

  • artwork_url

  • duration

  • type

  • user (overwritten by wrapper)

  • tracks (array)

Custom Wrapper Attributes/Methods:

  • user

Look up the resource attributes and filtering usage here:

wiki.github.com/soundcloud/api/documentation#playlist

Examples:

# Find a Playlist and add a track to it
playlist = sc_client.Playlist.find('my-playlist')   
track = sc_client.Track.find('my-track')
playlist.tracks << track
playlist.save   

# Delete first song in playlist
playlist.tracks.delete playlist.tracks.first
playlist.save

Instance Method Summary collapse

Methods inherited from Base

can_be_a_single_changeable, has_many_single_changeable, #send_files

Constructor Details

#initialize(*args) ⇒ Playlist

Returns a new instance of Playlist.



48
49
50
51
52
# File 'lib/soundcloud/models/playlist.rb', line 48

def initialize(*args)
  super(*args)
  #create empty tracks array if not existing
  attributes['tracks'] = Array.new if not self.tracks?
end

Instance Method Details

#createObject



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/soundcloud/models/playlist.rb', line 62

def create
  if data_attributes.all? { |attr| self.attributes[attr].nil? }
    super
  else
   # default to private
   if self.sharing?.nil? 
     self.sharing = 'private'
   end
   send_files(:post,'/playlists', 'playlist')
  end
end

#updateObject



54
55
56
57
58
59
60
# File 'lib/soundcloud/models/playlist.rb', line 54

def update
  if data_attributes.all? { |attr| self.attributes[attr].nil? }
    super
  else
    send_files(:put,"/playlists/#{self.id}",'playlist')
  end
end