class Grooveshark::User

User class

Attributes

city[R]
country[R]
data[R]
email[R]
favorites[R]
id[R]
name[R]
playlists[R]
premium[R]
sex[R]

Public Class Methods

new(client, data = nil) click to toggle source

Init user account object

# File lib/grooveshark/user.rb, line 10
def initialize(client, data = nil)
  if data
    @data     = data
    @id       = data['user_id']
    @name     = data['f_name']
    @premium  = data['is_premium']
    @email    = data['email']
    @city     = data['city']
    @country  = data['country']
    @sex      = data['sex']
  end
  @client     = client
end

Public Instance Methods

add_favorite(song) click to toggle source

Add song to favorites

# File lib/grooveshark/user.rb, line 116
def add_favorite(song)
  song_id = song.is_a?(Song) ? song.id : song
  @client.request('favorite', what: 'Song', ID: song_id)
end
avatar() click to toggle source

Get user avatar URL

# File lib/grooveshark/user.rb, line 25
def avatar
  "http://images.grooveshark.com/static/userimages/#{@id}.jpg"
end
create_playlist(name, description = '', songs = []) click to toggle source

Create new user playlist

# File lib/grooveshark/user.rb, line 95
def create_playlist(name, description = '', songs = [])
  @client.request('createPlaylist',
                  'playlistName' => name,
                  'playlistAbout' => description,
                  'songIDs' => songs.map do |s|
                    s.is_a?(Song) ? s.id : s.to_s
                  end)
end
feed(date = nil) click to toggle source

Get user activity for the date (COMES AS RAW RESPONSE)

# File lib/grooveshark/user.rb, line 30
def feed(date = nil)
  date = Time.now if date.nil?
  @client.request('getProcessedUserFeedData',
                  userID: @id,
                  day: date.strftime('%Y%m%d'))
end
get_playlist(id) click to toggle source

Get playlist by ID

# File lib/grooveshark/user.rb, line 87
def get_playlist(id)
  result = playlists.select { |p| p.id == id }
  result.nil? ? nil : result.first
end
Also aliased as: playlist
library(page = 0) click to toggle source

Fetch songs from library

# File lib/grooveshark/user.rb, line 42
def library(page = 0)
  songs = []
  resp = @client.request('userGetSongsInLibrary',
                         userID: @id,
                         page: page.to_s)
  songs = resp['songs'].map do |song|
    Song.new song
  end if resp.key?('songs')
  songs
end
library_add(songs = []) click to toggle source

Add songs to user’s library

# File lib/grooveshark/user.rb, line 54
def library_add(songs = [])
  @client.request('userAddSongsToLibrary', songs: songs.map(&:to_hash))
end
library_remove(song) click to toggle source

Remove song from user library

# File lib/grooveshark/user.rb, line 59
def library_remove(song)
  fail ArgumentError, 'Song object required' unless song.is_a?(Song)
  req = { userID: @id,
          songID: song.id,
          albumID: song.album_id,
          artistID: song.artist_id }
  @client.request('userRemoveSongFromLibrary', req)
end
library_ts_modified() click to toggle source

Get library modification time

# File lib/grooveshark/user.rb, line 69
def library_ts_modified
  @client.request('userGetLibraryTSModified', userID: @id)
end
playlist(id)
Alias for: get_playlist
remove_favorite(song) click to toggle source

Remove song from favorites

# File lib/grooveshark/user.rb, line 122
def remove_favorite(song)
  song_id = song.is_a?(Song) ? song.id : song
  @client.request('unfavorite', what: 'Song', ID: song_id)
end