16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/beatport/client.rb', line 16
def self.retrieve(path, klass, *args)
uri = Addressable::URI.new(
:scheme => 'https',
:host => 'api.beatport.com',
:path => "/catalog/3/#{path}",
:query_values => builder.process(*args)
)
result = client.fetch_protected_resource(:uri => uri.to_s)
result = JSON.parse(result.body)
result = Support::Inflector.process_keys(result) { |k| Support::Inflector.underscore(k) }
if result['metadata']['error']
raise Error.new("#{result['metadata']['error']}: #{result['metadata']['message']}")
end
case result['results']
when Array
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 Error.new("results is an unexpected class #{result['results'].class}")
end
end
|