lib/beatport/client.rb in beatport-0.1.1 vs lib/beatport/client.rb in beatport-0.1.2
- old
+ new
@@ -1,18 +1,24 @@
module Beatport
module Client
include HTTParty
- parser Beatport::Parser
+ parser Beatport::Support::Parser
base_uri "http://api.beatport.com/catalog/3"
format :json
# default_params :v => '1.0', :format => 'json'
def self.retrieve(path, klass, *args)
- result = get("/#{path}", :query => QueryBuilder.process(*args))
+ builder = Support::QueryBuilder.new
+
+ result = get("/#{path}", :query => builder.process(*args))
case result['results']
when Array
- Collection.new(klass, result)
+ if builder.single_result?
+ klass.new(result['results'].first) if result['results'].any?
+ else
+ Collection.new(klass, result)
+ end
when Hash
klass.new(result['results'])
else
raise "results is an unexpected class #{result['results'].class}"
end
\ No newline at end of file