onfido 1.1.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +5 -5
  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 +2 -8
  6. data/CHANGELOG.md +26 -1
  7. data/Gemfile +2 -0
  8. data/README.md +37 -148
  9. data/lib/onfido.rb +3 -3
  10. data/lib/onfido/api.rb +18 -12
  11. data/lib/onfido/errors/connection_error.rb +2 -0
  12. data/lib/onfido/errors/onfido_error.rb +2 -0
  13. data/lib/onfido/errors/request_error.rb +2 -0
  14. data/lib/onfido/errors/server_error.rb +2 -0
  15. data/lib/onfido/options.rb +38 -0
  16. data/lib/onfido/resource.rb +48 -59
  17. data/lib/onfido/resources/address.rb +3 -4
  18. data/lib/onfido/resources/applicant.rb +2 -0
  19. data/lib/onfido/resources/check.rb +6 -0
  20. data/lib/onfido/resources/document.rb +2 -0
  21. data/lib/onfido/resources/extraction.rb +2 -0
  22. data/lib/onfido/resources/live_photo.rb +2 -0
  23. data/lib/onfido/resources/live_video.rb +2 -0
  24. data/lib/onfido/resources/report.rb +2 -0
  25. data/lib/onfido/resources/sdk_token.rb +2 -0
  26. data/lib/onfido/resources/webhook.rb +4 -2
  27. data/lib/onfido/version.rb +3 -1
  28. data/onfido.gemspec +5 -6
  29. data/spec/integrations/address_spec.rb +4 -2
  30. data/spec/integrations/applicant_spec.rb +12 -7
  31. data/spec/integrations/check_spec.rb +17 -4
  32. data/spec/integrations/document_spec.rb +7 -3
  33. data/spec/integrations/extraction_spec.rb +6 -2
  34. data/spec/integrations/live_photo_spec.rb +7 -3
  35. data/spec/integrations/live_video_spec.rb +6 -1
  36. data/spec/integrations/report_spec.rb +6 -1
  37. data/spec/integrations/resource_spec.rb +106 -0
  38. data/spec/integrations/sdk_token_spec.rb +5 -1
  39. data/spec/integrations/webhook_spec.rb +28 -24
  40. data/spec/onfido/api_spec.rb +14 -25
  41. data/spec/onfido/connection_error_spec.rb +4 -2
  42. data/spec/onfido/options_spec.rb +39 -0
  43. data/spec/onfido/request_error_spec.rb +4 -2
  44. data/spec/spec_helper.rb +3 -5
  45. data/spec/support/fake_onfido_api.rb +63 -49
  46. data/spec/support/fixtures/applicant.json +1 -1
  47. data/spec/support/fixtures/check.json +1 -1
  48. data/spec/support/fixtures/checks.json +1 -1
  49. data/spec/support/fixtures/document.json +1 -1
  50. data/spec/support/fixtures/documents.json +2 -2
  51. data/spec/support/fixtures/live_photo.json +2 -2
  52. data/spec/support/fixtures/live_photos.json +4 -4
  53. data/spec/support/fixtures/live_video.json +2 -2
  54. data/spec/support/fixtures/live_videos.json +2 -2
  55. data/spec/support/fixtures/report.json +1 -1
  56. data/spec/support/fixtures/reports.json +2 -2
  57. data/spec/support/fixtures/webhook.json +1 -1
  58. data/spec/support/fixtures/webhooks.json +2 -2
  59. metadata +16 -33
  60. data/Rakefile +0 -1
  61. data/lib/onfido/configuration.rb +0 -47
  62. data/lib/onfido/null_logger.rb +0 -5
  63. data/spec/integrations/exceptions_spec.rb +0 -73
  64. data/spec/onfido/resource_spec.rb +0 -133
  65. data/spec/onfido_spec.rb +0 -83
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 8749aa43cbc394686f1ff769f0b0ada44c541a9c
4
- data.tar.gz: f6e314d3f734e8eb315f97daa6765c0904bec8db
2
+ SHA256:
3
+ metadata.gz: e0b036d234a60e209cbc230d2c4e59ae7cded8f49f8639b63f3d0589610043fc
4
+ data.tar.gz: 736290686f770587e2a270921d34a2a8b78015c2e3539be5a476980318314ad3
5
5
  SHA512:
