Class: Locaweb::Gateway::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/locaweb-gateway/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_response) ⇒ Response

Returns a new instance of Response.



6
7
8
9
10
# File 'lib/locaweb-gateway/response.rb', line 6

def initialize(raw_response)
  @raw_response = raw_response
  @body = JSON.parse(raw_response.body.to_s)
  @http_status = raw_response.to_i
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



4
5
6
# File 'lib/locaweb-gateway/response.rb', line 4

def body
  @body
end

#http_statusObject (readonly)

Returns the value of attribute http_status.



4
5
6
# File 'lib/locaweb-gateway/response.rb', line 4

def http_status
  @http_status
end

#raw_responseObject (readonly)

Returns the value of attribute raw_response.



4
5
6
# File 'lib/locaweb-gateway/response.rb', line 4

def raw_response
  @raw_response
end

Instance Method Details

#parseObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/locaweb-gateway/response.rb', line 12

def parse
  transaction = Locaweb::Gateway::Transaction.new
  transaction.response = self
  transaction_node = @body['transacao'] || {}
  error_node = transaction_node['erro'] || {}

  transaction.id             = transaction_node['id']
  transaction.status         = transaction_node['status']
  transaction.url_acesso     = transaction_node['url_acesso']
  transaction.meio_pagamento = transaction_node['meio_pagamento']
  transaction.numero_pedido  = transaction_node['numero_pedido']
  transaction.detalhes       = transaction_node['detalhes']
  transaction.erro           = error_node.symbolize_keys
  transaction.erro_codigo    = error_node['codigo']
  transaction.erro_mensagem  = error_node['mensagem']

  transaction
end