Sha256: c144424b031284da2117fd5b94fd0d3794df506be4402cf14f2e6d0ac78e120d
Contents?: true
Size: 1.82 KB
Versions: 2
Compression:
Stored size: 1.82 KB
Contents
require 'uri' require 'rest-client' require 'json' module Voucherify class Client attr_reader :backend_url def initialize (options) @options = options @backend_url = 'https://api.voucherify.io/v1' @headers = { 'X-App-Id' => @options[:applicationId] || @options['applicationId'], 'X-App-Token' => @options[:clientSecretKey] || @options['clientSecretKey'], 'X-Voucherify-Channel' => 'Ruby-SDK', :accept => :json } end def vouchers Voucherify::Service::Vouchers.new(self) end def distributions Voucherify::Service::Distributions.new(self) end def validations Voucherify::Service::Validations.new(self) end def redemptions Voucherify::Service::Redemptions.new(self) end def customers Voucherify::Service::Customers.new(self) end def products Voucherify::Service::Products.new(self) end def campaigns Voucherify::Service::Campaigns.new(self) end def get(path, params = {}) url = @backend_url + path response = RestClient.get(url, @headers.merge({:params => params})) JSON.parse(response.body) end def put(path, body, params = {}) url = @backend_url + path response = RestClient.put(url, body, @headers.merge({:params => params, :content_type => :json})) JSON.parse(response.body) end def post(path, body, params = {}) url = @backend_url + path response = RestClient.post(url, body, @headers.merge({:params => params, :content_type => :json})) if !response.body.empty? JSON.parse(response.body) else nil end end def delete(path, params = {}) url = @backend_url + path RestClient.delete(url, @headers.merge({:params => params})) nil end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
voucherify-1.2.0 | lib/voucherify/client.rb |
voucherify-1.1.0 | lib/voucherify/client.rb |