onfido 1.1.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -49
  3. data/.travis.yml +2 -8
  4. data/CHANGELOG.md +7 -0
  5. data/Gemfile +2 -0
  6. data/README.md +37 -148
  7. data/lib/onfido.rb +3 -2
  8. data/lib/onfido/api.rb +18 -12
  9. data/lib/onfido/errors/connection_error.rb +2 -0
  10. data/lib/onfido/errors/onfido_error.rb +2 -0
  11. data/lib/onfido/errors/request_error.rb +2 -0
  12. data/lib/onfido/errors/server_error.rb +2 -0
  13. data/lib/onfido/options.rb +38 -0
  14. data/lib/onfido/resource.rb +45 -59
  15. data/lib/onfido/resources/address.rb +2 -0
  16. data/lib/onfido/resources/applicant.rb +2 -0
  17. data/lib/onfido/resources/check.rb +6 -0
  18. data/lib/onfido/resources/document.rb +2 -0
  19. data/lib/onfido/resources/extraction.rb +2 -0
  20. data/lib/onfido/resources/live_photo.rb +2 -0
  21. data/lib/onfido/resources/live_video.rb +2 -0
  22. data/lib/onfido/resources/report.rb +2 -0
  23. data/lib/onfido/resources/sdk_token.rb +2 -0
  24. data/lib/onfido/resources/webhook.rb +4 -2
  25. data/lib/onfido/version.rb +3 -1
  26. data/onfido.gemspec +5 -6
  27. data/spec/integrations/address_spec.rb +4 -2
  28. data/spec/integrations/applicant_spec.rb +12 -7
  29. data/spec/integrations/check_spec.rb +17 -4
  30. data/spec/integrations/document_spec.rb +7 -3
  31. data/spec/integrations/extraction_spec.rb +6 -2
  32. data/spec/integrations/live_photo_spec.rb +7 -3
  33. data/spec/integrations/live_video_spec.rb +6 -1
  34. data/spec/integrations/report_spec.rb +6 -1
  35. data/spec/integrations/resource_spec.rb +93 -0
  36. data/spec/integrations/sdk_token_spec.rb +5 -1
  37. data/spec/integrations/webhook_spec.rb +28 -24
  38. data/spec/onfido/api_spec.rb +14 -25
  39. data/spec/onfido/connection_error_spec.rb +4 -2
  40. data/spec/onfido/options_spec.rb +39 -0
  41. data/spec/onfido/request_error_spec.rb +4 -2
  42. data/spec/spec_helper.rb +3 -5
  43. data/spec/support/fake_onfido_api.rb +63 -49
  44. data/spec/support/fixtures/applicant.json +1 -1
  45. data/spec/support/fixtures/check.json +1 -1
  46. data/spec/support/fixtures/checks.json +1 -1
  47. data/spec/support/fixtures/document.json +1 -1
  48. data/spec/support/fixtures/documents.json +2 -2
  49. data/spec/support/fixtures/live_photo.json +2 -2
  50. data/spec/support/fixtures/live_photos.json +4 -4
  51. data/spec/support/fixtures/live_video.json +2 -2
  52. data/spec/support/fixtures/live_videos.json +2 -2
  53. data/spec/support/fixtures/report.json +1 -1
  54. data/spec/support/fixtures/reports.json +2 -2
  55. data/spec/support/fixtures/webhook.json +1 -1
  56. data/spec/support/fixtures/webhooks.json +2 -2
  57. metadata +11 -29
  58. data/Rakefile +0 -1
  59. data/lib/onfido/configuration.rb +0 -47
  60. data/lib/onfido/null_logger.rb +0 -5
  61. data/spec/integrations/exceptions_spec.rb +0 -72
  62. data/spec/onfido/resource_spec.rb +0 -133
  63. data/spec/onfido_spec.rb +0 -83
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5402f96702de9c0251f8c92ac14739b1cf54ad9a5336cf63c7088e4cc45dc0ae
4
- data.tar.gz: 89c7091cf1059f7eb4db9d96ae6c8ace2ca7176961524ba886b12ba3969cf462
3
+ metadata.gz: e01591b4bd8952e983ea3f65ad8b534dcc43efa6e4243c33c340150771081b49
4
+ data.tar.gz: c40818067b6634ac7af1a0e4472163fbbd2538a462730d364b0b7de82e5de405
5
5
  SHA512:
