Skip to content

Commit

Permalink
[Consents] Support consents API
Browse files Browse the repository at this point in the history
  • Loading branch information
lkulig committed Jun 14, 2021
1 parent 158088b commit 2180d49
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: ruby
rvm:
- 2.2.0
- 2.7.0
before_install:
- gem update bundler
install:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions lib/voucherify.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions lib/voucherify/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions lib/voucherify/service/consents.rb
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion lib/voucherify/service/customers.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'uri'
require 'erb'

module Voucherify
module Service
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/voucherify/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Voucherify
VERSION = '3.0.0'
VERSION = '4.0.0'
end
31 changes: 31 additions & 0 deletions spec/consents_spec.rb
Original file line number Diff line number Diff line change
@@ -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
14 changes: 13 additions & 1 deletion spec/customers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -52,4 +57,11 @@

voucherify.customers.delete customer[:id]
end
end

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
6 changes: 3 additions & 3 deletions voucherify.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2180d49

Please sign in to comment.