Class: Firstfm::Geo

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

Class Method Summary collapse

Class Method Details

.get_events(params = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/firstfm/geo.rb', line 9

def self.get_events(params = {})
  location = params.delete(:location)
  lat = params.delete(:lat)
  lng = params.delete(:lng)
  page = params.delete(:page) || 1
  distance = params.delete(:distance)
  
  response = get("/2.0/", {:query => {:method => 'geo.getevents', :location => location, :page => page, :lat => lat, :lng => lng, :distance => distance, :api_key => Firstfm.config.api_key}})
  events = response && response['lfm'] ? Event.init_events_from_hash(response['lfm']) : []
  
  collection = WillPaginate::Collection.create(page, 10) do |pager|
    pager.replace events
    pager.total_entries = response['lfm']['events']['total'].to_i
  end
  
end

.get_generic_artist_chart(method, params = {}) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/firstfm/geo.rb', line 59

def self.get_generic_artist_chart(method, params = {})
  metro = params[:metro]
  country = params[:country]
  start_timestamp = params[:start]
  end_timestamp = params[:end]
  page = params[:page] || 1
  limit = params[:limit] || 50
  
  response = get("/2.0/", {:query => {
    :method => method, 
    :country => country,
    :metro => metro,
    :start => start_timestamp,
    :end => end_timestamp,
    :page => page, 
    :limit => limit, 
    :api_key => Firstfm.config.api_key }.reject {|k,v| v.nil?}
  })
  
  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

.get_metro_artist_chart(params = {}) ⇒ Object



47
48
49
# File 'lib/firstfm/geo.rb', line 47

def self.get_metro_artist_chart(params = {})
  get_generic_artist_chart 'geo.getmetroartistchart', params
end

.get_metro_hype_artist_chart(params = {}) ⇒ Object



51
52
53
# File 'lib/firstfm/geo.rb', line 51

def self.get_metro_hype_artist_chart(params = {})
  get_generic_artist_chart 'geo.getmetrohypeartistchart', params
end

.get_metro_unique_artist_chart(params = {}) ⇒ Object



55
56
57
# File 'lib/firstfm/geo.rb', line 55

def self.get_metro_unique_artist_chart(params = {})
  get_generic_artist_chart 'geo.getmetrouniqueartistchart', params
end

.get_top_artists(params = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/firstfm/geo.rb', line 26

def self.get_top_artists(params = {})
  country = params[:country]
  page = params[:page] || 1
  limit = params[:limit] || 50
  
  response = get("/2.0/", {:query => {
    :method => 'geo.gettopartists', 
    :country => country,
    :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