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

- old
+ new

@@ -1,19 +1,19 @@ $:.unshift File.dirname(__FILE__) require 'httparty' module MetaSpotify - + API_VERSION = '1' - + class Base include HTTParty base_uri 'http://ws.spotify.com' - + attr_reader :name, :uri, :popularity - + 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) @@ -29,20 +29,20 @@ items << self.new(result[item_name]) end end return { (item_name+'s').to_sym => items, :query => { - :start_page => result["opensearch:Query"]["startPage"].to_i, - :role => result["opensearch:Query"]["role"], - :search_terms => result["opensearch:Query"]["searchTerms"] + :start_page => result["Query"]["startPage"].to_i, + :role => result["Query"]["role"], + :search_terms => result["Query"]["searchTerms"] }, - :items_per_page => result["opensearch:itemsPerPage"].to_i, - :start_index => result["opensearch:startIndex"].to_i, - :total_results => result["opensearch:totalResults"].to_i + :items_per_page => result["itemsPerPage"].to_i, + :start_index => result["startIndex"].to_i, + :total_results => result["totalResults"].to_i } 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) query = {:uri => uri} query[:extras] = opts[:extras] if opts.has_key? :extras @@ -53,18 +53,18 @@ case k when "artist" return Artist.new(v) when "album" return Album.new(v) - when "track" + when "track" return Track.new(v) end end end - + private - + def self.raise_errors(response) case response.code when 400 raise BadRequestError.new('400 - The request was not understood') when 403 @@ -77,16 +77,16 @@ raise ServerError.new('500 - The server encountered an unexpected problem') when 503 raise ServerError.new('503 - The API is temporarily unavailable') end end - + end - + class MetaSpotifyError < StandardError attr_reader :data - + def initialize(data) @data = data super end end @@ -97,6 +97,7 @@ class ServerError < MetaSpotifyError; end end require 'meta-spotify/artist' require 'meta-spotify/track' -require 'meta-spotify/album' \ No newline at end of file +require 'meta-spotify/album' +require 'meta-spotify/version'