class Xdelivery::API::Base
Constants
- BASE_URL
Attributes
access_key[RW]
merchant_no[RW]
Public Class Methods
new(merchant_no='', access_key='')
click to toggle source
# File lib/xdelivery/api/base.rb, line 11 def initialize(merchant_no='', access_key='') self.merchant_no = merchant_no self.access_key = access_key end
Protected Instance Methods
get(path)
click to toggle source
# File lib/xdelivery/api/base.rb, line 30 def get(path) RestClient::Request.execute(method: :get, url: uri(path).to_s, open_timeout: open_timeout, read_timeout: read_timeout) rescue RestClient::ExceptionWithResponse => e e.response end
open_timeout()
click to toggle source
# File lib/xdelivery/api/base.rb, line 36 def open_timeout Xdelivery.open_timeout end
params()
click to toggle source
- GET
-
query string params
# File lib/xdelivery/api/base.rb, line 45 def params {} end
patch(path)
click to toggle source
# File lib/xdelivery/api/base.rb, line 18 def patch(path) RestClient::Request.execute(method: :patch, url: uri(path).to_s, payload: patch_data, open_timeout: open_timeout, read_timeout: read_timeout) rescue RestClient::ExceptionWithResponse => e e.response end
patch_data()
click to toggle source
- PATCH
# File lib/xdelivery/api/base.rb, line 55 def patch_data {} end
post(path)
click to toggle source
# File lib/xdelivery/api/base.rb, line 24 def post(path) RestClient::Request.execute(method: :post, url: uri(path).to_s, payload: post_data, open_timeout: open_timeout, read_timeout: read_timeout) rescue RestClient::ExceptionWithResponse => e e.response end
post_data()
click to toggle source
- POST
# File lib/xdelivery/api/base.rb, line 50 def post_data {} end
read_timeout()
click to toggle source
# File lib/xdelivery/api/base.rb, line 40 def read_timeout Xdelivery.read_timeout end
Private Instance Methods
auth_params()
click to toggle source
# File lib/xdelivery/api/base.rb, line 69 def auth_params { merchant_no: merchant_no, access_key: access_key } end
query_auth_params()
click to toggle source
# File lib/xdelivery/api/base.rb, line 65 def query_auth_params URI.encode_www_form(auth_params.merge(params)) end
uri(path)
click to toggle source
# File lib/xdelivery/api/base.rb, line 61 def uri(path) uri = URI.parse("#{BASE_URL}#{path}").tap { |u| u.query = query_auth_params } end