Class: Biro::Midia100::Response

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

Instance Attribute Summary

Attributes inherited from BaseResponse

#body

Instance Method Summary collapse

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

#addressesObject



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

#birthdateObject



16
17
18
# File 'lib/biro/gateways/midia100/response.rb', line 16

def birthdate
  text('DtNasc')
end

#cpfObject



12
13
14
# File 'lib/biro/gateways/midia100/response.rb', line 12

def cpf
  text('Cpf')&.gsub(/\D/, '')
end

#defaultsObject



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

#educationObject



40
41
42
# File 'lib/biro/gateways/midia100/response.rb', line 40

def education
  text('Escolaridade')
end

#emailsObject



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

#errorObject



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

#genderObject



48
49
50
# File 'lib/biro/gateways/midia100/response.rb', line 48

def gender
  text('Sexo')
end

#incomeObject



32
33
34
# File 'lib/biro/gateways/midia100/response.rb', line 32

def income
  text('RendaPresumida')
end

#jobsObject



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_phonesObject



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_statusObject



20
21
22
# File 'lib/biro/gateways/midia100/response.rb', line 20

def marital_status
  text('EstadoCivil')
end

#mobile_phonesObject



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_nameObject



28
29
30
# File 'lib/biro/gateways/midia100/response.rb', line 28

def mothers_name
  text('NomeMae')
end

#nameObject



44
45
46
# File 'lib/biro/gateways/midia100/response.rb', line 44

def name
  text('Nome')
end

#phonesObject



115
116
117
# File 'lib/biro/gateways/midia100/response.rb', line 115

def phones
  landline_phones.to_a + mobile_phones.to_a
end

#pisObject



24
25
26
# File 'lib/biro/gateways/midia100/response.rb', line 24

def pis
  text('Pis')
end

#professionObject



36
37
38
# File 'lib/biro/gateways/midia100/response.rb', line 36

def profession
  text('IdProfissao')
end

#receita_federalObject



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

Returns:

  • (Boolean)


85
86
87
# File 'lib/biro/gateways/midia100/response.rb', line 85

def success?
  error.blank?
end