Sha256: f17198c5edb6ca1ac3671ab80ebc3d2bccf72b66e7ed8a544f51806ec5717afc
Contents?: true
Size: 1.68 KB
Versions: 2
Compression:
Stored size: 1.68 KB
Contents
require 'uri' require 'rest-client' module Xdelivery module API class Base attr_accessor :merchant_no, :access_key BASE_URL = 'https://api.xdelivery.io' def initialize(merchant_no='', access_key='') self.merchant_no = merchant_no self.access_key = access_key end protected 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 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 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 def open_timeout Xdelivery.open_timeout end def read_timeout Xdelivery.read_timeout end # [GET] query string params def params {} end # [POST] def post_data {} end # [PATCH] def patch_data {} end private def uri(path) uri = URI.parse("#{BASE_URL}#{path}").tap { |u| u.query = query_auth_params } end def query_auth_params URI.encode_www_form(auth_params.merge(params)) end def auth_params { merchant_no: merchant_no, access_key: access_key } end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
xdelivery-1.0.2 | lib/xdelivery/api/base.rb |
xdelivery-1.0.1 | lib/xdelivery/api/base.rb |