6
- metadata.gz: f2db07995e16031cb9b04da83497400f082fb1fdac289761b46481ab83d283efbdf7bc12ac61508fa50583f081c53311c4dce8aa7cf90efda97d5c6bc4244435
7
- data.tar.gz: 3e41ed2d4988192d230b67382e78b19209684a059aec2af1ca875234b3bf7787f17dbcdbd6004ca1ad0df12b051061d9413afffc85a6739c519d9eccfc89c1a9
6
+ metadata.gz: afb5f59c5836aa78326f82adbcf05a3620a4bbce772e8f03a6b5e715550720eeaf511b267a9cbac5c800bec16edad0f7e6eba466d2bfbcd96746d8fc9f00efc2
7
+ data.tar.gz: 707e28800455819c2f2a1c1585f68a302d3d8e8e62ccc186838f37fc110345da8dcdd5310857ebe49e9f6ef218ae7122af1a4b9655e6356ace519c5ff42f17fd
@@ -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,19 +1,13 @@
1
1
  language: ruby
2
- cache: bundler
2
+ cache: bundler
3
3
 
4
4
  rvm:
5
- - 2.2
6
- - 2.3
7
5
  - 2.4
8
6
  - 2.5
9
7
  - 2.6
10
8
  - 2.7
9
+ - 3.0
11
10
 
12
11
  script:
13
12
  - bundle exec rubocop
14
13
  - bundle exec rspec spec
15
-
16
- # safelist
17
- branches:
18
- only:
19
- - master
data/CHANGELOG.md CHANGED
@@ -1,7 +1,32 @@
1
- ## v1.1.0, 6 Aug 2020
1
+ ## v2.1.0, 23 June 2021
2
+
3
+ - Support Onfido API version 3.2
4
+
5
+ ## v2.0.2, 10 June 2021
6
+
7
+ - Add error coverage for errors RestClient:BadGateway
8
+
9
+ ## v2.0.1, 27 May 2021
10
+
11
+ - Remove onfido/null_logger
12
+
13
+ ## v2.0.0, 5 May 2021
14
+
15
+ - Remove global configuration, all configuration is now per `Onfido::API` instance
16
+ - Region is now a required argument (it previously defaulted to `:eu`)
17
+ - Support Onfido API version 3.1
18
+ - Drop support for Ruby 2.2 and 2.3
19
+
20
+ ## v1.1.1, 12 March 2021
21
+
22
+ - Send the postcode in the query string for the address picker endpoint
23
+
24
+ ## v1.1.0, 14 Aug 2020
2
25
 
3
26
  - Add User-Agent header
4
27
  - Add support for CA region
28
+ - Add extractions endpoint
29
+ - Add webhook deletion endpoint
5
30
 
6
31
  ## v1.0.0, 13 Jan 2020
7
32
 
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/README.md CHANGED
@@ -1,180 +1,53 @@
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
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 only `v3` of Onfido's API from version `1.0.0` onwards. The latest version that supports `v2` of Onfido's API is `0.15.0`. `v1` of Onfido's API is deprecated.
8
+ Documentation can be found at https://documentation.onfido.com
9
9
 
10
- 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.
11
-
12
- Refer to Onfido's [API documentation](https://documentation.onfido.com) for details of the expected requests and responses.
10
+ This version uses Onfido API v3.2 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.
13
11
 
14
12
  ## Installation
15
13
 
16
14
  Add this line to your application's Gemfile:
17
15
 
18
16
  ```ruby
19
- gem 'onfido', '~> 1.1.0'
17
+ gem 'onfido', '~> 2.0.1'
20
18
  ```
21
19
 
22
- ## Configuration
20
+ ## Getting started
23
21
 
24
- There are 5 configuration options:
22
+ Configure with your API token and region:
25
23
 
26
24
  ```ruby
27
- Onfido.configure do |config|
28
- config.api_key = '<YOUR_API_KEY>'
29
- config.logger = Logger.new(STDOUT)
30
- config.open_timeout = 30
31
- config.read_timeout = 80
32
- config.region = nil
33
- end
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
+ )
34
30
  ```
35
31
 
