Class: Biro::CredDefense::Response
- Inherits:
-
BaseResponse
- Object
- BaseResponse
- Biro::CredDefense::Response
- Defined in:
- lib/biro/gateways/cred_defense/response.rb
Instance Attribute Summary
Attributes inherited from BaseResponse
Instance Method Summary collapse
- #addresses ⇒ Object
- #birthdate ⇒ Object
- #cpf ⇒ Object
- #emails ⇒ Object
- #equities ⇒ Object
- #error ⇒ Object
- #income ⇒ Object
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
- #mothers_name ⇒ Object
- #name ⇒ Object
- #phones ⇒ Object
- #profession ⇒ Object
- #receita_federal ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
6 7 8 |
# File 'lib/biro/gateways/cred_defense/response.rb', line 6 def initialize(response) @body = response.body end |
Instance Method Details
#addresses ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/biro/gateways/cred_defense/response.rb', line 69 def addresses data.fetch('dmlistaenderecos', nil).map do |a| parts = a['nologradouro'].split('-') street = parts[0]&.split[0..-2].join(' ') number = parts[0]&.split&.pop city_parts = a['cdibgemunicipio']&.split('/') city = city_parts && city_parts[0] state = city_parts && city_parts[1] { street: street, number: number, complement: parts[1]&.strip, city: city, state: state, zipcode: a['nrcep'] } end end |
#birthdate ⇒ Object
14 15 16 |
# File 'lib/biro/gateways/cred_defense/response.rb', line 14 def birthdate text('dtnascimento') end |
#cpf ⇒ Object
10 11 12 |
# File 'lib/biro/gateways/cred_defense/response.rb', line 10 def cpf text('nrcpf').gsub(/\D/, '') end |
#emails ⇒ Object
34 35 36 37 |
# File 'lib/biro/gateways/cred_defense/response.rb', line 34 def emails email = text('noemail') Array.wrap(email) end |
#equities ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/biro/gateways/cred_defense/response.rb', line 47 def equities data.dig('dmlistaparticipacaosocietaria')&.map do |e| cpf = e.dig('nrdocumentosocio')&.gsub(/\D/, '') cnpj = e.dig('nrcnpj')&.gsub(/\D/, '') name = e.dig('nosocio')&.strip company = e.dig('norazaosocial')&.strip shares = e.dig('qtpercentualcapitalsocial') position = e.dig('noqualificacaosocio')&.strip since = e.dig('dtentradasociedade')&.strip { cpf: cpf, cnpj: cnpj, name: name, company: company, shares: shares, position: position, since: since, } end end |
#error ⇒ Object
110 111 112 113 114 |
# File 'lib/biro/gateways/cred_defense/response.rb', line 110 def error if json['result'] == 'error' json['messages']&.first end end |
#income ⇒ Object
26 27 28 |
# File 'lib/biro/gateways/cred_defense/response.rb', line 26 def income text('nrrenda') end |
#mothers_name ⇒ Object
18 19 20 |
# File 'lib/biro/gateways/cred_defense/response.rb', line 18 def mothers_name text('nomae') end |
#name ⇒ Object
22 23 24 |
# File 'lib/biro/gateways/cred_defense/response.rb', line 22 def name text('nopessoa') end |
#phones ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/biro/gateways/cred_defense/response.rb', line 90 def phones data.fetch('dmlistatelefones', nil).map do |p| parts = p['nrtelefone']&.split(' ') ddd = parts&.fetch(0, nil)&.gsub(/\D/, '') number = parts&.fetch(1) kind = (number.to_s[0] == '9' ? :mobile : :landline) if number { ddd: ddd, number: number, kind: kind } end end |
#profession ⇒ Object
30 31 32 |
# File 'lib/biro/gateways/cred_defense/response.rb', line 30 def profession text('nrcbo') end |
#receita_federal ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/biro/gateways/cred_defense/response.rb', line 39 def receita_federal rf = data.dig('dmcomprovantereceita')&.first return nil unless rf { name: rf.dig('nopessoa'), status: rf.dig('nosituacao'), date: rf.dig('dhprocessamento'), death: text('boobito') } end |
#success? ⇒ Boolean
106 107 108 |
# File 'lib/biro/gateways/cred_defense/response.rb', line 106 def success? error.blank? end |