Module: Idnow::API::RetrieveIdentifications

Included in:
Client
Defined in:
lib/idnow/API/retrieve_identifications.rb

Constant Summary collapse

IDENTIFICATION_STATUSES =
%w[pending failed].freeze

Instance Method Summary collapse

Instance Method Details

#download_identification(transaction_number:) ⇒ Object



41
42
43
44
# File 'lib/idnow/API/retrieve_identifications.rb', line 41

def download_identification(transaction_number:)
  path = "#{transaction_number}.zip"
  @sftp_client.download(path)
end

#get_identification(transaction_number:) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/idnow/API/retrieve_identifications.rb', line 24

def get_identification(transaction_number:)
  raise Idnow::AuthenticationException if @auth_token.nil?

  path = full_path_for("identifications/#{transaction_number}")
  request = Idnow::GetRequest.new(path)
  response = execute(request, { 'X-API-LOGIN-TOKEN' => @auth_token })
  Idnow::Identification.new(response.data)
end

#get_identification_file(transaction_number:) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/idnow/API/retrieve_identifications.rb', line 33

def get_identification_file(transaction_number:)
  raise Idnow::AuthenticationException if @auth_token.nil?

  path = full_path_for("identifications/#{transaction_number}.zip")
  request = Idnow::GetRequest.new(path, '')
  execute(request, { 'X-API-LOGIN-TOKEN' => @auth_token })
end

#list_identifications(status: nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/idnow/API/retrieve_identifications.rb', line 8

def list_identifications(status: nil)
  raise Idnow::AuthenticationException if @auth_token.nil?

  unless status.nil? || IDENTIFICATION_STATUSES.include?(status)
    raise Idnow::InvalidArguments, "Status #{status} not defined, possible options are: #{IDENTIFICATION_STATUSES.join(',')}"
  end

  partial_path = status.nil? ? 'identifications' : "identifications?#{status}=true"
  path = full_path_for(partial_path)
  request = Idnow::GetRequest.new(path)
  response = execute(request, { 'X-API-LOGIN-TOKEN' => @auth_token })
  response.data['identifications'].map do |data|
    Idnow::Identification.new(data)
  end
end