26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/gmo.rb', line 26
def api(path, args = {}, verb = "post", options = {}, &error_checking_block)
path = "/payment/#{path}" unless path =~ /^\//
options.merge!({ :host => @host })
result = GMO.make_request path, args, verb, options
if result.status >= 500
error_detail = {
:http_status => result.status.to_i,
:body => result.body,
}
raise GMO::Payment::ServerError.new(result.body, error_detail)
end
if /\.json\Z/ =~ path
parsed_result = ::JSON.parse(result.body)
response = parsed_result.is_a?(Array) ? parsed_result[0] : parsed_result
else
key_values = result.body.to_s.split('&').map { |str| str.split('=', 2) }.flatten
response = Hash[*key_values]
end
if response['RedirectUrl'] && response['RedirectUrl'] != '' && response['t'] && response['t'] != '' && response.keys.index('RedirectUrl') + 1 == response.keys.index('t')
response['RedirectUrl'] = response['RedirectUrl'] + '&t=' + response['t']
response.delete('t')
end
body = response = Hash[response.map { |k,v| [k, NKF.nkf('-S -w',v)] }]
yield(body) if error_checking_block
if options[:http_component]
result.send options[:http_component]
else
body
end
end
|