Class: Bs2Api::Entities::Error

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Error

Returns a new instance of Error.



8
9
10
11
# File 'lib/bs2_api/entities/error.rb', line 8

def initialize(args = {})
  @code        = args.fetch(:code, nil)
  @description = args.fetch(:description, nil)
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



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

def code
  @code
end

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

Class Method Details

.from_response(hash_payload) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/bs2_api/entities/error.rb', line 22

def self.from_response(hash_payload)
  return {} if hash_payload.blank?

  hash = ActiveSupport::HashWithIndifferentAccess.new(hash_payload)
  Bs2Api::Entities::Error.new(
    code: hash['erroCodigo'],
    description: hash['erroDescricao']
  )
end

Instance Method Details

#to_hashObject



13
14
15
16
17
18
19
20
# File 'lib/bs2_api/entities/error.rb', line 13

def to_hash
  hash_data = {
    "erroCodigo":    @code,
    "erroDescricao": @description
  }

  ActiveSupport::HashWithIndifferentAccess.new(hash_data)
end