Module: Indix::Resource

Included in:
Brands, Categories, Offers, Prices, Products, Stores
Defined in:
lib/indix/resource.rb

Instance Method Summary collapse

Instance Method Details

#base_uriObject



8
9
10
# File 'lib/indix/resource.rb', line 8

def base_uri
  @base_uri ||= 'https://api.indix.com/v1'
end

#clientObject



12
13
14
# File 'lib/indix/resource.rb', line 12

def client
  @client ||= HTTPClient.new
end

#get(path, params = {}) ⇒ Object



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

  # no need to escape params as httpclient does it anyways
  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