Class: Grooveshark::Playlist
- Inherits:
-
Object
- Object
- Grooveshark::Playlist
- Defined in:
- lib/grooveshark/playlist.rb
Overview
Playlist class
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.
-
#num_songs ⇒ Object
readonly
Returns the value of attribute num_songs.
-
#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.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/grooveshark/playlist.rb', line 9 def initialize(client, data = nil, user_id = nil) @client = client @songs = [] return if data.nil? @id = data['playlist_id'] @name = data['name'] @about = data['about'] @picture = data['picture'] @user_id = data['user_id'] || user_id @username = data['f_name'] @num_songs = data['num_songs'].to_i end |
Instance Attribute Details
#about ⇒ Object (readonly)
Returns the value of attribute about.
6 7 8 |
# File 'lib/grooveshark/playlist.rb', line 6 def about @about end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/grooveshark/playlist.rb', line 5 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/grooveshark/playlist.rb', line 6 def name @name end |
#num_songs ⇒ Object (readonly)
Returns the value of attribute num_songs.
7 8 9 |
# File 'lib/grooveshark/playlist.rb', line 7 def num_songs @num_songs end |
#picture ⇒ Object (readonly)
Returns the value of attribute picture.
6 7 8 |
# File 'lib/grooveshark/playlist.rb', line 6 def picture @picture end |
#songs ⇒ Object (readonly)
Returns the value of attribute songs.
7 8 9 |
# File 'lib/grooveshark/playlist.rb', line 7 def songs @songs end |
#user_id ⇒ Object (readonly)
Returns the value of attribute user_id.
5 6 7 |
# File 'lib/grooveshark/playlist.rb', line 5 def user_id @user_id end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
6 7 8 |
# File 'lib/grooveshark/playlist.rb', line 6 def username @username end |
Instance Method Details
#delete ⇒ Object
Delete existing playlist
45 46 47 |
# File 'lib/grooveshark/playlist.rb', line 45 def delete @client.request('deletePlaylist', playlistID: @id, name: @name) end |
#load_songs ⇒ Object
Fetch playlist songs
24 25 26 27 28 29 30 31 |
# File 'lib/grooveshark/playlist.rb', line 24 def load_songs @songs = [] playlist = @client.request('getPlaylistByID', playlistID: @id) @songs = playlist['songs'].map! do |s| Song.new(s) end if playlist.key?('songs') @songs end |
#rename(name, description) ⇒ Object
Rename playlist
34 35 36 37 38 39 40 41 42 |
# File 'lib/grooveshark/playlist.rb', line 34 def rename(name, description) @client.request('renamePlaylist', playlistID: @id, playlistName: name) @client.request('setPlaylistAbout', playlistID: @id, about: description) @name = name @about = description true rescue false end |