lib/meta-spotify.rb in meta-spotify-0.2.0 vs lib/meta-spotify.rb in meta-spotify-0.3.0

- old
+ new

@@ -10,10 +10,14 @@ include HTTParty base_uri 'http://ws.spotify.com' attr_reader :name, :uri, :popularity + def self.uri_regex + nil + end + def self.search(string, opts={}) item_name = self.name.downcase.gsub(/^.*::/,'') query = {:q => string} query[:page] = opts[:page].to_s if opts.has_key? :page result = get("/search/#{API_VERSION}/#{item_name}", :query => query, :format => :xml) @@ -41,11 +45,11 @@ } end def self.lookup(uri, opts={}) uri = uri.strip - raise URIError.new("Spotify URI not in the correct syntax") unless self::URI_REGEX.match(uri) + raise URIError.new("Spotify URI not in the correct syntax") unless uri_regex.match(uri) query = {:uri => uri} query[:extras] = opts[:extras] if opts.has_key? :extras result = get("/lookup/#{API_VERSION}/",:query => query, :format => :xml) raise_errors(result) result.each do |k,v| @@ -56,9 +60,17 @@ when "album" return Album.new(v) when "track" return Track.new(v) end + end + end + + def spotify_id + if uri + uri[self.class.uri_regex, 1] + else + nil end end private