class Paymaster::BaseResponse
Attributes
data[RW]
Public Class Methods
new(args={})
click to toggle source
# File lib/paymaster/base_response.rb, line 5 def initialize(args={}) args.each do |k, v| public_send "#{k}=", v end end
parse(body)
click to toggle source
# File lib/paymaster/base_response.rb, line 16 def parse(body) response = Hash.from_xml(body)["Response"] if response["Retval"].to_i != 1 Paymaster::RequestError.new(response) else response = response["Retdata"] response = response[root] if root attrs = {} response.each do |key, value| next unless field = fields[key] attrs[field[:name]] = send(field[:type], value) end new(attrs.merge(data: response)) end end
Protected Class Methods
datetime(value)
click to toggle source
# File lib/paymaster/base_response.rb, line 62 def datetime(value) ActiveSupport::TimeZone["Europe/Kiev"].parse(value) end
decimal(value)
click to toggle source
# File lib/paymaster/base_response.rb, line 50 def decimal(value) BigDecimal.new(value) end
field(name, type=:string, key: name.to_s)
click to toggle source
# File lib/paymaster/base_response.rb, line 45 def field(name, type=:string, key: name.to_s) fields[key] = { name: name, type: type } attr_accessor name end
fields()
click to toggle source
# File lib/paymaster/base_response.rb, line 41 def fields @fields ||= {} end
integer(value)
click to toggle source
# File lib/paymaster/base_response.rb, line 54 def integer(value) value.to_i end
root(value=nil)
click to toggle source
# File lib/paymaster/base_response.rb, line 37 def root(value=nil) @root ||= value end
string(value)
click to toggle source
# File lib/paymaster/base_response.rb, line 58 def string(value) value end
Public Instance Methods
error?()
click to toggle source
# File lib/paymaster/base_response.rb, line 11 def error? false end