Class: Grooveshark::Playlist

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

Overview

Playlist class

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#aboutObject (readonly)

Returns the value of attribute about.



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

def about
  @about
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#num_songsObject (readonly)

Returns the value of attribute num_songs.



7
8
9
# File 'lib/grooveshark/playlist.rb', line 7

def num_songs
  @num_songs
end

#pictureObject (readonly)

Returns the value of attribute picture.



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

def picture
  @picture
end

#songsObject (readonly)

Returns the value of attribute songs.



7
8
9
# File 'lib/grooveshark/playlist.rb', line 7

def songs
  @songs
end

#user_idObject (readonly)

Returns the value of attribute user_id.



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

def user_id
  @user_id
end

#usernameObject (readonly)

Returns the value of attribute username.



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

def username
  @username
end

Instance Method Details

#deleteObject

Delete existing playlist



45
46
47
# File 'lib/grooveshark/playlist.rb', line 45

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

#load_songsObject

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