Class: Biro::Spc::Response
- Inherits:
-
BaseResponse
- Object
- BaseResponse
- Biro::Spc::Response
- Defined in:
- lib/biro/gateways/spc/response.rb
Instance Attribute Summary
Attributes inherited from BaseResponse
Instance Method Summary collapse
- #addresses ⇒ Object
- #birthdate ⇒ Object
- #cpf ⇒ Object
- #defaults ⇒ Object
- #emails ⇒ Object
- #error ⇒ Object
- #fathers_name ⇒ Object
- #gender ⇒ Object
- #income ⇒ Object
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
- #marital_status ⇒ Object
- #mothers_name ⇒ Object
- #name ⇒ Object
- #phones ⇒ Object
- #receita_federal ⇒ Object
- #rg ⇒ Object
- #scores ⇒ Object
- #success? ⇒ Boolean
- #voter_id ⇒ Object
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
6 7 8 |
# File 'lib/biro/gateways/spc/response.rb', line 6 def initialize(response) @body = response.body end |
Instance Method Details
#addresses ⇒ Object
56 57 58 |
# File 'lib/biro/gateways/spc/response.rb', line 56 def addresses [single_address] + all_addresses end |
#birthdate ⇒ Object
14 15 16 |
# File 'lib/biro/gateways/spc/response.rb', line 14 def birthdate fetch_date(person.dig(:@data_nascimento)) end |
#cpf ⇒ Object
10 11 12 |
# File 'lib/biro/gateways/spc/response.rb', line 10 def cpf person.dig(:cpf, :@numero) end |
#defaults ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/biro/gateways/spc/response.rb', line 64 def defaults Array.wrap(spc).map do |d| { bureau: :spc, company: d.dig(:@nome_associado)&.strip, created_at: fetch_date(d.dig(:@data_inclusao)), due_at: fetch_date(d.dig(:@data_vencimento)), value: d.dig(:@valor)&.to_f, city: d.dig(:cidade_associado, :@nome), state: d.dig(:cidade_associado, :estado, :@sigla_uf), phone: { ddd: d.dig(:telefone_associado, :@numero_ddd), number: d.dig(:telefone_associado, :@numero) }, contract: d.dig(:@contrato) } end end |
#emails ⇒ Object
99 100 101 |
# File 'lib/biro/gateways/spc/response.rb', line 99 def emails Array.wrap(person&.dig(:@email)) end |
#error ⇒ Object
92 93 94 95 96 97 |
# File 'lib/biro/gateways/spc/response.rb', line 92 def error return nil unless registration.keys.first =~ /Erro/ error = registration.flatten "#{error[0]} - #{error[1]['Mensagem']}" end |
#fathers_name ⇒ Object
26 27 28 |
# File 'lib/biro/gateways/spc/response.rb', line 26 def fathers_name person.dig(:@nome_pai) end |
#gender ⇒ Object
42 43 44 |
# File 'lib/biro/gateways/spc/response.rb', line 42 def gender person.dig(:@sexo) end |
#income ⇒ Object
46 47 48 |
# File 'lib/biro/gateways/spc/response.rb', line 46 def income result.dig(:renda_presumida_spc, :resumo, :@valor_total)&.to_f&.round(2) end |
#marital_status ⇒ Object
18 19 20 |
# File 'lib/biro/gateways/spc/response.rb', line 18 def marital_status person.dig(:@estado_civil) end |
#mothers_name ⇒ Object
22 23 24 |
# File 'lib/biro/gateways/spc/response.rb', line 22 def mothers_name person.dig(:@nome_mae) end |
#name ⇒ Object
34 35 36 |
# File 'lib/biro/gateways/spc/response.rb', line 34 def name person.dig(:@nome) end |
#phones ⇒ Object
60 61 62 |
# File 'lib/biro/gateways/spc/response.rb', line 60 def phones [single_phone] + all_phones end |
#receita_federal ⇒ Object
50 51 52 53 54 |
# File 'lib/biro/gateways/spc/response.rb', line 50 def receita_federal return nil unless rf { status: rf.dig(:@descricao_situacao), date: fetch_date(rf.dig(:@data_situacao)) } end |
#rg ⇒ Object
30 31 32 |
# File 'lib/biro/gateways/spc/response.rb', line 30 def rg person.dig(:@numero_rg) end |
#scores ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/biro/gateways/spc/response.rb', line 80 def scores [:spc_score_3_meses, :spc_score_12_meses].map do |score| next unless result.include? score fetch_score(result.dig(score)) end.compact end |
#success? ⇒ Boolean
88 89 90 |
# File 'lib/biro/gateways/spc/response.rb', line 88 def success? error.blank? end |
#voter_id ⇒ Object
38 39 40 |
# File 'lib/biro/gateways/spc/response.rb', line 38 def voter_id person.dig(:@numero_titulo_eleitor) end |