Class: Grooveshark::Playlist
- Inherits:
-
Object
- Object
- Grooveshark::Playlist
- Defined in:
- lib/grooveshark/playlist.rb
Instance Attribute Summary collapse
-
#about ⇒ Object
readonly
Returns the value of attribute about.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#picture ⇒ Object
readonly
Returns the value of attribute picture.
-
#songs ⇒ Object
readonly
Returns the value of attribute songs.
-
#user_id ⇒ Object
readonly
Returns the value of attribute user_id.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
-
#delete ⇒ Object
Delete existing playlist.
-
#initialize(client, data = nil, user_id = nil) ⇒ Playlist
constructor
A new instance of Playlist.
-
#load_songs ⇒ Object
Fetch playlist songs.
-
#rename(name, description) ⇒ Object
Rename playlist.
Constructor Details
#initialize(client, data = nil, user_id = nil) ⇒ Playlist
Returns a new instance of Playlist.
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/grooveshark/playlist.rb', line 7 def initialize(client, data=nil, user_id=nil) @client = client @songs = [] if data @id = data['playlist_id'] @name = data['name'] @about = data['about'] @picture = data['picture'] @user_id = data['user_id'] || user_id @username = data['user_name'] end end |
Instance Attribute Details
#about ⇒ Object (readonly)
Returns the value of attribute about.
4 5 6 |
# File 'lib/grooveshark/playlist.rb', line 4 def about @about end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/grooveshark/playlist.rb', line 3 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/grooveshark/playlist.rb', line 4 def name @name end |
#picture ⇒ Object (readonly)
Returns the value of attribute picture.
4 5 6 |
# File 'lib/grooveshark/playlist.rb', line 4 def picture @picture end |
#songs ⇒ Object (readonly)
Returns the value of attribute songs.
5 6 7 |
# File 'lib/grooveshark/playlist.rb', line 5 def songs @songs end |
#user_id ⇒ Object (readonly)
Returns the value of attribute user_id.
3 4 5 |
# File 'lib/grooveshark/playlist.rb', line 3 def user_id @user_id end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
4 5 6 |
# File 'lib/grooveshark/playlist.rb', line 4 def username @username end |
Instance Method Details
#delete ⇒ Object
Delete existing playlist
40 41 42 |
# File 'lib/grooveshark/playlist.rb', line 40 def delete @client.request('deletePlaylist', {:playlistID => @id, :name => @name}) end |
#load_songs ⇒ Object
Fetch playlist songs
22 23 24 25 |
# File 'lib/grooveshark/playlist.rb', line 22 def load_songs @songs = @client.request('getPlaylistByID', :playlistID => @id)['songs'] @songs.map! { |s| Song.new(s) } end |
#rename(name, description) ⇒ Object
Rename playlist
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/grooveshark/playlist.rb', line 28 def rename(name, description) begin @client.request('renamePlaylist', :playlistID => @id, :playlistName => name) @client.request('setPlaylistAbout', :playlistID => @id, :about => description) @name = name ; @about = description return true rescue return false end end |