Class: Voucherify::Client
- Inherits:
-
Object
- Object
- Voucherify::Client
- Defined in:
- lib/voucherify/client.rb
Instance Attribute Summary collapse
-
#backend_url ⇒ Object
readonly
Returns the value of attribute backend_url.
Instance Method Summary collapse
- #campaigns ⇒ Object
- #customers ⇒ Object
- #delete(path, params = {}) ⇒ Object
- #distributions ⇒ Object
- #events ⇒ Object
- #get(path, params = {}) ⇒ Object
-
#initialize(options) ⇒ Client
constructor
A new instance of Client.
- #loyalties ⇒ Object
- #orders ⇒ Object
- #post(path, body, params = {}) ⇒ Object
- #products ⇒ Object
- #promotions ⇒ Object
- #put(path, body, params = {}) ⇒ Object
- #redemptions ⇒ Object
- #rewards ⇒ Object
- #segments ⇒ Object
- #validation_rules ⇒ Object
- #validations ⇒ Object
- #vouchers ⇒ Object
Constructor Details
#initialize(options) ⇒ Client
Returns a new instance of Client.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/voucherify/client.rb', line 10 def initialize () @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', 'X-Voucherify-API-Version' => @options[:apiVersion] || @options['apiVersion'] || 'v2018-08-01', :accept => :json, }.reject{ |k,v| v.nil? } @timeout = @options[:timeout] || @options['timeout'] end |
Instance Attribute Details
#backend_url ⇒ Object (readonly)
Returns the value of attribute backend_url.
8 9 10 |
# File 'lib/voucherify/client.rb', line 8 def backend_url @backend_url end |
Instance Method Details
#campaigns ⇒ Object
47 48 49 |
# File 'lib/voucherify/client.rb', line 47 def campaigns Voucherify::Service::Campaigns.new(self) end |
#customers ⇒ Object
39 40 41 |
# File 'lib/voucherify/client.rb', line 39 def customers Voucherify::Service::Customers.new(self) end |
#delete(path, params = {}) ⇒ Object
113 114 115 116 117 118 119 120 121 |
# File 'lib/voucherify/client.rb', line 113 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 ⇒ Object
27 28 29 |
# File 'lib/voucherify/client.rb', line 27 def distributions Voucherify::Service::Distributions.new(self) end |
#events ⇒ Object
59 60 61 |
# File 'lib/voucherify/client.rb', line 59 def events Voucherify::Service::Events.new(self) end |
#get(path, params = {}) ⇒ Object
79 80 81 82 83 84 85 86 87 |
# File 'lib/voucherify/client.rb', line 79 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 ⇒ Object
75 76 77 |
# File 'lib/voucherify/client.rb', line 75 def loyalties Voucherify::Service::Loyalties.new(self) end |
#orders ⇒ Object
67 68 69 |
# File 'lib/voucherify/client.rb', line 67 def orders Voucherify::Service::Orders.new(self) end |
#post(path, body, params = {}) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/voucherify/client.rb', line 99 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 ⇒ Object
43 44 45 |
# File 'lib/voucherify/client.rb', line 43 def products Voucherify::Service::Products.new(self) end |
#promotions ⇒ Object
63 64 65 |
# File 'lib/voucherify/client.rb', line 63 def promotions Voucherify::Service::Promotions.new(self) end |
#put(path, body, params = {}) ⇒ Object
89 90 91 92 93 94 95 96 97 |
# File 'lib/voucherify/client.rb', line 89 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 ⇒ Object
35 36 37 |
# File 'lib/voucherify/client.rb', line 35 def redemptions Voucherify::Service::Redemptions.new(self) end |
#rewards ⇒ Object
71 72 73 |
# File 'lib/voucherify/client.rb', line 71 def rewards Voucherify::Service::Rewards.new(self) end |
#segments ⇒ Object
55 56 57 |
# File 'lib/voucherify/client.rb', line 55 def segments Voucherify::Service::Segments.new(self) end |
#validation_rules ⇒ Object
51 52 53 |
# File 'lib/voucherify/client.rb', line 51 def validation_rules Voucherify::Service::ValidationRules.new(self) end |
#validations ⇒ Object
31 32 33 |
# File 'lib/voucherify/client.rb', line 31 def validations Voucherify::Service::Validations.new(self) end |
#vouchers ⇒ Object
23 24 25 |
# File 'lib/voucherify/client.rb', line 23 def vouchers Voucherify::Service::Vouchers.new(self) end |