onfido 0.15.1 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/gem-push.yml +31 -0
  3. data/.github/workflows/ruby.yml +25 -0
  4. data/.rubocop.yml +5 -49
  5. data/.travis.yml +3 -10
  6. data/CHANGELOG.md +28 -0
  7. data/Gemfile +2 -0
  8. data/LICENSE +2 -1
  9. data/README.md +46 -172
  10. data/lib/onfido.rb +4 -4
  11. data/lib/onfido/api.rb +21 -15
  12. data/lib/onfido/errors/connection_error.rb +2 -0
  13. data/lib/onfido/errors/onfido_error.rb +2 -0
  14. data/lib/onfido/errors/request_error.rb +2 -0
  15. data/lib/onfido/errors/server_error.rb +2 -0
  16. data/lib/onfido/options.rb +38 -0
  17. data/lib/onfido/resource.rb +44 -61
  18. data/lib/onfido/resources/address.rb +3 -2
  19. data/lib/onfido/resources/applicant.rb +8 -6
  20. data/lib/onfido/resources/check.rb +15 -19
  21. data/lib/onfido/resources/document.rb +13 -11
  22. data/lib/onfido/resources/extraction.rb +11 -0
  23. data/lib/onfido/resources/live_photo.rb +11 -14
  24. data/lib/onfido/resources/live_video.rb +7 -8
  25. data/lib/onfido/resources/report.rb +10 -9
  26. data/lib/onfido/resources/sdk_token.rb +5 -5
  27. data/lib/onfido/resources/webhook.rb +15 -11
  28. data/lib/onfido/version.rb +3 -1
  29. data/onfido.gemspec +10 -12
  30. data/spec/integrations/address_spec.rb +5 -2
  31. data/spec/integrations/applicant_spec.rb +29 -42
  32. data/spec/integrations/check_spec.rb +28 -69
  33. data/spec/integrations/document_spec.rb +22 -19
  34. data/spec/integrations/extraction_spec.rb +23 -0
  35. data/spec/integrations/live_photo_spec.rb +18 -15
  36. data/spec/integrations/live_video_spec.rb +13 -11
  37. data/spec/integrations/report_spec.rb +16 -13
  38. data/spec/integrations/resource_spec.rb +93 -0
  39. data/spec/integrations/sdk_token_spec.rb +10 -6
  40. data/spec/integrations/webhook_spec.rb +56 -37
  41. data/spec/onfido/api_spec.rb +14 -25
  42. data/spec/onfido/connection_error_spec.rb +4 -2
  43. data/spec/onfido/options_spec.rb +39 -0
  44. data/spec/onfido/request_error_spec.rb +4 -2
  45. data/spec/spec_helper.rb +3 -5
  46. data/spec/support/fake_onfido_api.rb +77 -88
  47. data/spec/support/fixtures/applicant.json +21 -42
  48. data/spec/support/fixtures/check.json +4 -4
  49. data/spec/support/fixtures/checks.json +4 -4
  50. data/spec/support/fixtures/document.json +2 -2
  51. data/spec/support/fixtures/documents.json +8 -8
  52. data/spec/support/fixtures/extraction.json +23 -0
  53. data/spec/support/fixtures/live_photo.json +3 -3
  54. data/spec/support/fixtures/live_photos.json +6 -6
  55. data/spec/support/fixtures/live_video.json +3 -3
  56. data/spec/support/fixtures/live_videos.json +4 -4
  57. data/spec/support/fixtures/report.json +4 -4
  58. data/spec/support/fixtures/reports.json +8 -8
  59. data/spec/support/fixtures/webhook.json +6 -5
  60. data/spec/support/fixtures/webhooks.json +17 -12
  61. metadata +27 -65
  62. data/Rakefile +0 -1
  63. data/lib/onfido/configuration.rb +0 -47
  64. data/lib/onfido/null_logger.rb +0 -5
  65. data/lib/onfido/resources/report_type_group.rb +0 -11
  66. data/spec/integrations/exceptions_spec.rb +0 -74
  67. data/spec/integrations/report_type_group_spec.rb +0 -19
  68. data/spec/onfido/resource_spec.rb +0 -137
  69. data/spec/onfido_spec.rb +0 -84
  70. data/spec/support/fixtures/check_with_expanded_reports.json +0 -30
  71. data/spec/support/fixtures/checks_with_expanded_reports.json +0 -34
  72. data/spec/support/fixtures/report_type_group.json +0 -25
  73. data/spec/support/fixtures/report_type_groups.json +0 -30
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4a3a4754fe9f0896451df78eed5bf0af851ddffad2d4992e59d68fd5a3dc5e1d
4
- data.tar.gz: 4c51e178c11a4a60cda311c517803cd890d90c383b5fef10250e2064f372649b
3
+ metadata.gz: dac270e812885659e0a16e9a2a65c934de0b82c5df4f3422755665094e261d93
4
+ data.tar.gz: f2f66564aa340e239fde067fcff022d0b8db316fbb472e55d429d83dc051b4af
5
5
  SHA512:
