class GMO::Payment::API
Attributes
host[R]
Public Class Methods
new(options = {})
click to toggle source
# File lib/gmo.rb 21 def initialize(options = {}) 22 @host = options[:host] 23 end
Public Instance Methods
api(path, args = {}, verb = "post", options = {}) { |body| ... }
click to toggle source
# File lib/gmo.rb 26 def api(path, args = {}, verb = "post", options = {}, &error_checking_block) 27 # Setup args for make_request 28 path = "/payment/#{path}" unless path =~ /^\// 29 options.merge!({ :host => @host }) 30 # Make request via the provided service 31 result = GMO.make_request path, args, verb, options 32 # Check for any 500 server errors before parsing the body 33 if result.status >= 500 34 error_detail = { 35 :http_status => result.status.to_i, 36 :body => result.body, 37 } 38 raise GMO::Payment::ServerError.new(result.body, error_detail) 39 end 40 # Transform the body to Hash 41 # "ACS=1&ACSUrl=url" => { "ACS" => "1", ACSUrl => "url" } 42 key_values = result.body.to_s.split('&').map { |str| str.split('=', 2) }.flatten 43 response = Hash[*key_values] 44 # converting to UTF-8 45 body = response = Hash[response.map { |k,v| [k, NKF.nkf('-w',v)] }] 46 # Check for errors if provided a error_checking_block 47 yield(body) if error_checking_block 48 # Return result 49 if options[:http_component] 50 result.send options[:http_component] 51 else 52 body 53 end 54 end
get_request(name, args = {}, options = {})
click to toggle source
gmo.get_request(“EntryTran.idPass”, {:foo => “bar”}) GET /EntryTran.idPass with params foo=bar
# File lib/gmo.rb 58 def get_request(name, args = {}, options = {}) 59 api_call(name, args, "get", options) 60 end
Also aliased as: get!
post_request(name, args = {}, options = {})
click to toggle source
gmo.post_request(“EntryTran.idPass”, {:foo => “bar”}) POST /EntryTran.idPass with params foo=bar
# File lib/gmo.rb 65 def post_request(name, args = {}, options = {}) 66 args = associate_options_to_gmo_params args 67 api_call(name, args, "post", options) 68 end
Also aliased as: post!
Private Instance Methods
api_call(*args)
click to toggle source
# File lib/gmo.rb 82 def api_call(*args) 83 raise "Called abstract method: api_call" 84 end
assert_required_options(required, options)
click to toggle source
# File lib/gmo.rb 73 def assert_required_options(required, options) 74 missing = required.select { |param| options[param].nil? } 75 raise ArgumentError, "Required #{missing.join(', ')} were not provided." unless missing.empty? 76 end
associate_options_to_gmo_params(options)
click to toggle source
# File lib/gmo.rb 78 def associate_options_to_gmo_params(options) 79 Hash[options.map { |k, v| [GMO::Const::INPUT_PARAMS[k], v] }] 80 end