5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/idiomag/rest.rb', line 5
def self.fetch(resource, query={}, parse=true)
raise ArgumentError, 'api key missing' if Base.api_key.blank?
options = {:query => {:key => Base.api_key}}
options[:query].merge!(query)
options[:format] = :json if parse
begin
data = HTTParty.get(API_URL + resource + "/json", options)
rescue Net::HTTPServerException => e
raise ArgumentError, 'invalid user, artist or tag' if e.message =~ /400/
end
raise InvalidResult if data.blank?
data
end
|