Class: Grooveshark::Playlist

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#aboutObject (readonly)

Returns the value of attribute about.



4
5
6
# File 'lib/grooveshark/playlist.rb', line 4

def about
  @about
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/grooveshark/playlist.rb', line 3

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/grooveshark/playlist.rb', line 4

def name
  @name
end

#pictureObject (readonly)

Returns the value of attribute picture.



4
5
6
# File 'lib/grooveshark/playlist.rb', line 4

def picture
  @picture
end

#songsObject (readonly)

Returns the value of attribute songs.



5
6
7
# File 'lib/grooveshark/playlist.rb', line 5

def songs
  @songs
end

#user_idObject (readonly)

Returns the value of attribute user_id.



3
4
5
# File 'lib/grooveshark/playlist.rb', line 3

def user_id
  @user_id
end

#usernameObject (readonly)

Returns the value of attribute username.



4
5
6
# File 'lib/grooveshark/playlist.rb', line 4

def username
  @username
end

Instance Method Details

#deleteObject

Delete existing playlist



40
41
42
# File 'lib/grooveshark/playlist.rb', line 40

def delete
  @client.request('deletePlaylist', {:playlistID => @id, :name => @name})
end

#load_songsObject

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