From 1f189174e58ae460ea359df6c2e2a4692addbc33 Mon Sep 17 00:00:00 2001 From: Raine Virta Date: Wed, 25 Feb 2009 01:56:05 +0200 Subject: lastfm: add method for searching venues --- data/rbot/plugins/lastfm.rb | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'data/rbot/plugins/lastfm.rb') diff --git a/data/rbot/plugins/lastfm.rb b/data/rbot/plugins/lastfm.rb index a5f526f1..d1115ed8 100644 --- a/data/rbot/plugins/lastfm.rb +++ b/data/rbot/plugins/lastfm.rb @@ -47,6 +47,8 @@ class ::LastFmEvent end +define_structure :LastFmVenue, :id, :city, :street, :postal, :country, :name, :url, :lat, :long + class LastFmPlugin < Plugin include REXML Config.register Config::IntegerValue.new('lastfm.max_events', @@ -129,6 +131,39 @@ class LastFmPlugin < Plugin end end + # TODO allow searching by country etc. + # + # Options: name, limit + def search_venue_by(options) + params = {} + params[:venue] = CGI.escape(options[:name]) + options.delete(:name) + params.merge!(options) + + uri = "#{APIURL}method=venue.search&" + uri << params.to_a.map {|e| e.join("=")}.join("&") + + xml = @bot.httputil.get_response(uri) + doc = Document.new xml.body + results = [] + + doc.root.elements.each("results/venuematches/venue") do |v| + venue = LastFmVenue.new + venue.id = v.elements["id"].text.to_i + venue.url = v.elements["url"].text + venue.lat = v.elements["location/geo:point/geo:lat"].text.to_f + venue.long = v.elements["location/geo:point/geo:long"].text.to_f + venue.name = v.elements["name"].text + venue.city = v.elements["location/city"].text + venue.street = v.elements["location/street"].text + venue.postal = v.elements["location/postalcode"].text + venue.country = v.elements["location/country"].text + + results << venue + end + results + end + def find_events(m, params) num = params[:num] || @bot.config['lastfm.default_events'] num = num.to_i.clip(1, @bot.config['lastfm.max_events']) -- cgit v1.2.3