Class: GMO::Payment::API
- Inherits:
-
Object
- Object
- GMO::Payment::API
- Defined in:
- lib/gmo.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
Instance Method Summary collapse
- #api(path, args = {}, verb = "post", options = {}) {|body| ... } ⇒ Object
-
#get_request(name, args = {}, options = {}) ⇒ Object
(also: #get!)
gmo.get_request(“EntryTran.idPass”, => “bar”) GET /EntryTran.idPass with params foo=bar.
-
#initialize(options = {}) ⇒ API
constructor
A new instance of API.
-
#post_request(name, args = {}, options = {}) ⇒ Object
(also: #post!)
gmo.post_request(“EntryTran.idPass”, => “bar”) POST /EntryTran.idPass with params foo=bar.
Constructor Details
#initialize(options = {}) ⇒ API
Returns a new instance of API.
21 22 23 |
# File 'lib/gmo.rb', line 21 def initialize( = {}) @host = [:host] end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
24 25 26 |
# File 'lib/gmo.rb', line 24 def host @host end |
Instance Method Details
#api(path, args = {}, verb = "post", options = {}) {|body| ... } ⇒ Object
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 |
# File 'lib/gmo.rb', line 26 def api(path, args = {}, verb = "post", = {}, &error_checking_block) # Setup args for make_request path = "/payment/#{path}" unless path =~ /^\// .merge!({ :host => @host }) # Make request via the provided service result = GMO.make_request path, args, verb, # Check for any 500 server errors before parsing the body 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 # Transform the body to Hash if /\.json\Z/ =~ path # Parse the body as JSON parsed_result = ::JSON.parse(result.body) response = parsed_result.is_a?(Array) ? parsed_result[0] : parsed_result else # Parse the body as Query string # "ACS=1&ACSUrl=url" => { "ACS" => "1", ACSUrl => "url" } key_values = result.body.to_s.split('&').map { |str| str.split('=', 2) }.flatten response = Hash[*key_values] end # converting to UTF-8 body = response = Hash[response.map { |k,v| [k, NKF.nkf('-S -w',v)] }] # Check for errors if provided a error_checking_block yield(body) if error_checking_block # Return result if [:http_component] result.send [:http_component] else body end end |
#get_request(name, args = {}, options = {}) ⇒ Object Also known as: get!
gmo.get_request(“EntryTran.idPass”, => “bar”) GET /EntryTran.idPass with params foo=bar
65 66 67 |
# File 'lib/gmo.rb', line 65 def get_request(name, args = {}, = {}) api_call(name, args, "get", ) end |
#post_request(name, args = {}, options = {}) ⇒ Object Also known as: post!
gmo.post_request(“EntryTran.idPass”, => “bar”) POST /EntryTran.idPass with params foo=bar
72 73 74 75 |
# File 'lib/gmo.rb', line 72 def post_request(name, args = {}, = {}) args = args api_call(name, args, "post", ) end |