diff --git a/.rubocop.yml b/.rubocop.yml index 3f9486e..1dc68b9 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -51,3 +51,7 @@ Layout/DotPosition: # Allow class and message or instance raises Style/RaiseArgs: Enabled: false + +Lint/AmbiguousBlockAssociation: + Exclude: + - "spec/**/*" diff --git a/CHANGELOG.md b/CHANGELOG.md index be9debd..9534aa2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +## v0.14.0, 28 Jan 2019 + +- Add support for applicant deletion and restore endpoints + +## v0.13.0, 5 Nov 2018 + +- Add support for region-specific environments (@stephencookdev) + ## v0.12.0, 29 May 2018 - Add support for the Live Video resource (#55) (@Intrepidd) diff --git a/README.md b/README.md index 989bb67..aa20cfa 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ This gem supports both `v1` and `v2` of the Onfido API. Refer to Onfido's [API d Add this line to your application's Gemfile: ```ruby -gem 'onfido', '~> 0.13.0' +gem 'onfido', '~> 0.14.0' ``` The gem is compatible with Ruby 2.2.0 and onwards. Earlier versions of Ruby have [reached end-of-life](https://www.ruby-lang.org/en/news/2017/04/01/support-of-ruby-2-1-has-ended/), are no longer supported and no longer receive security fixes. @@ -28,7 +28,7 @@ Onfido.configure do |config| config.logger = Logger.new(STDOUT) config.open_timeout = 30 config.read_timeout = 80 - config.region = nil + config.region = nil end ``` @@ -68,11 +68,15 @@ Applicants are the object upon which Onfido checks are performed. ```ruby api.applicant.create(params) # => Creates an applicant api.applicant.update('applicant_id', params) # => Updates an applicant -api.applicant.destroy('applicant_id') # => Destroy an applicant +api.applicant.destroy('applicant_id') # => Schedule an applicant for deletion +api.applicant.restore('applicant_id') # => Restore an applicant scheduled for deletion api.applicant.find('applicant_id') # => Finds a single applicant api.applicant.all # => Returns all applicants ``` +**Note:** Calling `api.applicant.destroy` adds the applicant and all associated documents, photos, videos, checks, and reports to the deletion queue. They will be deleted 20 days after the request is made. An applicant that is scheduled for deletion can be restored but applicants that have been permanently deleted cannot. +See https://documentation.onfido.com/#delete-applicant for more information. + #### Documents Documents provide supporting evidence for Onfido checks. diff --git a/lib/onfido/resources/applicant.rb b/lib/onfido/resources/applicant.rb index 42fffb4..c2ffd64 100644 --- a/lib/onfido/resources/applicant.rb +++ b/lib/onfido/resources/applicant.rb @@ -19,5 +19,9 @@ def find(applicant_id) def all(page: 1, per_page: 20) get(url: url_for("applicants?page=#{page}&per_page=#{per_page}")) end + + def restore(applicant_id) + post(url: url_for("applicants/#{applicant_id}/restore")) + end end end diff --git a/lib/onfido/version.rb b/lib/onfido/version.rb index b7e83d3..39139be 100644 --- a/lib/onfido/version.rb +++ b/lib/onfido/version.rb @@ -1,3 +1,3 @@ module Onfido - VERSION = '0.13.0'.freeze + VERSION = '0.14.0'.freeze end diff --git a/spec/integrations/applicant_spec.rb b/spec/integrations/applicant_spec.rb index 717958d..39231a6 100644 --- a/spec/integrations/applicant_spec.rb +++ b/spec/integrations/applicant_spec.rb @@ -97,4 +97,28 @@ end end end + + describe '#restore' do + context 'an applicant scheduled for deletion' do + let(:applicant_id) { '61f659cb-c90b-4067-808a-6136b5c01351' } + + it 'returns nil' do + expect(applicant.restore(applicant_id)).to be_nil + end + end + + context 'an applicant not scheduled for deletion' do + let(:applicant_id) { 'a2fb9c62-ab10-4898-a8ec-342c4b552ad5' } + + it 'returns an error' do + expect { applicant.restore(applicant_id) }.to raise_error { |error| + expect(error).to be_a(Onfido::RequestError) + expect(error.message).to eq('There was a validation error on this request') + expect(error.fields).to eq( + "Applicant a2fb9c62-ab10-4898-a8ec-342c4b552ad5 is not scheduled for deletion" + ) + } + end + end + end end diff --git a/spec/support/fake_onfido_api.rb b/spec/support/fake_onfido_api.rb index 4753ad2..684ec00 100644 --- a/spec/support/fake_onfido_api.rb +++ b/spec/support/fake_onfido_api.rb @@ -26,6 +26,14 @@ class FakeOnfidoAPI < Sinatra::Base status 204 end + post '/v2/applicants/:id/restore' do + if params["id"] == "a2fb9c62-ab10-4898-a8ec-342c4b552ad5" + json_response(422, 'not_scheduled_for_deletion_error.json') + else + status 204 + end + end + post '/v2/applicants/:id/documents' do json_response(201, 'document.json') end diff --git a/spec/support/fixtures/not_scheduled_for_deletion_error.json b/spec/support/fixtures/not_scheduled_for_deletion_error.json new file mode 100644 index 0000000..91c94f9 --- /dev/null +++ b/spec/support/fixtures/not_scheduled_for_deletion_error.json @@ -0,0 +1,7 @@ +{ + "error": { + "type": "validation_error", + "message": "There was a validation error on this request", + "fields": "Applicant a2fb9c62-ab10-4898-a8ec-342c4b552ad5 is not scheduled for deletion" + } +}