Class: TNSPayments::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/tns_payments/response.rb

Direct Known Subclasses

ErrorResponse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.



7
8
9
# File 'lib/tns_payments/response.rb', line 7

def initialize response
  @raw_response = response
end

Instance Attribute Details

#raw_responseObject (readonly)

Returns the value of attribute raw_response.



5
6
7
# File 'lib/tns_payments/response.rb', line 5

def raw_response
  @raw_response
end

Instance Method Details

#messageObject

Public: Unuseful message.

Returns a string.



35
36
37
38
39
40
41
# File 'lib/tns_payments/response.rb', line 35

def message
  if success?
    'Successful request'
  else
    ErrorResponse.new(raw_response).explanation
  end
end

#responseObject

Public: The parsed response.

Returns a hash of the parsed response.



14
15
16
# File 'lib/tns_payments/response.rb', line 14

def response
  @response ||= JSON.parse(raw_response)
end

#resultObject

Public: The result of the request.

Returns a string.



21
22
23
# File 'lib/tns_payments/response.rb', line 21

def result
  response.fetch('result') { 'UNKNOWN' }
end

#success?Boolean

Public: Check if the request was successful.

Returns boolean.

Returns:

  • (Boolean)


28
29
30
# File 'lib/tns_payments/response.rb', line 28

def success?
  result == 'SUCCESS'
end