6
- metadata.gz: be9b5b35882b37be5d70e0004191c10ba67c069ac99b86b7382abb6924b8e6d29f557340d4ff18e38f9bcd8f898f0ae60c57daea5ebac1037e781aa551fc38ae
7
- data.tar.gz: 5d2cd866567a2159a661ae3ec7af29d2d620b47f5ba44e681fb84e8ca1798c0c8b13c8eb0da829ccd9b46861038f0a89d6ccd1b4ec4de576b61d45fe78ea9c30
6
+ metadata.gz: 3d14985d14c7fab0ddd535154cdb9c67d5bc7c4b70405d70faec190e7fa87fd5efff3248264261137f5db97371aebc41dd2e6fc03118b2cca402f50285986420
7
+ data.tar.gz: 5f8af0136caaba37b6a5c37c5f912e01f89d5b79f03e53fa5eccb442cde2ca67dd5999228d815c13e8161bdc8ecdf4a134e8d24749eff4c17f2503e22fe332b3
@@ -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
- DisplayCopNames: true
5
- Exclude:
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
- Metrics/MethodLength:
28
- CountComments: false
29
- Max: 25
5
+ Layout/LineLength:
6
+ Max: 100
30
7
 
31
8
  Metrics/BlockLength:
32
9
  Exclude:
33
10
  - spec/**/*
34
11
 
