Class: SuperpayApi::Telefone

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
lib/superpay_api/telefone.rb

Constant Summary collapse

TIPOS_DE_TELEFONE =

Opções de Tipo de Telefone

{
  :outros        => 1,
  :residencial   => 2,
  :comercial     => 3,
  :recados       => 4,
  :cobranca      => 5,
  :temporario    => 6,
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(campos = {}) ⇒ Telefone

Nova instancia da classe Telefone

Parameters:

  • campos (Hash) (defaults to: {})


46
47
48
49
50
51
52
# File 'lib/superpay_api/telefone.rb', line 46

def initialize(campos = {})
  campos.each do |campo, valor|
     if SuperpayApi::Telefone.public_instance_methods.include? "#{campo}=".to_sym
      send "#{campo}=", valor
    end
  end
end

Instance Attribute Details

#codigo_tipo_telefoneObject

Ver tabela “Tipos de Telefone” Simbolo - Valores pré-definidos [:outros, :residencial, :comercial, :recados, :cobranca, :temporario]



17
18
19
# File 'lib/superpay_api/telefone.rb', line 17

def codigo_tipo_telefone
  @codigo_tipo_telefone
end

#dddObject

DDD do telefone Alfa Numérico - Até 3 caracteres



25
26
27
# File 'lib/superpay_api/telefone.rb', line 25

def ddd
  @ddd
end

#ddiObject

DDI do telefone Alfa Numérico - Até 3 caracteres



29
30
31
# File 'lib/superpay_api/telefone.rb', line 29

def ddi
  @ddi
end

#telefoneObject

Telefone sem espaços ou traços Alfa Numérico - Até 10 caracteres



21
22
23
# File 'lib/superpay_api/telefone.rb', line 21

def telefone
  @telefone
end

Class Method Details

.validosObject

Retornar array com os possíveis tipos de telefone



35
36
37
# File 'lib/superpay_api/telefone.rb', line 35

def self.validos
  TIPOS_DE_TELEFONE.map{ |key, value| key }
end

Instance Method Details

#codigo_tipo_telefone_to_requestObject

Retornar o número do tipo de telefone



55
56
57
# File 'lib/superpay_api/telefone.rb', line 55

def codigo_tipo_telefone_to_request
  TIPOS_DE_TELEFONE[self.codigo_tipo_telefone]
end

#to_request(tipo) ⇒ Object

Montar o Hash de tefone conforme o tipo dele no padrão utilizado pelo SuperPay tipo: [:comprador, :adicional_comprador, :entrega, :adicional_entrega]



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/superpay_api/telefone.rb', line 61

def to_request tipo
  telefone = {}
  case tipo.to_sym
    when :comprador then
      telefone = {
        codigo_tipo_telefone_comprador:   self.codigo_tipo_telefone_to_request,
        telefone_comprador:               self.telefone,
        ddd_comprador:                    self.ddd,
        ddi_comprador:                    self.ddi,
      }
    when :adicional_comprador then
      telefone = {
        codigo_tipo_telefone_adicional_comprador:   self.codigo_tipo_telefone_to_request,
        telefone_adicional_comprador:               self.telefone,
        ddd_adicional_comprador:                    self.ddd,
        ddi_adicional_comprador:                    self.ddi,
      }
    when :entrega then
      telefone = {
        codigo_tipo_telefone_entrega:   self.codigo_tipo_telefone_to_request,
        telefone_entrega:               self.telefone,
        ddd_entrega:                    self.ddd,
        ddi_entrega:                    self.ddi,
      }
    when :adicional_entrega then
      telefone = {
        codigo_tipo_telefone_adicional_entrega:   self.codigo_tipo_telefone_to_request,
        telefone_adicional_entrega:               self.telefone,
        ddd_adicional_entrega:                    self.ddd,
        ddi_adicional_entrega:                    self.ddi,
      }
    else
      raise 'Tipo inválido.'
  end
  return telefone
end