Class: Xhash::DatabaseLookup

Inherits:
ApiClient show all
Defined in:
lib/xhash/database_lookup.rb

Class Method Summary collapse

Methods inherited from ApiClient

api_base, api_base=, api_key, api_key=, config, timeout, timeout=

Methods included from JsonApi

included

Class Method Details

.renapo(curp) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/xhash/database_lookup.rb', line 3

def self.renapo(curp)
  url = 'database-lookup/renapo'
  body = { curp: curp }
  response = api_post(url: url, body: body)
  payload = response[:payload]

  if payload.nil?
    raise Xhash::MissingRequiredFieldError.new(
            {
              message: Xhash::ErrorMessage::MISSING_CURP, response: response
            }
          )
  end

  if payload[:name] == 'CURP INVALIDO'
    raise Xhash::InvalidFieldError.new(
            {
              message: Xhash::ErrorMessage::INVALID_CURP, response: response
            }
          )
  end

  Xhash::CURP.new(*payload.values_at(*Xhash::CURP.members))
end