Skip to content
This repository has been archived by the owner on Jan 14, 2020. It is now read-only.

Commit

Permalink
Merge pull request #81 from hvssle/feature/add_restore_endpoint
Browse files Browse the repository at this point in the history
Add support for applicant deletion and restore endpoints
  • Loading branch information
Alan Carrie committed Jan 28, 2019
2 parents 8209a7a + 3ef4576 commit 5857f8e
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,7 @@ Layout/DotPosition:
# Allow class and message or instance raises
Style/RaiseArgs:
Enabled: false

Lint/AmbiguousBlockAssociation:
Exclude:
- "spec/**/*"
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
```

Expand Down Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions lib/onfido/resources/applicant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/onfido/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Onfido
VERSION = '0.13.0'.freeze
VERSION = '0.14.0'.freeze
end
24 changes: 24 additions & 0 deletions spec/integrations/applicant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions spec/support/fake_onfido_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions spec/support/fixtures/not_scheduled_for_deletion_error.json
Original file line number Diff line number Diff line change
@@ -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"
}
}

0 comments on commit 5857f8e

Please sign in to comment.