Class: Biro::Midia100::Response
- Inherits:
-
BaseResponse
- Object
- BaseResponse
- Biro::Midia100::Response
- Defined in:
- lib/biro/gateways/midia100/response.rb
Instance Attribute Summary
Attributes inherited from BaseResponse
Instance Method Summary collapse
- #addresses ⇒ Object
- #birthdate ⇒ Object
- #cpf ⇒ Object
- #defaults ⇒ Object
- #education ⇒ Object
- #emails ⇒ Object
- #error ⇒ Object
- #gender ⇒ Object
- #income ⇒ Object
-
#initialize(responses) ⇒ Response
constructor
A new instance of Response.
- #jobs ⇒ Object
- #landline_phones ⇒ Object
- #marital_status ⇒ Object
- #mobile_phones ⇒ Object
- #mothers_name ⇒ Object
- #name ⇒ Object
- #phones ⇒ Object
- #pis ⇒ Object
- #profession ⇒ Object
- #receita_federal ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(responses) ⇒ Response
Returns a new instance of Response.
6 7 8 9 10 |
# File 'lib/biro/gateways/midia100/response.rb', line 6 def initialize(responses) @body = { registration: responses[:registration].body } [:rf, :equity, :job, :default].each { |r| @body[r] = responses[r].body if responses[r] } end |
Instance Method Details
#addresses ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/biro/gateways/midia100/response.rb', line 96 def addresses Array.wrap(registration&.fetch('Enderecos', nil)).map do |e| { street: e['Logradouro']&.strip, number: e['Numero']&.strip, complement: e['Complemento']&.strip, city: e['Cidade']&.strip, state: e['Uf']&.strip, zipcode: e['Cep']&.strip } end end |
#birthdate ⇒ Object
16 17 18 |
# File 'lib/biro/gateways/midia100/response.rb', line 16 def birthdate text('DtNasc') end |
#cpf ⇒ Object
12 13 14 |
# File 'lib/biro/gateways/midia100/response.rb', line 12 def cpf text('Cpf')&.gsub(/\D/, '') end |
#defaults ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/biro/gateways/midia100/response.rb', line 69 def defaults Array.wrap(default&.fetch('spc', nil)).map do |d| { bureau: :spc, company: d['nomeassociado']&.strip, created_at: d['datainclusao'], due_at: d['datavencimento'], value: d['valor'], city: d['nome'], state: d['siglauf'], phone: { ddd: d['numeroddd'], number: d['numero'] }, contract: d['contrato'] } end end |
#education ⇒ Object
40 41 42 |
# File 'lib/biro/gateways/midia100/response.rb', line 40 def education text('Escolaridade') end |
#emails ⇒ Object
109 110 111 112 113 |
# File 'lib/biro/gateways/midia100/response.rb', line 109 def emails Array.wrap(registration&.fetch('Emails', nil)).map do |e| e['EMail']&.strip end end |
#error ⇒ Object
89 90 91 92 93 94 |
# File 'lib/biro/gateways/midia100/response.rb', line 89 def error return nil unless registration.keys.first =~ /Erro/ error = registration.flatten "#{error[0]} - #{error[1]['Mensagem']}" end |
#gender ⇒ Object
48 49 50 |
# File 'lib/biro/gateways/midia100/response.rb', line 48 def gender text('Sexo') end |
#income ⇒ Object
32 33 34 |
# File 'lib/biro/gateways/midia100/response.rb', line 32 def income text('RendaPresumida') end |
#jobs ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/biro/gateways/midia100/response.rb', line 60 def jobs Array.wrap(job&.fetch('Funcionarios', nil)).map do |j| { cnpj: j['Cnpj']&.gsub(/[\s\.\-\/]/, ''), company: j['Empresa']&.strip, } end end |
#landline_phones ⇒ Object
119 120 121 122 123 124 125 126 127 |
# File 'lib/biro/gateways/midia100/response.rb', line 119 def landline_phones Array.wrap(registration&.fetch('Telefones', nil)).map do |t| { ddd: t['Ddd'], number: t['Fone'], kind: :landline } end end |
#marital_status ⇒ Object
20 21 22 |
# File 'lib/biro/gateways/midia100/response.rb', line 20 def marital_status text('EstadoCivil') end |
#mobile_phones ⇒ Object
129 130 131 132 133 134 135 136 137 |
# File 'lib/biro/gateways/midia100/response.rb', line 129 def mobile_phones Array.wrap(registration&.fetch('Celulares', nil)).map do |c| { ddd: c['Ddd'], number: c['Fone'], kind: :mobile } end end |
#mothers_name ⇒ Object
28 29 30 |
# File 'lib/biro/gateways/midia100/response.rb', line 28 def mothers_name text('NomeMae') end |
#name ⇒ Object
44 45 46 |
# File 'lib/biro/gateways/midia100/response.rb', line 44 def name text('Nome') end |
#phones ⇒ Object
115 116 117 |
# File 'lib/biro/gateways/midia100/response.rb', line 115 def phones landline_phones.to_a + mobile_phones.to_a end |
#pis ⇒ Object
24 25 26 |
# File 'lib/biro/gateways/midia100/response.rb', line 24 def pis text('Pis') end |
#profession ⇒ Object
36 37 38 |
# File 'lib/biro/gateways/midia100/response.rb', line 36 def profession text('IdProfissao') end |
#receita_federal ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/biro/gateways/midia100/response.rb', line 52 def receita_federal return nil unless rf data = rf['Receita_x0020_Federal_x0020_Pf'] { name: data.dig('Nome'), status: data.dig('Situacao'), date: data.dig('DataPesquisa'), death: data.dig('Obito') } end |
#success? ⇒ Boolean
85 86 87 |
# File 'lib/biro/gateways/midia100/response.rb', line 85 def success? error.blank? end |