36
- ### Regions
37
-
38
- The gem will use the default region if no region is specified.
39
-
40
- To specify the US region do:
41
- `config.region = :us`
42
-
43
- To specify the CA region do:
44
- `config.region = :ca`
45
-
46
- See https://documentation.onfido.com/#regions for supported regions.
47
-
48
- ## Usage
49
-
50
- You can make API calls by using an instance of the `API` class:
51
-
52
- ```ruby
53
- onfido = Onfido::API.new
54
- ```
55
-
56
- You can also set an API key as follows, instead of in the initializer configuration:
57
-
58
- ```ruby
59
- onfido = Onfido::API.new(api_key: '<YOUR_API_KEY>')
60
- ```
61
-
62
- ### Resources
63
-
64
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.
65
33
 
66
- **Note:** *All param keys should be symbols e.g. `{ report_names: ['document'] }`*
67
-
68
- #### Applicants
69
-
70
- Applicants are the object upon which Onfido checks are performed.
71
-
72
- ```ruby
73
- onfido.applicant.create(params) # => Creates an applicant
74
- onfido.applicant.update('<APPLICANT_ID>', params) # => Updates an applicant
75
- onfido.applicant.destroy('<APPLICANT_ID>') # => Schedule an applicant for deletion
76
- onfido.applicant.restore('<APPLICANT_ID>') # => Restore an applicant scheduled for deletion
77
- onfido.applicant.find('<APPLICANT_ID>') # => Finds a single applicant
78
- onfido.applicant.all # => Returns all applicants
79
- ```
80
-
81
- **Note:** Calling `onfido.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.
82
- See https://documentation.onfido.com/#delete-applicant for more information.
83
-
84
- #### Documents
85
-
86
- Some report types require identity documents (passport, driving licence etc.) in order to be processed.
34
+ For example, to create an applicant:
87
35
 
88
36
  ```ruby
89
- onfido.document.create(applicant_id: '<APPLICANT_ID>', file: <FILE>, type: 'passport') # => Creates a document
90
- onfido.document.find('<DOCUMENT_ID>') # => Finds a document
91
- onfido.document.download('<DOCUMENT_ID>') # => Downloads a document as a binary data
92
- onfido.document.all('<APPLICANT_ID>') # => Returns all documents belonging to an applicant
37
+ onfido.applicant.create(
38
+ first_name: 'Test',
39
+ last_name: 'Applicant'
40
+ )
93
41
  ```
94
42
 
95
- **Note:** The file parameter must be a `File`-like object which responds to `#read` and `#path`.
96
- Previous versions of this gem supported providing a URL to a file accessible over HTTP or a path
97
- to a file in the local filesystem. You should instead load the file yourself and then pass it in
98
- to `#create`.
99
-
100
- See https://documentation.onfido.com/#document-types for example document types.
101
-
102
- #### Live Photos
103
-
104
- Live photos are images of the applicant’s face, typically taken at the same time as documents are provided. These photos are used to perform Facial Similarity Photo reports on the applicant.
105
-
106
- ```ruby
107
- onfido.live_photo.create(applicant_id: '<APPLICANT_ID>', file: <FILE>) # => Creates a live photo
108
- onfido.live_photo.find('<LIVE_PHOTO_ID>') # => Finds a live photo
109
- onfido.live_photo.download('<LIVE_PHOTO_ID>') # => Downloads a live photo as binary data
110
- onfido.live_photo.all('<APPLICANT_ID>') # => Returns all live photos belonging to an applicant
111
- ```
112
-
113
- **Note:** The file parameter must be a `File`-like object which responds to `#read` and `#path`.
114
- Previous versions of this gem supported providing a URL to a file accessible over HTTP or a path
115
- to a file in the local filesystem. You should instead load the file yourself and then pass it in
116
- to `#create`.
117
-
118
- #### Checks
43
+ Documentation and code examples can be found at https://documentation.onfido.com
119
44
 
