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.
20 21 22 |
# File 'lib/gmo.rb', line 20 def initialize( = {}) @host = [:host] end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
23 24 25 |
# File 'lib/gmo.rb', line 23 def host @host end |
Instance Method Details
#api(path, args = {}, verb = "post", options = {}) {|body| ... } ⇒ Object
25 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 |
# File 'lib/gmo.rb', line 25 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 # Parse the body as Query string response = Rack::Utils.parse_nested_query(result.body.to_s) # converting to UTF-8 body = response = Hash[response.map { |k,v| [k, NKF.nkf('-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
55 56 57 |
# File 'lib/gmo.rb', line 55 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
62 63 64 65 |
# File 'lib/gmo.rb', line 62 def post_request(name, args = {}, = {}) args = args api_call(name, args, "post", ) end |