Class: Bs2Api::Entities::PixKey

Inherits:
Object
  • Object
show all
Defined in:
lib/bs2_api/entities/pix_key.rb

Constant Summary collapse

TYPES =
{
  cpf: 'CPF',
  cnpj: 'CNPJ',
  phone: 'PHONE',
  email: 'EMAIL',
  random: 'EVP'
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ PixKey

Returns a new instance of PixKey.



16
17
18
19
# File 'lib/bs2_api/entities/pix_key.rb', line 16

def initialize(args = {})
  @key = args.fetch(:key, nil)
  @type = args.fetch(:type, 'CPF')
end

Instance Attribute Details

#keyObject

Returns the value of attribute key.



6
7
8
# File 'lib/bs2_api/entities/pix_key.rb', line 6

def key
  @key
end

#typeObject

Returns the value of attribute type.



6
7
8
# File 'lib/bs2_api/entities/pix_key.rb', line 6

def type
  @type
end

Class Method Details

.from_response(hash_payload) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/bs2_api/entities/pix_key.rb', line 30

def self.from_response(hash_payload)
  hash = ActiveSupport::HashWithIndifferentAccess.new(hash_payload)
  
  Bs2Api::Entities::PixKey.new(
    key: hash["valor"],
    type: hash["tipo"]
  )
end

Instance Method Details

#to_hashObject



21
22
23
24
25
26
27
28
# File 'lib/bs2_api/entities/pix_key.rb', line 21

def to_hash
  ActiveSupport::HashWithIndifferentAccess.new(
    {
      "valor": @key,
      "tipo": @type
    }
  )
end