16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/indix/resource.rb', line 16
def get(path, params = {})
params[:app_id] = Indix::Config.app_id
params[:app_key] = Indix::Config.app_key
target = base_uri + path
client.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
response = client.get(target, :query => params)
if response.status == 200
content = JSON.parse(response.content)
data = content["response"]
data = to_hashie(data)
elsif response.status == 401
raise AuthenticationError.new('Cannot complete request. Authentication failed. Please provide a valid app_id and app_key')
elsif response.status == 402
raise UnauthorizedAccessError.new('Cannot complete request. Not authorized to access this resource')
elsif response.status == 429
raise LimitExceededError.new('Too many requests')
else
raise StandardError.new('Cannot complete request. Response Code: ' + response.status.to_s + ' Response Body: ' + response.content)
end
end
|