Class: Biro::Spc::Response

Inherits:
BaseResponse show all
Defined in:
lib/biro/gateways/spc/response.rb

Instance Attribute Summary

Attributes inherited from BaseResponse

#body

Instance Method Summary collapse

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

#addressesObject



56
57
58
# File 'lib/biro/gateways/spc/response.rb', line 56

def addresses
  [single_address] + all_addresses
end

#birthdateObject



14
15
16
# File 'lib/biro/gateways/spc/response.rb', line 14

def birthdate
  fetch_date(person.dig(:@data_nascimento))
end

#cpfObject



10
11
12
# File 'lib/biro/gateways/spc/response.rb', line 10

def cpf
  person.dig(:cpf, :@numero)
end

#defaultsObject



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

#emailsObject



99
100
101
# File 'lib/biro/gateways/spc/response.rb', line 99

def emails
  Array.wrap(person&.dig(:@email))
end

#errorObject



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_nameObject



26
27
28
# File 'lib/biro/gateways/spc/response.rb', line 26

def fathers_name
  person.dig(:@nome_pai)
end

#genderObject



42
43
44
# File 'lib/biro/gateways/spc/response.rb', line 42

def gender
  person.dig(:@sexo)
end

#incomeObject



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_statusObject



18
19
20
# File 'lib/biro/gateways/spc/response.rb', line 18

def marital_status
  person.dig(:@estado_civil)
end

#mothers_nameObject



22
23
24
# File 'lib/biro/gateways/spc/response.rb', line 22

def mothers_name
  person.dig(:@nome_mae)
end

#nameObject



34
35
36
# File 'lib/biro/gateways/spc/response.rb', line 34

def name
  person.dig(:@nome)
end

#phonesObject



60
61
62
# File 'lib/biro/gateways/spc/response.rb', line 60

def phones
  [single_phone] + all_phones
end

#receita_federalObject



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

#rgObject



30
31
32
# File 'lib/biro/gateways/spc/response.rb', line 30

def rg
  person.dig(:@numero_rg)
end

#scoresObject



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

Returns:

  • (Boolean)


88
89
90
# File 'lib/biro/gateways/spc/response.rb', line 88

def success?
  error.blank?
end

#voter_idObject



38
39
40
# File 'lib/biro/gateways/spc/response.rb', line 38

def voter_id
  person.dig(:@numero_titulo_eleitor)
end