Class: CPFHub::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/cpfhub/client.rb

Constant Summary collapse

BASE_URL =
'https://api.cpfhub.io/v1'

Instance Method Summary collapse

Constructor Details

#initialize(api_key:) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
14
15
16
17
18
# File 'lib/cpfhub/client.rb', line 9

def initialize(api_key:)
  @api_key = api_key
  @connection = Faraday.new(url: BASE_URL) do |f|
    f.request :retry, max: 3, interval: 0.5
    f.headers['Authorization'] = "Bearer #{@api_key}"
    f.headers['Content-Type'] = 'application/json'
    f.headers['User-Agent'] = "CPFHub-Ruby-SDK/#{CPFHub::VERSION}"
    f.adapter Faraday.default_adapter
  end
end

Instance Method Details

#lookup(cpf) ⇒ Object



20
21
22
23
24
25
# File 'lib/cpfhub/client.rb', line 20

def lookup(cpf)
  clean_cpf = cpf.to_s.gsub(/\D/, '')
  response = @connection.get("cpf/#{clean_cpf}")
  
  handle_response(response)
end