class Xhash::OCR
Constants
- IDENTIFICATION_TYPES
Public Class Methods
generic(document_url: nil, document_file: nil)
click to toggle source
# File lib/xhash/ocr.rb, line 5 def self.generic(document_url: nil, document_file: nil) url = 'ocr' if document_url.nil? and document_file.nil? raise Xhash::MissingRequiredFieldError.new( { message: Xhash::ErrorMessage::MISSING_FILE } ) end payload = request_by_file_or_url( url: url, document_url: document_url, document_file: document_file ) is_identification = IDENTIFICATION_TYPES.include? payload[:type] document = if is_identification Xhash::Identification.new( *payload.values_at(*Xhash::Identification.members) ) else Xhash::ProofOfAddress.new( *payload.values_at(*Xhash::ProofOfAddress.members) ) end document end
identification(document_url: nil, document_file: nil)
click to toggle source
# File lib/xhash/ocr.rb, line 35 def self.identification(document_url: nil, document_file: nil) url = 'ocr/identification' if document_url.nil? and document_file.nil? raise Xhash::MissingRequiredFieldError.new( { message: Xhash::ErrorMessage::MISSING_FILE } ) end payload = request_by_file_or_url( url: url, document_url: document_url, document_file: document_file ) Xhash::Identification.new( *payload.values_at(*Xhash::Identification.members) ) end
ine_reverse(document_url: nil, document_file: nil)
click to toggle source
# File lib/xhash/ocr.rb, line 73 def self.ine_reverse(document_url: nil, document_file: nil) url = 'ocr/ine-reverse' if document_url.nil? and document_file.nil? raise Xhash::MissingRequiredFieldError.new( { message: Xhash::ErrorMessage::MISSING_FILE } ) end payload = request_by_file_or_url( url: url, document_url: document_url, document_file: document_file ) Xhash::Identification.new( *payload.values_at(*Xhash::Identification.members) ) end
proof_of_address(document_url: nil, document_file: nil)
click to toggle source
# File lib/xhash/ocr.rb, line 54 def self.proof_of_address(document_url: nil, document_file: nil) url = 'ocr/proof-of-address' if document_url.nil? and document_file.nil? raise Xhash::MissingRequiredFieldError.new( { message: Xhash::ErrorMessage::MISSING_FILE } ) end payload = request_by_file_or_url( url: url, document_url: document_url, document_file: document_file ) Xhash::ProofOfAddress.new( *payload.values_at(*Xhash::ProofOfAddress.members) ) end
Private Class Methods
request_by_file_or_url( url: nil, document_url: nil, document_file: nil )
click to toggle source
# File lib/xhash/ocr.rb, line 94 def self.request_by_file_or_url( url: nil, document_url: nil, document_file: nil ) body = { 'document_url' => document_url, 'document_file' => document_file }.compact response = if document_file.nil? api_post( url: url, body: body, headers: { 'boundary' => '---011000010111000001101001' } ) else data = api_post_multipart(url: url, body: body) JSON.parse(data, symbolize_names: true) end payload = response[:payload] if payload.nil? raise Xhash::InvalidFieldError.new( { message: Xhash::ErrorMessage::INVALID_FILE } ) end payload end