class Voucherify::Client
Attributes
backend_url[R]
Public Class Methods
new(options)
click to toggle source
# File lib/voucherify/client.rb, line 10 def initialize (options) @options = options @backend_url = (@options[:apiUrl] || @options['apiUrl'] || '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', 'X-Voucherify-API-Version' => @options[:apiVersion] || @options['apiVersion'] || 'v2018-08-01', :accept => :json, }.reject{ |k,v| v.nil? } @timeout = @options[:timeout] || @options['timeout'] end
Public Instance Methods
campaigns()
click to toggle source
# File lib/voucherify/client.rb, line 47 def campaigns Voucherify::Service::Campaigns.new(self) end
consents()
click to toggle source
# File lib/voucherify/client.rb, line 79 def consents Voucherify::Service::Consents.new(self) end
customers()
click to toggle source
# File lib/voucherify/client.rb, line 39 def customers Voucherify::Service::Customers.new(self) end
delete(path, params = {})
click to toggle source
# File lib/voucherify/client.rb, line 117 def delete(path, params = {}) begin url = @backend_url + path RestClient::Request::execute(method: :delete, url: url, headers: @headers.merge({:params => params}), read_timeout: @timeout, open_timeout: @timeout) nil rescue RestClient::Exception => e raise VoucherifyError.new(e) end end
distributions()
click to toggle source
# File lib/voucherify/client.rb, line 27 def distributions Voucherify::Service::Distributions.new(self) end
events()
click to toggle source
# File lib/voucherify/client.rb, line 59 def events Voucherify::Service::Events.new(self) end
get(path, params = {})
click to toggle source
# File lib/voucherify/client.rb, line 83 def get(path, params = {}) begin url = @backend_url + path response = RestClient::Request::execute(method: :get, url: url, headers: @headers.merge({:params => params}), read_timeout: @timeout, open_timeout: @timeout) JSON.parse(response.body) rescue RestClient::Exception => e raise VoucherifyError.new(e) end end
loyalties()
click to toggle source
# File lib/voucherify/client.rb, line 75 def loyalties Voucherify::Service::Loyalties.new(self) end
orders()
click to toggle source
# File lib/voucherify/client.rb, line 67 def orders Voucherify::Service::Orders.new(self) end
post(path, body, params = {})
click to toggle source
# File lib/voucherify/client.rb, line 103 def post(path, body, params = {}) begin url = @backend_url + path response = RestClient::Request::execute(method: :post, url: url, payload: body, headers: @headers.merge({:params => params, :content_type => :json}), read_timeout: @timeout, open_timeout: @timeout) if !response.body.empty? JSON.parse(response.body) else nil end rescue RestClient::Exception => e raise VoucherifyError.new(e) end end
products()
click to toggle source
# File lib/voucherify/client.rb, line 43 def products Voucherify::Service::Products.new(self) end
promotions()
click to toggle source
# File lib/voucherify/client.rb, line 63 def promotions Voucherify::Service::Promotions.new(self) end
put(path, body, params = {})
click to toggle source
# File lib/voucherify/client.rb, line 93 def put(path, body, params = {}) begin url = @backend_url + path response = RestClient::Request::execute(method: :put, url: url, payload: body, headers: @headers.merge({:params => params, :content_type => :json}), read_timeout: @timeout, open_timeout: @timeout) JSON.parse(response.body) rescue RestClient::Exception => e raise VoucherifyError.new(e) end end
redemptions()
click to toggle source
# File lib/voucherify/client.rb, line 35 def redemptions Voucherify::Service::Redemptions.new(self) end
rewards()
click to toggle source
# File lib/voucherify/client.rb, line 71 def rewards Voucherify::Service::Rewards.new(self) end
segments()
click to toggle source
# File lib/voucherify/client.rb, line 55 def segments Voucherify::Service::Segments.new(self) end
validation_rules()
click to toggle source
# File lib/voucherify/client.rb, line 51 def validation_rules Voucherify::Service::ValidationRules.new(self) end
validations()
click to toggle source
# File lib/voucherify/client.rb, line 31 def validations Voucherify::Service::Validations.new(self) end
vouchers()
click to toggle source
# File lib/voucherify/client.rb, line 23 def vouchers Voucherify::Service::Vouchers.new(self) end