Class: Firstfm::User

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/firstfm/user.rb

Class Method Summary collapse

Class Method Details

.get_top_artists(user, period = "overall", page = 1, limit = 50) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/firstfm/user.rb', line 9

def self.get_top_artists(user, period = "overall", page = 1, limit = 50)
  response = get("/2.0/", {query: {method: 'user.getTopArtists', user: user, period: period, page: page, limit: limit, api_key: Firstfm.config.api_key}})
  artists_array = (response and response["lfm"] and response["lfm"]["topartists"] and response["lfm"]["topartists"]["artist"]) || []
  artists = Artist.init_from_array(artists_array)
  WillPaginate::Collection.create(page, limit) do |pager|
    pager.replace artists
    pager.total_entries = response['lfm']['topartists']['total'].to_i rescue 0
  end
end