Sha256: dd2e5b8fc0ccd3c6e2b42b9690f3e9d9cc0bd0da663984d3af9d38c91fd8cf39
Contents?: true
Size: 1.28 KB
Versions: 12
Compression:
Stored size: 1.28 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.patch(uri(path).to_s, patch_data) rescue RestClient::ExceptionWithResponse => e e.response end def post(path) RestClient.post(uri(path).to_s, post_data) rescue RestClient::ExceptionWithResponse => e e.response end def get(path) RestClient.get(uri(path).to_s) rescue RestClient::ExceptionWithResponse => e e.response 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
12 entries across 12 versions & 1 rubygems