Class: BriteVerifyApi::Clients::Base

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/brite_verify_api/clients/base.rb

Direct Known Subclasses

Email

Constant Summary collapse

API_HOST =
"https://bpi.briteverify.com".freeze

Instance Method Summary collapse

Instance Method Details

#get(url, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/brite_verify_api/clients/base.rb', line 8

def get(url, options = {})
  options[:apikey] = BriteVerifyApi.configuration.api_key
  begin
    response = self.class.get(url, options)
    data = JSON.parse response.body, symbolize_names: true
    case response.code
    when 200
      return RecursiveOpenStruct.new(data)
    else
      raise BriteVerifyApi::Error, data[:errors][:user]
    end
  rescue Errno::ECONNREFUSED => e
    raise BriteVerifyApi::Error, e.message
  rescue HTTParty::Error => e
    raise BriteVerifyApi::Error, e.message
  rescue => e
    raise BriteVerifyApi::Error, e.message
  end
end