14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/skiddle/client.rb', line 14
def self.make_request(klass, endpoint, params = {})
query_url = convert_query_to_url(params)
result = get("#{endpoint}?api_key=#{ENV['SKIDDLE_API_KEY']}#{query_url}")
parsed_result = JSON.parse(result.body)
if parsed_result["error"] == 1
parsed_result
else
if parsed_result["results"].class == Array
objects = parsed_result["results"].map do |result|
klass.new(result)
end
objects.length == 1 ? objects.first : objects
else
klass.new(result)
end
end
end
|