Class: SuperpayApi::Telefone
- Inherits:
-
Object
- Object
- SuperpayApi::Telefone
- 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
-
#codigo_tipo_telefone ⇒ Object
Ver tabela “Tipos de Telefone” Simbolo - Valores pré-definidos [:outros, :residencial, :comercial, :recados, :cobranca, :temporario].
-
#ddd ⇒ Object
DDD do telefone Alfa Numérico - Até 3 caracteres.
-
#ddi ⇒ Object
DDI do telefone Alfa Numérico - Até 3 caracteres.
-
#telefone ⇒ Object
Telefone sem espaços ou traços Alfa Numérico - Até 10 caracteres.
Class Method Summary collapse
-
.validos ⇒ Object
Retornar array com os possíveis tipos de telefone.
Instance Method Summary collapse
-
#codigo_tipo_telefone_to_request ⇒ Object
Retornar o número do tipo de telefone.
-
#initialize(campos = {}) ⇒ Telefone
constructor
Nova instancia da classe Telefone.
-
#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].
Constructor Details
#initialize(campos = {}) ⇒ Telefone
Nova instancia da classe Telefone
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_telefone ⇒ Object
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 |
#ddd ⇒ Object
DDD do telefone Alfa Numérico - Até 3 caracteres
25 26 27 |
# File 'lib/superpay_api/telefone.rb', line 25 def ddd @ddd end |
#ddi ⇒ Object
DDI do telefone Alfa Numérico - Até 3 caracteres
29 30 31 |
# File 'lib/superpay_api/telefone.rb', line 29 def ddi @ddi end |
#telefone ⇒ Object
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
.validos ⇒ Object
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_request ⇒ Object
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 |