diff --git a/.travis.yml b/.travis.yml index afc33489..2a7e7b46 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: ruby rvm: - - 2.2.0 + - 2.7.0 before_install: - gem update bundler install: diff --git a/README.md b/README.md index f097526f..d580dc96 100644 --- a/README.md +++ b/README.md @@ -757,6 +757,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To Bug reports and pull requests are welcome on GitHub at https://github.com/rspective/voucherify-ruby-sdk. ## Changelog +- **2021-06-14** - `4.0.0` - Bumped required ruby version, bumped dependencies, added `Consents` API support, remove deprecated `URI.escape`. - **2020-03-09** - `3.0.0` - Bumped required ruby version, bumped dependencies, added `list` method in Customers module. - **2019-06-19** - `2.4.0` - Added support for custom API endpoint, that allows to connect to projects created in specific Voucherify region. - **2019-05-09** - `2.3.0` - Added `create_publication` method in Distributions module. diff --git a/lib/voucherify.rb b/lib/voucherify.rb index 1ad87ca5..621b9d7a 100644 --- a/lib/voucherify.rb +++ b/lib/voucherify.rb @@ -15,6 +15,7 @@ require 'voucherify/service/validation_rules' require 'voucherify/service/validations' require 'voucherify/service/vouchers' +require 'voucherify/service/consents' require 'voucherify/utils' module Voucherify diff --git a/lib/voucherify/client.rb b/lib/voucherify/client.rb index 94b43b50..94f4761e 100644 --- a/lib/voucherify/client.rb +++ b/lib/voucherify/client.rb @@ -76,6 +76,10 @@ def loyalties Voucherify::Service::Loyalties.new(self) end + def consents + Voucherify::Service::Consents.new(self) + end + def get(path, params = {}) begin url = @backend_url + path diff --git a/lib/voucherify/service/consents.rb b/lib/voucherify/service/consents.rb new file mode 100644 index 00000000..9d67b31f --- /dev/null +++ b/lib/voucherify/service/consents.rb @@ -0,0 +1,17 @@ +require 'uri' + +module Voucherify + module Service + class Consents + attr_reader :client + + def initialize(client) + @client = client + end + + def get() + @client.get('/consents') + end + end + end +end diff --git a/lib/voucherify/service/customers.rb b/lib/voucherify/service/customers.rb index b86e33ff..71cdab35 100644 --- a/lib/voucherify/service/customers.rb +++ b/lib/voucherify/service/customers.rb @@ -1,4 +1,4 @@ -require 'uri' +require 'erb' module Voucherify module Service @@ -28,6 +28,10 @@ def update(customer) def delete(customer_id) @client.delete("/customers/#{ERB::Util.url_encode(customer_id)}") end + + def update_consents(customer_id, consents) + @client.put("/customers/#{ERB::Util.url_encode(customer_id)}/consents", consents.to_json) + end end end end diff --git a/lib/voucherify/version.rb b/lib/voucherify/version.rb index 20f864dc..5b133927 100644 --- a/lib/voucherify/version.rb +++ b/lib/voucherify/version.rb @@ -1,3 +1,3 @@ module Voucherify - VERSION = '3.0.0' + VERSION = '4.0.0' end diff --git a/spec/consents_spec.rb b/spec/consents_spec.rb new file mode 100644 index 00000000..185de94a --- /dev/null +++ b/spec/consents_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' +require 'rest-client' +require 'date' + +describe 'Consents API' do + + let(:application_id) { 'application_id' } + let(:client_secret_key) { 'client_secret_key' } + + let(:voucherify) { Voucherify::Client.new({:applicationId => application_id, :clientSecretKey => client_secret_key}) } + let(:headers) { { + 'X-App-Id' => application_id, + 'X-App-Token' => client_secret_key, + 'X-Voucherify-Channel' => 'Ruby-SDK', + :accept => 'application/json' + } } + + let(:consents) { { + :groups => {}, + :consents => {} + } } + + it 'should get consents' do + stub_request(:get, "https://api.voucherify.io/v1/consents") + .with(headers: headers) + .to_return(:status => 200, :body => consents.to_json, :headers => {}) + + voucherify.consents.get() + end + +end diff --git a/spec/customers_spec.rb b/spec/customers_spec.rb index 74480a27..b58ba2b7 100644 --- a/spec/customers_spec.rb +++ b/spec/customers_spec.rb @@ -23,6 +23,11 @@ :lang => 'en' }} } + let(:consents) { { + :groups => {}, + :consents => {} + } } + it 'should create customer' do stub_request(:post, 'https://api.voucherify.io/v1/customers') .with(body: customer.to_json, headers: headers) @@ -52,4 +57,11 @@ voucherify.customers.delete customer[:id] end -end \ No newline at end of file + + it 'should update customer consents' do + stub_request(:put, "https://api.voucherify.io/v1/customers/#{customer[:id]}/consents") + .to_return(:status => 200, :body => customer.to_json, :headers => {}) + + voucherify.customers.update_consents(customer[:id], consents) + end +end diff --git a/voucherify.gemspec b/voucherify.gemspec index fd4fb9e5..84aa92c6 100644 --- a/voucherify.gemspec +++ b/voucherify.gemspec @@ -18,11 +18,11 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ['lib'] - spec.add_development_dependency 'rake', '~> 13.0.1' - spec.add_development_dependency 'rspec', '~> 3.0' + spec.add_development_dependency 'rake', '~> 13.0.3' + spec.add_development_dependency 'rspec', '~> 3.9.0' spec.add_development_dependency 'webmock', '~> 3.8.2' - spec.add_dependency 'rest-client', '~> 2.0' + spec.add_dependency 'rest-client', '~> 2.1.0' spec.required_ruby_version = '>= 2.2.0' end