Class: QiwiPay::Api::Response
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- QiwiPay::Api::Response
- Includes:
- MessagesForCodes
- Defined in:
- lib/qiwi-pay/api/response.rb
Overview
QiwiPay API response
Constant Summary collapse
- INTEGER_PARAMS =
Parameters of integer type
%w[ txn_id txn_status txn_type error_code currency ]
Constants included from MessagesForCodes
MessagesForCodes::ERROR_MESSAGES, MessagesForCodes::TXN_STATUS_MESSAGES, MessagesForCodes::TXN_TYPE_MESSAGES
Instance Method Summary collapse
-
#initialize(response_code, response_body) ⇒ Response
constructor
A new instance of Response.
- #success? ⇒ Boolean
Methods included from MessagesForCodes
#error_message, #txn_status_message, #txn_type_message
Constructor Details
#initialize(response_code, response_body) ⇒ Response
Returns a new instance of Response.
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/qiwi-pay/api/response.rb', line 22 def initialize(response_code, response_body) begin params = JSON.parse(response_body) (INTEGER_PARAMS & params.keys).each do |p| params[p] = params[p] && params[p].to_i end super params rescue JSON::ParserError super error_code: -1 define_singleton_method :error_message, ->{ response_body } end send(:http_code=, response_code) end |
Instance Method Details
#success? ⇒ Boolean
36 37 38 |
# File 'lib/qiwi-pay/api/response.rb', line 36 def success? http_code == 200 && error_code == 0 end |