lib/firstfm/venue.rb in firstfm-0.7.0 vs lib/firstfm/venue.rb in firstfm-0.8.0

- old
+ new

@@ -1,42 +1,42 @@ module Firstfm - + class Venue - + attr_accessor :id, :name, :url, :location, :website, :phonenumber, :images - + include HTTParty base_uri 'ws.audioscrobbler.com' - format :xml - + format :json + def self.search(venue, page = 1, limit = 50, country = nil) - response = get("/2.0/", {:query => {:method => 'venue.search', :venue => venue, :page => page, :limit => limit, :country => country, :api_key => Firstfm.config.api_key}}) - venues = response && response['lfm'] ? Venue.init_venues_from_hash(response['lfm']) : [] + response = get("/2.0/", {:query => {:method => 'venue.search', :venue => venue, :page => page, :limit => limit, :country => country, :api_key => Firstfm.config.api_key, :format => :json}}) + venues = response['results'] && response['results']['venuematches'] && response['results']['venuematches']['venue'] ? Venue.init_venues_from_hash(response) : [] collection = WillPaginate::Collection.create(page, limit) do |pager| pager.replace venues - pager.total_entries = response['lfm']['results']['totalResults'].to_i + pager.total_entries = response['results']['opensearch:totalResults'].to_i end end - + def self.get_events(venue_id) - response = get("/2.0/", {:query => {:method => 'venue.getEvents', :venue => venue_id, :api_key => Firstfm.config.api_key}}) - events = response && response['lfm'] ? Event.init_events_from_hash(response['lfm']) : [] + response = get("/2.0/", {:query => {:method => 'venue.getEvents', :venue => venue_id, :api_key => Firstfm.config.api_key, :format => :json}}) + events = response['events'] && response['events']['event'] ? Event.init_events_from_hash(response) : [] end - + def get_events self.class.get_events(self.id) end - + def self.init_venues_from_hash(hash) return [] unless hash["results"] && hash["results"]["venuematches"] && hash["results"]["venuematches"]["venue"] return [init_venue_from_hash(hash["results"]["venuematches"]["venue"])] if hash["results"]["venuematches"]["venue"].is_a?(Hash) hash["results"]["venuematches"]["venue"].inject([]) do |arr, venue_hash| arr << init_venue_from_hash(venue_hash) arr end end - + def self.init_venue_from_hash(hash) venue = Venue.new venue.id = hash["id"] venue.name = hash["name"] venue.url = hash["url"] @@ -44,9 +44,9 @@ venue.website = hash["website"] venue.phonenumber = hash["phonenumber"] venue.images = hash["image"] venue end - + end - + end \ No newline at end of file