35
- Metrics/AbcSize:
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
- before_install:
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,3 +1,31 @@
1
+ ## v2.0.1, 27 May 2021
2
+
3
+ - Remove onfido/null_logger
4
+
5
+ ## v2.0.0, 5 May 2021
6
+
7
+ - Remove global configuration, all configuration is now per `Onfido::API` instance
8
+ - Region is now a required argument (it previously defaulted to `:eu`)
9
+ - Support Onfido API version 3.1
10
+ - Drop support for Ruby 2.2 and 2.3
11
+
12
+ ## v1.1.1, 12 March 2021
13
+
14
+ - Send the postcode in the query string for the address picker endpoint
15
+
16
+ ## v1.1.0, 14 Aug 2020
17
+
18
+ - Add User-Agent header
19
+ - Add support for CA region
20
+ - Add extractions endpoint
21
+ - Add webhook deletion endpoint
22
+
23
+ ## v1.0.0, 13 Jan 2020
24
+
25
+ - Support Onfido API version 3
26
+ - Drop support for Onfido API version 2
27
+ - To upgrade from 0.15.0 see the v2 to v3 migration [guide](https://developers.onfido.com/guide/v2-to-v3-migration-guide)
28
+
1
29
  ## v0.15.0, 4 Feb 2019
2
30
 
3
31
  - Add Check#find_by_url method (@ctrlaltdylan)
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
  gemspec
3
5
 
data/LICENSE CHANGED
@@ -1,6 +1,7 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015 Hassle
3
+ Original work Copyright (c) 2015 Hassle
4
+ Modified work Copyright 2019 Onfido
4
5
 
5
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
7
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,198 +1,60 @@
1
1
  # Onfido
2
2
 
3
- A thin wrapper for Onfido's API.
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
- [![Build Status](https://travis-ci.org/hvssle/onfido.svg?branch=master)](https://travis-ci.org/hvssle/onfido)
6
+ [![Build Status](https://travis-ci.org/onfido/onfido-ruby.svg?branch=master)](https://travis-ci.org/onfido/onfido-ruby)
7
7
 
8
- This gem supports both `v1` and `v2` of the Onfido API. Refer to Onfido's [API documentation](https://onfido.com/documentation#introduction) for details of the expected requests and responses for both.
8
+ Documentation can be found at https://documentation.onfido.com
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.
9
11
 
10
12
  ## Installation
11
13
 
12
14
  Add this line to your application's Gemfile:
13
15
 
14
16
  ```ruby
15
- gem 'onfido', '~> 0.15.1'
17
+ gem 'onfido', '~> 2.0.1'
16
18
  ```
17
19
 
18
- 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.
19
-
20
- ## Configuration
21
-
22
- There are 6 configuration options:
23
-
24
- ```ruby
25
- Onfido.configure do |config|
26
- config.api_key = 'MY_API_KEY'
27
- config.api_version = 'v2'
28
- config.logger = Logger.new(STDOUT)
29
- config.open_timeout = 30
30
- config.read_timeout = 80
31
- config.region = nil
32
- end
33
- ```
34
-
35
- ### Regions
36
-
37
- The gem will use the default region if no region is specified.
20
+ ## Getting started
38
21
 
39
- To specify the US region do:
40
- `config.region = :us`
41
-
42
- See https://documentation.onfido.com/#regions for supported regions.
43
-
44
- ## Usage
45
-
46
- You can make API calls by using an instance of the `API` class:
22
+ Configure with your API token and region:
47
23
 
48
24
  ```ruby
49
- api = Onfido::API.new
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
+ )
50
30
  ```
51
31
 
52
- Alternatively, you can set an API key here instead of in the initializer:
53
-
54
- ```ruby
55
- api = Onfido::API.new(api_key: 'API_KEY')
56
- ```
57
-
58
- ### Resources
59
-
60
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.
61
33
 
62
- **Note:** *All param keys should be a symbol e.g. `{ type: 'express', reports: [{ name: 'identity' }] }`*
63
-
64
- #### Applicants
65
-
66
- Applicants are the object upon which Onfido checks are performed.
67
-
68
- ```ruby
69
- api.applicant.create(params) # => Creates an applicant
70
- api.applicant.update('applicant_id', params) # => Updates an applicant
71
- api.applicant.destroy('applicant_id') # => Schedule an applicant for deletion
72
- api.applicant.restore('applicant_id') # => Restore an applicant scheduled for deletion
73
- api.applicant.find('applicant_id') # => Finds a single applicant
74
- api.applicant.all # => Returns all applicants
75
- ```
76
-
77
- **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.
78
- See https://documentation.onfido.com/#delete-applicant for more information.
79
-
80
- #### Documents
81
-
82
- Documents provide supporting evidence for Onfido checks.
83
-
84
- ```ruby
85
- api.document.create('applicant_id', file: 'http://example.com', type: 'passport') # => Creates a document
86
- api.document.find('applicant_id', 'document_id') # => Finds a document
87
- api.document.download('applicant_id', 'document_id') # => Downloads a document as a binary data
88
- api.document.all('applicant_id') # => Returns all applicant's documents
89
- ```
90
-
91
- **Note:** The file parameter must be a `File`-like object which responds to `#read` and `#path`.
92
- Previous versions of this gem supported providing a URL to a file accessible over HTTP or a path
93
- to a file in the local filesystem. You should instead load the file yourself and then pass it in
94
- to `#create`.
95
-
96
- #### Live Photos
97
-
98
- Live Photos, like documents, can provide supporting evidence for Onfido checks.
99
-
100
- ```ruby
101
- api.live_photo.create('applicant_id', file: 'http://example.com')
102
- api.live_photo.find(applicant_id, live_photo_id) # => Finds a live photo
103
- api.live_photo.download(applicant_id, live_photo_id) # => Downloads a live photo as binary data
104
- api.live_photo.all(applicant_id) # => Returns all applicant's live photos
105
- ```
106
-
107
- **Note:** The file parameter must be a `File`-like object which responds to `#read` and `#path`.
108
- Previous versions of this gem supported providing a URL to a file accessible over HTTP or a path
109
- to a file in the local filesystem. You should instead load the file yourself and then pass it in
110
- to `#create`.
111
-
112
- #### Checks
113
-
114
- Checks are requests for Onfido to check an applicant, by commissioning one or
115
- more "reports" on them.
116
-
117
- ```ruby
118
- api.check.create('applicant_id', type: 'express', reports: [{ name: 'identity' }])
119
- api.check.find('applicant_id', 'check_id')
120
- api.check.find_by_url('applicants/a90e7a17-677a-49ab-a171-281f96c77bde/checks/c9f41bef-0610-4d2f-9982-ae9387876edc')
121
- api.check.resume('check_id')
122
- api.check.all('applicant_id')
123
- ```
124
-
125
- #### Reports
126
-
127
- Reports provide details of the results of some part of a "check". They are
128
- created when a check is created, so the Onfido API only provides support for
129
- finding and listing them. For paused reports specifically, additional support for resuming and
130
- cancelling reports is also available.
131
-
132
- ```ruby
133
- api.report.find('check_id', 'report_id')
134
- api.report.all('check_id')
135
- api.report.resume('check_id', 'report_id')
136
- api.report.cancel('check_id', 'report_id')
137
- ```
138
-
139
- #### Report Type Groups
140
-
141
- Report type groups provide a convenient way to group and organize different types of reports.
142
- The Onfido API only provides support for finding and listing them.
34
+ For example, to create an applicant:
143
35
 
144
36
  ```ruby
145
- api.report_type_group.find('report_type_group_id')
146
- api.report_type_group.all()
37
+ onfido.applicant.create(
38
+ first_name: 'Test',
39
+ last_name: 'Applicant'
40
+ )
147
41
  ```
148
42
 
149
- #### Address Lookups
43
+ Documentation and code examples can be found at https://documentation.onfido.com
150
44
 
151
- Onfido provides an address lookup service, to help ensure well-formatted
152
- addresses are provided when creating "applicants". To search for addresses
153
- by postcode, use:
45
+ ## Error Handling
154
46
 
155
- ```ruby
156
- api.address.all('SE1 4NG')
157
- ```
47
+ There are 3 classes of errors raised by the library, all of which subclass `Onfido::OnfidoError`:
158
48
 
159
- #### Webhook Endpoints
160
-
161
- Onfido allows you to set up and view your webhook endpoints via the API, as well
162
- as through the dashboard.
163
-
164
- ```ruby
165
- api.webhook.create(params) # => Creates a webhook endpoint
166
- api.webhook.find('webhook_id') # => Finds a single webhook endpoint
167
- api.webhook.all # => Returns all webhook endpoints
168
- ```
169
-
170
- #### SDK Tokens
171
-
172
- Onfido allows you to generate JSON Web Tokens via the API in order to authenticate
173
- with Onfido's [JavaScript SDK](https://github.com/onfido/onfido-sdk-ui).
174
-
175
- ```ruby
176
- api.sdk_token.create(applicant_id: 'applicant_id', referrer: 'referrer')
177
- ```
178
-
179
- ### Pagination
180
-
181
- All resources that support an `all` method also support pagination. By default,
182
- the first 20 records are fetched.
183
-
184
- ### Error Handling
185
-
186
- 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
187
50
  - `Onfido::ServerError` is raised whenever Onfido returns a `5xx` response
188
- - `Onfido::RequestError` is raised whenever Onfido returns any other kind of error
189
51
  - `Onfido::ConnectionError` is raised whenever a network error occurs (e.g., a timeout)
190
52
 
191
- All three 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 three are likely to be `nil`).
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`).
192
54
 
193
55
  ```ruby
194
56
  def create_applicant
195
- api.applicant.create(params)
57
+ onfido.applicant.create(params)
196
58
  rescue Onfido::RequestError => e
197
59
  e.type # => 'validation_error'
198
60
  e.fields # => { "email": { "messages": ["invalid format"] } }
@@ -200,15 +62,27 @@ rescue Onfido::RequestError => e
200
62
  end
201
63
  ```
202
64
 
203
- ## Webhooks
65
+ ## Other configuration
204
66
 
205
- 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-Signature` header.
67
+ Optional configuration options with their defaults:
206
68
 
207
- This provided signature [should](https://onfido.com/documentation#webhook-security) be compared to one you generate yourself with the token to check that a webhook is a genuine request from Onfido.
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.
208
82
 
209
83
  ```ruby
210
84
  if Onfido::Webhook.valid?(request.raw_post,
211
- request.headers["X-Signature"],
85
+ request.headers["X-SHA2-Signature"],
212
86
  ENV['ONFIDO_WEBHOOK_TOKEN'])
213
87
  process_webhook
214
88
  else
@@ -216,16 +90,16 @@ else
216
90
  end
217
91
  ```
218
92
 
219
- ## Roadmap
220
-
221
- - Improve test coverage with more scenarios
222
- - Add custom errors based on the response code
223
- - Improve pagination handling (use information passed in link header)
93
+ Read more at https://onfido.com/documentation#webhook-security
224
94
 
225
95
  ## Contributing
226
96
 
227
- 1. Fork it ( https://github.com/hvssle/onfido/fork )
97
+ 1. Fork it ( https://github.com/onfido/onfido-ruby/fork )
228
98
  2. Create your feature branch (`git checkout -b my-new-feature`)
229
99
  3. Commit your changes (`git commit -am 'Add some feature'`)
230
100
  4. Push to the branch (`git push origin my-new-feature`)
231
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