onfido 1.0.0 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/gem-push.yml +31 -0
- data/.github/workflows/ruby.yml +25 -0
- data/.rubocop.yml +5 -49
- data/.travis.yml +3 -10
- data/CHANGELOG.md +27 -0
- data/Gemfile +2 -0
- data/README.md +44 -156
- data/lib/onfido.rb +4 -3
- data/lib/onfido/api.rb +21 -11
- data/lib/onfido/errors/connection_error.rb +2 -0
- data/lib/onfido/errors/onfido_error.rb +2 -0
- data/lib/onfido/errors/request_error.rb +2 -0
- data/lib/onfido/errors/server_error.rb +2 -0
- data/lib/onfido/options.rb +38 -0
- data/lib/onfido/resource.rb +48 -58
- data/lib/onfido/resources/address.rb +3 -4
- data/lib/onfido/resources/applicant.rb +2 -0
- data/lib/onfido/resources/check.rb +6 -0
- data/lib/onfido/resources/document.rb +2 -0
- data/lib/onfido/resources/extraction.rb +11 -0
- data/lib/onfido/resources/live_photo.rb +2 -0
- data/lib/onfido/resources/live_video.rb +2 -0
- data/lib/onfido/resources/report.rb +2 -0
- data/lib/onfido/resources/sdk_token.rb +2 -0
- data/lib/onfido/resources/webhook.rb +8 -2
- data/lib/onfido/version.rb +3 -1
- data/onfido.gemspec +5 -7
- data/spec/integrations/address_spec.rb +4 -2
- data/spec/integrations/applicant_spec.rb +12 -7
- data/spec/integrations/check_spec.rb +17 -4
- data/spec/integrations/document_spec.rb +8 -4
- data/spec/integrations/extraction_spec.rb +23 -0
- data/spec/integrations/live_photo_spec.rb +8 -4
- data/spec/integrations/live_video_spec.rb +6 -1
- data/spec/integrations/report_spec.rb +6 -1
- data/spec/integrations/resource_spec.rb +106 -0
- data/spec/integrations/sdk_token_spec.rb +5 -1
- data/spec/integrations/webhook_spec.rb +35 -24
- data/spec/onfido/api_spec.rb +14 -25
- data/spec/onfido/connection_error_spec.rb +4 -2
- data/spec/onfido/options_spec.rb +39 -0
- data/spec/onfido/request_error_spec.rb +4 -2
- data/spec/spec_helper.rb +3 -5
- data/spec/support/fake_onfido_api.rb +69 -46
- data/spec/support/fixtures/applicant.json +1 -1
- data/spec/support/fixtures/check.json +1 -1
- data/spec/support/fixtures/checks.json +1 -1
- data/spec/support/fixtures/document.json +1 -1
- data/spec/support/fixtures/documents.json +2 -2
- data/spec/support/fixtures/extraction.json +23 -0
- data/spec/support/fixtures/live_photo.json +2 -2
- data/spec/support/fixtures/live_photos.json +4 -4
- data/spec/support/fixtures/live_video.json +2 -2
- data/spec/support/fixtures/live_videos.json +2 -2
- data/spec/support/fixtures/report.json +1 -1
- data/spec/support/fixtures/reports.json +2 -2
- data/spec/support/fixtures/webhook.json +1 -1
- data/spec/support/fixtures/webhooks.json +2 -2
- metadata +18 -43
- data/Rakefile +0 -1
- data/lib/onfido/configuration.rb +0 -46
- data/lib/onfido/null_logger.rb +0 -5
- data/spec/integrations/exceptions_spec.rb +0 -73
- data/spec/onfido/resource_spec.rb +0 -131
- data/spec/onfido_spec.rb +0 -76
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7983a2913b8ae4c7a1e53d92b8b62028b57e6e05705f6e5cef13028e77d7a30d
|
4
|
+
data.tar.gz: e923fe60b61214229d3546868a82128607147fb462a7966552ebc67e5d1263e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ab79a44f5d86fbb3fd17c56e3d876ce256f95f88508300d571ebd6a068973323082f7c1a32cf1edd44bbcec5351a073363c08d4950cae6e0510e54263cff448
|
7
|
+
data.tar.gz: a02418a2e5db122bf0fcf3bce2d5547033e4c8e71b18f7a39006674e0a55cd46fb658986224c6f025c3b028e8bac48d19370c903abaa41e874456420ab2c0bf2
|
@@ -0,0 +1,31 @@
|
|
1
|
+
name: Ruby Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
release:
|
5
|
+
types: [published]
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
build:
|
9
|
+
name: Build + Publish
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
permissions:
|
12
|
+
contents: read
|
13
|
+
packages: write
|
14
|
+
|
15
|
+
steps:
|
16
|
+
- uses: actions/checkout@v2
|
17
|
+
- name: Set up Ruby 2.6
|
18
|
+
uses: actions/setup-ruby@v1
|
19
|
+
with:
|
20
|
+
ruby-version: 2.6.x
|
21
|
+
|
22
|
+
- name: Publish to RubyGems
|
23
|
+
run: |
|
24
|
+
mkdir -p $HOME/.gem
|
25
|
+
touch $HOME/.gem/credentials
|
26
|
+
chmod 0600 $HOME/.gem/credentials
|
27
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
28
|
+
gem build *.gemspec
|
29
|
+
gem push *.gem
|
30
|
+
env:
|
31
|
+
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ master ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
strategy:
|
14
|
+
matrix:
|
15
|
+
ruby-version: ['2.4', '2.5', '2.6', '2.7', '3.0']
|
16
|
+
|
17
|
+
steps:
|
18
|
+
- uses: actions/checkout@v2
|
19
|
+
- name: Set up Ruby
|
20
|
+
uses: ruby/setup-ruby@v1
|
21
|
+
with:
|
22
|
+
ruby-version: ${{ matrix.ruby-version }}
|
23
|
+
bundler-cache: true
|
24
|
+
- name: Run tests
|
25
|
+
run: bundle exec rspec spec
|
data/.rubocop.yml
CHANGED
@@ -1,57 +1,13 @@
|
|
1
|
-
# For all options see https://github.com/bbatsov/rubocop/tree/master/config
|
2
|
-
|
3
1
|
AllCops:
|
4
|
-
|
5
|
-
|
6
|
-
- vendor/**/*
|
7
|
-
- .*/**
|
8
|
-
- spec/fixtures/**/*
|
9
|
-
TargetRubyVersion: 2.2.0
|
10
|
-
|
11
|
-
Style/StringLiterals:
|
12
|
-
Enabled: false
|
13
|
-
|
14
|
-
Style/PercentLiteralDelimiters:
|
15
|
-
Enabled: false
|
16
|
-
|
17
|
-
Style/Documentation:
|
18
|
-
Enabled: false
|
19
|
-
|
20
|
-
Style/SignalException:
|
21
|
-
EnforcedStyle: only_raise
|
22
|
-
|
23
|
-
Naming/FileName:
|
24
|
-
Exclude:
|
25
|
-
- Gemfile
|
2
|
+
NewCops: enable
|
3
|
+
TargetRubyVersion: 2.4.0
|
26
4
|
|
27
|
-
|
28
|
-
|
29
|
-
Max: 25
|
5
|
+
Layout/LineLength:
|
6
|
+
Max: 100
|
30
7
|
|
31
8
|
Metrics/BlockLength:
|
32
9
|
Exclude:
|
33
10
|
- spec/**/*
|
34
11
|
|
35
|
-
|
36
|
-
Max: 25
|
37
|
-
|
38
|
-
# Don't require utf-8 encoding comment
|
39
|
-
Style/Encoding:
|
40
|
-
Enabled: false
|
41
|
-
|
42
|
-
Metrics/LineLength:
|
43
|
-
Max: 90
|
44
|
-
|
45
|
-
Metrics/ClassLength:
|
46
|
-
Enabled: false
|
47
|
-
|
48
|
-
Layout/DotPosition:
|
49
|
-
EnforcedStyle: trailing
|
50
|
-
|
51
|
-
# Allow class and message or instance raises
|
52
|
-
Style/RaiseArgs:
|
12
|
+
Style/Documentation:
|
53
13
|
Enabled: false
|
54
|
-
|
55
|
-
Lint/AmbiguousBlockAssociation:
|
56
|
-
Exclude:
|
57
|
-
- "spec/**/*"
|
data/.travis.yml
CHANGED
@@ -1,20 +1,13 @@
|
|
1
1
|
language: ruby
|
2
|
+
cache: bundler
|
2
3
|
|
3
4
|
rvm:
|
4
|
-
- 2.3
|
5
5
|
- 2.4
|
6
6
|
- 2.5
|
7
7
|
- 2.6
|
8
|
-
|
9
|
-
|
10
|
-
- gem update --system
|
11
|
-
- gem install bundler
|
8
|
+
- 2.7
|
9
|
+
- 3.0
|
12
10
|
|
13
11
|
script:
|
14
12
|
- bundle exec rubocop
|
15
13
|
- bundle exec rspec spec
|
16
|
-
|
17
|
-
# safelist
|
18
|
-
branches:
|
19
|
-
only:
|
20
|
-
- master
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,34 @@
|
|
1
|
+
## v2.0.2, 10 June 2021
|
2
|
+
|
3
|
+
- Add error coverage for errors RestClient:BadGateway
|
4
|
+
|
5
|
+
## v2.0.1, 27 May 2021
|
6
|
+
|
7
|
+
- Remove onfido/null_logger
|
8
|
+
|
9
|
+
## v2.0.0, 5 May 2021
|
10
|
+
|
11
|
+
- Remove global configuration, all configuration is now per `Onfido::API` instance
|
12
|
+
- Region is now a required argument (it previously defaulted to `:eu`)
|
13
|
+
- Support Onfido API version 3.1
|
14
|
+
- Drop support for Ruby 2.2 and 2.3
|
15
|
+
|
16
|
+
## v1.1.1, 12 March 2021
|
17
|
+
|
18
|
+
- Send the postcode in the query string for the address picker endpoint
|
19
|
+
|
20
|
+
## v1.1.0, 14 Aug 2020
|
21
|
+
|
22
|
+
- Add User-Agent header
|
23
|
+
- Add support for CA region
|
24
|
+
- Add extractions endpoint
|
25
|
+
- Add webhook deletion endpoint
|
26
|
+
|
1
27
|
## v1.0.0, 13 Jan 2020
|
2
28
|
|
3
29
|
- Support Onfido API version 3
|
4
30
|
- Drop support for Onfido API version 2
|
31
|
+
- To upgrade from 0.15.0 see the v2 to v3 migration [guide](https://developers.onfido.com/guide/v2-to-v3-migration-guide)
|
5
32
|
|
6
33
|
## v0.15.0, 4 Feb 2019
|
7
34
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,184 +1,60 @@
|
|
1
1
|
# Onfido
|
2
2
|
|
3
|
-
|
3
|
+
The official Ruby library for integrating with the Onfido API.
|
4
4
|
|
5
5
|
[![Gem Version](https://badge.fury.io/rb/onfido.svg)](http://badge.fury.io/rb/onfido)
|
6
6
|
[![Build Status](https://travis-ci.org/onfido/onfido-ruby.svg?branch=master)](https://travis-ci.org/onfido/onfido-ruby)
|
7
7
|
|
8
|
-
|
9
|
-
The latest version that supports `v2` of Onfido's API is `0.15.0`. `v1` of Onfido's API is deprecated
|
10
|
-
Refer to Onfido's [API documentation](https://documentation.onfido.com) for details of the expected requests and responses.
|
8
|
+
Documentation can be found at https://documentation.onfido.com
|
11
9
|
|
10
|
+
This version uses Onfido API v3.1 and is compatible with Ruby 2.4 onwards. Refer to our [API versioning guide](https://developers.onfido.com/guide/api-versioning-policy#client-libraries) for details of which client library versions use which versions of the API.
|
12
11
|
|
13
12
|
## Installation
|
14
13
|
|
15
14
|
Add this line to your application's Gemfile:
|
16
15
|
|
17
16
|
```ruby
|
18
|
-
gem 'onfido', '~>
|
17
|
+
gem 'onfido', '~> 2.0.1'
|
19
18
|
```
|
20
19
|
|
21
|
-
|
20
|
+
## Getting started
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
There are 5 configuration options:
|
26
|
-
|
27
|
-
```ruby
|
28
|
-
Onfido.configure do |config|
|
29
|
-
config.api_key = 'MY_API_KEY'
|
30
|
-
config.logger = Logger.new(STDOUT)
|
31
|
-
config.open_timeout = 30
|
32
|
-
config.read_timeout = 80
|
33
|
-
config.region = nil
|
34
|
-
end
|
35
|
-
```
|
36
|
-
|
37
|
-
### Regions
|
38
|
-
|
39
|
-
The gem will use the default region if no region is specified.
|
40
|
-
|
41
|
-
To specify the US region do:
|
42
|
-
`config.region = :us`
|
43
|
-
|
44
|
-
See https://documentation.onfido.com/#regions for supported regions.
|
45
|
-
|
46
|
-
## Usage
|
47
|
-
|
48
|
-
You can make API calls by using an instance of the `API` class:
|
49
|
-
|
50
|
-
```ruby
|
51
|
-
api = Onfido::API.new
|
52
|
-
```
|
53
|
-
|
54
|
-
Alternatively, you can set an API key here instead of in the initializer:
|
22
|
+
Configure with your API token and region:
|
55
23
|
|
56
24
|
```ruby
|
57
|
-
|
25
|
+
onfido = Onfido::API.new(
|
26
|
+
api_key: ENV['ONFIDO_API_KEY'],
|
27
|
+
# Supports :eu, :us and :ca. Previously defaulted to :eu.
|
28
|
+
region: :eu
|
29
|
+
)
|
58
30
|
```
|
59
31
|
|
60
|
-
### Resources
|
61
|
-
|
62
32
|
All resources share the same interface when making API calls. Use `.create` to create a resource, `.find` to find one, and `.all` to fetch all resources.
|
63
33
|
|
64
|
-
|
65
|
-
|
66
|
-
#### Applicants
|
67
|
-
|
68
|
-
Applicants are the object upon which Onfido checks are performed.
|
69
|
-
|
70
|
-
```ruby
|
71
|
-
api.applicant.create(params) # => Creates an applicant
|
72
|
-
api.applicant.update('applicant_id', params) # => Updates an applicant
|
73
|
-
api.applicant.destroy('applicant_id') # => Schedule an applicant for deletion
|
74
|
-
api.applicant.restore('applicant_id') # => Restore an applicant scheduled for deletion
|
75
|
-
api.applicant.find('applicant_id') # => Finds a single applicant
|
76
|
-
api.applicant.all # => Returns all applicants
|
77
|
-
```
|
78
|
-
|
79
|
-
**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.
|
80
|
-
See https://documentation.onfido.com/#delete-applicant for more information.
|
81
|
-
|
82
|
-
#### Documents
|
83
|
-
|
84
|
-
Documents provide supporting evidence for Onfido checks.
|
85
|
-
|
86
|
-
```ruby
|
87
|
-
api.document.create('applicant_id', file: 'http://example.com', type: 'passport') # => Creates a document
|
88
|
-
api.document.find('document_id') # => Finds a document
|
89
|
-
api.document.download('document_id') # => Downloads a document as a binary data
|
90
|
-
api.document.all('applicant_id') # => Returns all applicant's documents
|
91
|
-
```
|
92
|
-
|
93
|
-
**Note:** The file parameter must be a `File`-like object which responds to `#read` and `#path`.
|
94
|
-
Previous versions of this gem supported providing a URL to a file accessible over HTTP or a path
|
95
|
-
to a file in the local filesystem. You should instead load the file yourself and then pass it in
|
96
|
-
to `#create`.
|
97
|
-
|
98
|
-
#### Live Photos
|
99
|
-
|
100
|
-
Live Photos, like documents, can provide supporting evidence for Onfido checks.
|
101
|
-
|
102
|
-
```ruby
|
103
|
-
api.live_photo.create('applicant_id', file: 'http://example.com')
|
104
|
-
api.live_photo.find(live_photo_id) # => Finds a live photo
|
105
|
-
api.live_photo.download(live_photo_id) # => Downloads a live photo as binary data
|
106
|
-
api.live_photo.all(applicant_id) # => Returns all applicant's live photos
|
107
|
-
```
|
108
|
-
|
109
|
-
**Note:** The file parameter must be a `File`-like object which responds to `#read` and `#path`.
|
110
|
-
Previous versions of this gem supported providing a URL to a file accessible over HTTP or a path
|
111
|
-
to a file in the local filesystem. You should instead load the file yourself and then pass it in
|
112
|
-
to `#create`.
|
113
|
-
|
114
|
-
#### Checks
|
115
|
-
|
116
|
-
Checks are requests for Onfido to check an applicant, by commissioning one or
|
117
|
-
more "reports" on them.
|
118
|
-
|
119
|
-
```ruby
|
120
|
-
api.check.create('applicant_id', report_names: ['document'])
|
121
|
-
api.check.find('check_id')
|
122
|
-
api.check.resume('check_id')
|
123
|
-
api.check.all('applicant_id')
|
124
|
-
```
|
125
|
-
|
126
|
-
#### Reports
|
127
|
-
|
128
|
-
Reports provide details of the results of some part of a "check". They are
|
129
|
-
created when a check is created, so the Onfido API only provides support for
|
130
|
-
finding and listing them. For paused reports specifically, additional support for resuming and
|
131
|
-
cancelling reports is also available.
|
34
|
+
For example, to create an applicant:
|
132
35
|
|
133
36
|
```ruby
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
37
|
+
onfido.applicant.create(
|
38
|
+
first_name: 'Test',
|
39
|
+
last_name: 'Applicant'
|
40
|
+
)
|
138
41
|
```
|
139
42
|
|
140
|
-
|
141
|
-
|
142
|
-
Onfido provides an address lookup service, to help ensure well-formatted
|
143
|
-
addresses are provided when creating "applicants". To search for addresses
|
144
|
-
by postcode, use:
|
145
|
-
|
146
|
-
```ruby
|
147
|
-
api.address.all('SE1 4NG')
|
148
|
-
```
|
43
|
+
Documentation and code examples can be found at https://documentation.onfido.com
|
149
44
|
|
150
|
-
|
45
|
+
## Error Handling
|
151
46
|
|
152
|
-
|
153
|
-
as through the dashboard.
|
47
|
+
There are 3 classes of errors raised by the library, all of which subclass `Onfido::OnfidoError`:
|
154
48
|
|
155
|
-
|
156
|
-
api.webhook.create(params) # => Creates a webhook endpoint
|
157
|
-
api.webhook.find('webhook_id') # => Finds a single webhook endpoint
|
158
|
-
api.webhook.all # => Returns all webhook endpoints
|
159
|
-
```
|
160
|
-
|
161
|
-
#### SDK Tokens
|
162
|
-
|
163
|
-
Onfido allows you to generate JSON Web Tokens via the API in order to authenticate
|
164
|
-
with Onfido's [JavaScript SDK](https://github.com/onfido/onfido-sdk-ui).
|
165
|
-
|
166
|
-
```ruby
|
167
|
-
api.sdk_token.create(applicant_id: 'applicant_id', referrer: 'referrer')
|
168
|
-
```
|
169
|
-
|
170
|
-
### Error Handling
|
171
|
-
|
172
|
-
There are three classes of errors raised by the library, all of which subclass `Onfido::OnfidoError`:
|
49
|
+
- `Onfido::RequestError` is raised whenever Onfido returns a `4xx` response
|
173
50
|
- `Onfido::ServerError` is raised whenever Onfido returns a `5xx` response
|
174
|
-
- `Onfido::RequestError` is raised whenever Onfido returns any other kind of error
|
175
51
|
- `Onfido::ConnectionError` is raised whenever a network error occurs (e.g., a timeout)
|
176
52
|
|
177
|
-
All
|
53
|
+
All 3 error classes provide the `response_code`, `response_body`, `json_body`, `type` and `fields` of the error (although for `Onfido::ServerError` and `Onfido::ConnectionError` the last 3 are likely to be `nil`).
|
178
54
|
|
179
55
|
```ruby
|
180
56
|
def create_applicant
|
181
|
-
|
57
|
+
onfido.applicant.create(params)
|
182
58
|
rescue Onfido::RequestError => e
|
183
59
|
e.type # => 'validation_error'
|
184
60
|
e.fields # => { "email": { "messages": ["invalid format"] } }
|
@@ -186,15 +62,27 @@ rescue Onfido::RequestError => e
|
|
186
62
|
end
|
187
63
|
```
|
188
64
|
|
189
|
-
##
|
65
|
+
## Other configuration
|
190
66
|
|
191
|
-
|
67
|
+
Optional configuration options with their defaults:
|
192
68
|
|
193
|
-
|
69
|
+
```ruby
|
70
|
+
onfido = Onfido::API.new(
|
71
|
+
# ...
|
72
|
+
open_timeout: 10,
|
73
|
+
read_timeout: 30
|
74
|
+
)
|
75
|
+
```
|
76
|
+
|
77
|
+
## Verifying webhooks
|
78
|
+
|
79
|
+
Each webhook endpoint has a secret token, generated automatically and [exposed](https://onfido.com/documentation#register-webhook) in the API. When sending a request, Onfido includes a signature computed using the request body and this token in the `X-SHA2-Signature` header.
|
80
|
+
|
81
|
+
You should compare this provided signature to one you generate yourself with the token to verify that a webhook is a genuine request from Onfido.
|
194
82
|
|
195
83
|
```ruby
|
196
84
|
if Onfido::Webhook.valid?(request.raw_post,
|
197
|
-
request.headers["X-Signature"],
|
85
|
+
request.headers["X-SHA2-Signature"],
|
198
86
|
ENV['ONFIDO_WEBHOOK_TOKEN'])
|
199
87
|
process_webhook
|
200
88
|
else
|
@@ -202,16 +90,16 @@ else
|
|
202
90
|
end
|
203
91
|
```
|
204
92
|
|
205
|
-
|
206
|
-
|
207
|
-
- Improve test coverage with more scenarios
|
208
|
-
- Add custom errors based on the response code
|
209
|
-
- Improve pagination handling (use information passed in link header)
|
93
|
+
Read more at https://onfido.com/documentation#webhook-security
|
210
94
|
|
211
95
|
## Contributing
|
212
96
|
|
213
|
-
1. Fork it ( https://github.com/onfido/onfido/fork )
|
97
|
+
1. Fork it ( https://github.com/onfido/onfido-ruby/fork )
|
214
98
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
215
99
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
216
100
|
4. Push to the branch (`git push origin my-new-feature`)
|
217
101
|
5. Create a new Pull Request
|
102
|
+
|
103
|
+
## More documentation
|
104
|
+
|
105
|
+
More documentation and code examples can be found at https://documentation.onfido.com
|