-module Spotify
- def self.get(service, method, query, page=1)
- url = URI.escape("http://ws.spotify.com/#{service}/1/#{method}?q=#{query}&page=#{page}")
- xml = Irc::Utils.bot.httputil.get_response(url).body
- return REXML::Document.new(xml).root
- end
-
- # returns a Spotify URL, e.g. 'http://open.spotify.com/track/3y6EhoUO3A8bPr3zt3Tm9b'
- def self.search(method, query, page=1)
- doc = get(:search, method, query, page)
- return nil if doc.elements["opensearch:totalResults"].text.to_i.zero?
- uri = doc.elements[method.to_s].attributes["href"]
- id = uri[uri.rindex(':')+1..-1]
- return URI.escape("http://open.spotify.com/#{method}/#{id}")
- end
-end
-