Class: VSafe::Response
- Inherits:
-
Object
- Object
- VSafe::Response
- Defined in:
- lib/vsafe/response.rb
Direct Known Subclasses
VSafe::Responses::ChargeAccountToTemporaryToken, VSafe::Responses::ChargeAuthorize, VSafe::Responses::ChargeConfirm, VSafe::Responses::ChargeSale, VSafe::Responses::GetPaymentStatus, VSafe::Responses::GetSessionTags, VSafe::Responses::ReversePayment, VSafe::Responses::ValidateChargeAccount
Constant Summary collapse
- SUCCESS_RESPONSE_CODE =
"0".freeze
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
- #success? ⇒ Boolean
- #to_hash ⇒ Object
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/vsafe/response.rb', line 26 def initialize(response) @response = response if response.success? unless success? @error = ResponseError.new(response.parsed_response) end else raise RequestError.new(response) end end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
8 9 10 |
# File 'lib/vsafe/response.rb', line 8 def error @error end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
8 9 10 |
# File 'lib/vsafe/response.rb', line 8 def response @response end |
Class Method Details
.define_attribute_mapping(attr_method, response_parameter, wrapper = nil) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/vsafe/response.rb', line 10 def self.define_attribute_mapping(attr_method, response_parameter, wrapper = nil) define_method(attr_method) do memo_variable = "@_#{attr_method}" memo_value = instance_variable_get(memo_variable) return memo_value if instance_variable_defined?(memo_variable) memo_value = if wrapper && response.parsed_response[response_parameter] wrapper.new(response.parsed_response[response_parameter]) else response.parsed_response[response_parameter] end instance_variable_set(memo_variable, memo_value) end end |
Instance Method Details
#success? ⇒ Boolean
38 39 40 41 |
# File 'lib/vsafe/response.rb', line 38 def success? response.success? && response.parsed_response["ResponseCode"].to_s == SUCCESS_RESPONSE_CODE end |
#to_hash ⇒ Object
43 44 45 |
# File 'lib/vsafe/response.rb', line 43 def to_hash response.parsed_response || {} end |