class Idnow::Client

Constants

API_VERSION

Attributes

host[R]

Public Class Methods

new(env:, company_id:, api_key:, timeout: nil, sftp_options: {}) click to toggle source
# File lib/idnow/client.rb, line 25
def initialize(env:, company_id:, api_key:, timeout: nil, sftp_options: {})
  raise 'Please set env to :test or :live' unless Idnow::ENVIRONMENTS.keys.include?(env)
  raise 'Please set your company_id' if company_id.nil?
  raise 'Please set your api_key' if api_key.nil?

  @host        = Idnow.endpoint(env, :host)
  @target_host = Idnow.endpoint(env, :target_host)
  @company_id  = company_id
  @api_key     = api_key

  @http_client = HttpClient.new(host: @host)

  sftp_options[:timeout] = timeout if timeout
  @sftp_client = SftpClient.new(host: @host, username: @company_id, password: @api_key, options: sftp_options)
end

Private Instance Methods

automated_testing_http_client() click to toggle source
# File lib/idnow/client.rb, line 61
def automated_testing_http_client
  @automated_testing_http_client ||= HttpClient.new(host: Idnow::API::AutomatedTesting::HOST)
end
execute(request, headers = {}, http_client: @http_client) click to toggle source
# File lib/idnow/client.rb, line 43
def execute(request, headers = {}, http_client: @http_client)
  http_response = http_client.execute(request, headers)

  response = if request.content_type == 'application/json'
               Idnow::JsonResponse.new(http_response.body)
             else
               Idnow::RawResponse.new(http_response.body)
             end

  response.tap do |r|
    raise Idnow::ResponseException, r.errors if r.errors?
  end
end
full_path_for(partial_path) click to toggle source
# File lib/idnow/client.rb, line 57
def full_path_for(partial_path)
  File.join('/api', API_VERSION, @company_id, partial_path)
end