120
- Checks are performed on an applicant. Depending on the type of check you wish to perform, different information will be required when you create an applicant. A check consists of one or more reports.
121
-
122
- ```ruby
123
- onfido.check.create(applicant_id: '<APPLICANT_ID>', report_names: ['document', 'facial_similarity_photo']) # => Creates a check
124
- onfido.check.find('<CHECK_ID>') # => Finds a check
125
- onfido.check.resume('<CHECK_ID>') # => Resumes a paused check
126
- onfido.check.all('<APPLICANT_ID>') # => Returns all an applicant's checks
127
- ```
128
-
129
- #### Reports
130
-
131
- Reports provide details of the results of some part of a check. They are
132
- created when a check is created, so the Onfido API only provides support for
133
- finding and listing them. For paused reports specifically, additional support for resuming and
134
- cancelling reports is also available.
135
-
136
- ```ruby
137
- onfido.report.find('<REPORT_ID>') # => Finds a report
138
- onfido.report.all('<CHECK_ID>') # => Returns all the reports in a check
139
- onfido.report.resume('<REPORT_ID>') # => Resumes a paused report
140
- onfido.report.cancel('<REPORT_ID>') # => Cancels a paused report
141
- ```
142
-
143
- #### Address Lookups
144
-
145
- Onfido provides an address lookup service, to help ensure well-formatted
146
- addresses are provided when creating applicants. To search for addresses
147
- by postcode, use:
148
-
149
- ```ruby
150
- onfido.address.all('SE1 4NG') # => Returns all addresses in a given postcode
151
- ```
152
-
153
- #### Webhook Endpoints
154
-
155
- Onfido allows you to set up and view your webhook endpoints via the API, as well
156
- as through the dashboard.
157
-
158
- ```ruby
159
- onfido.webhook.create(url: "https://webhook.url", events: ['report.completed, check.completed']) # => Registers a webhook endpoint
160
- onfido.webhook.find('<WEBHOOK_ID>') # => Finds a single webhook endpoint
161
- onfido.webhook.all # => Returns all webhook endpoints
162
- ```
163
-
164
- #### SDK Tokens
165
-
166
- Onfido allows you to generate JSON Web Tokens via the API in order to authenticate
167
- with Onfido's [JavaScript SDK](https://github.com/onfido/onfido-sdk-ui).
168
-
169
- ```ruby
170
- onfido.sdk_token.create(applicant_id: 'applicant_id', referrer: 'referrer') # => Creates a JWT
171
- ```
172
-
173
- ### Error Handling
45
+ ## Error Handling
174
46
 
175
47
  There are 3 classes of errors raised by the library, all of which subclass `Onfido::OnfidoError`:
48
+
49
+ - `Onfido::RequestError` is raised whenever Onfido returns a `4xx` response
176
50
  - `Onfido::ServerError` is raised whenever Onfido returns a `5xx` response
177
- - `Onfido::RequestError` is raised whenever Onfido returns any other kind of error
178
51
  - `Onfido::ConnectionError` is raised whenever a network error occurs (e.g., a timeout)
179
52
 
180
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`).
@@ -189,7 +62,19 @@ rescue Onfido::RequestError => e
189
62
  end
190
63
  ```
191
64
 
192
- ## Webhooks
65
+ ## Other configuration
66
+
67
+ Optional configuration options with their defaults:
68
+
69
+ ```ruby
70
+ onfido = Onfido::API.new(
71
+ # ...
72
+ open_timeout: 10,
73
+ read_timeout: 30
74
+ )
75
+ ```
76
+
77
+ ## Verifying webhooks
193
78
 
194
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.
195
80
 
@@ -214,3 +99,7 @@ Read more at https://onfido.com/documentation#webhook-security
214
99
  3. Commit your changes (`git commit -am 'Add some feature'`)
215
100
  4. Push to the branch (`git push origin my-new-feature`)
216
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
data/lib/onfido.rb CHANGED
@@ -1,16 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'json'
2
4
  require 'rack'
3
5
  require 'rest-client'
4
6
  require 'openssl'
5
7
 
6
8
  require 'onfido/version'
7
- require 'onfido/configuration'
8
9
  require 'onfido/errors/onfido_error'
9
10
  require 'onfido/errors/request_error'
10
11
  require 'onfido/errors/server_error'
11
12
  require 'onfido/errors/connection_error'
12
- require 'onfido/null_logger'
13
13
  require 'onfido/api'
14
+ require 'onfido/options'
14
15
  require 'onfido/resource'
15
16
  require 'onfido/resources/address'
16
17
  require 'onfido/resources/applicant'
@@ -24,5 +25,4 @@ require 'onfido/resources/sdk_token'
24
25
  require 'onfido/resources/webhook'
25
26
 
26
27
  module Onfido
27
- extend Configuration
28
28
  end