summaryrefslogtreecommitdiff
path: root/data/rbot/plugins
diff options
context:
space:
mode:
authorRaine Virta <rane@kapsi.fi>2009-02-25 01:56:05 +0200
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2009-02-26 00:39:48 +0100
commit1f189174e58ae460ea359df6c2e2a4692addbc33 (patch)
tree1dc8c538a7c95904ea2a580c7fc0cff8277c3d7e /data/rbot/plugins
parent5bcdd4c8279b35d78ed80883a77b7e459228b92d (diff)
lastfm: add method for searching venues
Diffstat (limited to 'data/rbot/plugins')
-rw-r--r--data/rbot/plugins/lastfm.rb35
1 files changed, 35 insertions, 0 deletions
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'])