6
- metadata.gz: 6dce59eeee514ce3371b8c03367f7e2c772d26dfe57231b4f49c13a3073ca233b4089798ee7e3a7e451b2e0b7e64d035f7ee4307bb902876b160053107652664
7
- data.tar.gz: 92dd31829e491e612556caaf098dba388d701dfade3e755625e2199d2fbb58eaa5f621f1bdc9b8a8c95adf4753b22bb740430933e7c6b4789ed9ff8388485d44
6
+ metadata.gz: 3774da7d757f4e3a48e1fecd437792d7dc69e39bb765b5828383b84ee8ecf508504deddb1cbd1770c600e01be3d610619049f7cbe1aa6b78113c5c699313c768
7
+ data.tar.gz: d27a782d5304688d4437ab8bf5d7218c25396502e71e802bf9af8d70b5ff55aaf59f2dafc5ad458e37db54614af769104f022aca4ff11dc0b9c42d200dabd9c4
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,3 +1,10 @@
1
+ ## v2.0.0, 5 May 2021
2
+
3
+ - Remove global configuration, all configuration is now per `Onfido::API` instance
4
+ - Region is now a required argument (it previously defaulted to `:eu`)
5
+ - Support Onfido API version 3.1
6
+ - Drop support for Ruby 2.2 and 2.3
7
+
1
8
  ## v1.1.1, 12 March 2021
2
9
 
3
10
  - Send the postcode in the query string for the address picker endpoint
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.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.
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.1'
17
+ gem 'onfido', '~> 2.0.0'
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,18 @@
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
13
  require 'onfido/null_logger'
13
14
  require 'onfido/api'
15
+ require 'onfido/options'
14
16
  require 'onfido/resource'
15
17
  require 'onfido/resources/address'
16
18
  require 'onfido/resources/applicant'
@@ -24,5 +26,4 @@ require 'onfido/resources/sdk_token'
24
26
  require 'onfido/resources/webhook'
25
27
 
26
28
  module Onfido
27
- extend Configuration
28
29
  end
data/lib/onfido/api.rb CHANGED
@@ -1,47 +1,53 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Onfido
2
4
  class API
3
- def initialize(options = {})
4
- @api_key = options[:api_key]
5
+ def initialize(api_key:, region:, **extra_options)
6
+ @options = Onfido::Options.new(api_key: api_key, region: region, **extra_options)
5
7
  end
6
8
 
7
9
  def applicant
8
- Onfido::Applicant.new(@api_key)
10
+ @applicant ||= Onfido::Applicant.new(options)
9
11
  end
10
12
 
11
13
  def check
12
- Onfido::Check.new(@api_key)
14
+ @check ||= Onfido::Check.new(options)
13
15
  end
14
16
 
15
17
  def document
16
- Onfido::Document.new(@api_key)
18
+ @document ||= Onfido::Document.new(options)
17
19
  end
18
20
 
19
21
  def live_photo
20
- Onfido::LivePhoto.new(@api_key)
22
+ @live_photo ||= Onfido::LivePhoto.new(options)
21
23
  end
22
24
 
23
25
  def live_video
24
- Onfido::LiveVideo.new(@api_key)
26
+ @live_video ||= Onfido::LiveVideo.new(options)
25
27
  end
26
28
 
27
29
  def report
28
- Onfido::Report.new(@api_key)
30
+ @report ||= Onfido::Report.new(options)
29
31
  end
30
32
 
31
33
  def sdk_token
32
- Onfido::SdkToken.new(@api_key)
34
+ @sdk_token ||= Onfido::SdkToken.new(options)
33
35
  end
34
36
 
35
37
  def webhook
36
- Onfido::Webhook.new(@api_key)
38
+ @webhook ||= Onfido::Webhook.new(options)
37
39
  end
38
40
 
39
41
  def address
40
- Onfido::Address.new(@api_key)
42
+ @address ||= Onfido::Address.new(options)
41
43
  end
42
44
 
43
45
  def extraction
44
- Onfido::Extraction.new(@api_key)
46
+ @extraction ||= Onfido::Extraction.new(options)
45
47
  end
48
+
49
+ private
50
+
51
+ attr_reader :options
46
52
  end
47
53
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Onfido
2
4
  class ConnectionError < OnfidoError
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Onfido
2
4
  class OnfidoError < StandardError
3
5
  attr_accessor :response_code, :response_body