Class: GMO::Payment::API

Inherits:
Object
  • Object
show all
Defined in:
lib/gmo.rb

Direct Known Subclasses

ShopAPI, ShopAndSiteAPI, SiteAPI

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ API

Returns a new instance of API.



20
21
22
# File 'lib/gmo.rb', line 20

def initialize(options = {})
  @host = options[:host]
end

Instance Attribute Details

#hostObject (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

Yields:

  • (body)


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", options = {}, &error_checking_block)
  # Setup args for make_request
  path = "/payment/#{path}" unless path =~ /^\//
  options.merge!({ :host => @host })
  # Make request via the provided service
  result = GMO.make_request path, args, verb, options
  # 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 options[:http_component]
    result.send options[: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 = {}, options = {})
  api_call(name, args, "get", options)
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 = {}, options = {})
  args = associate_options_to_gmo_params args
  api_call(name, args, "post", options)
end