onfido 0.15.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -49
  3. data/.travis.yml +3 -10
  4. data/CHANGELOG.md +24 -0
  5. data/Gemfile +2 -0
  6. data/LICENSE +2 -1
  7. data/README.md +46 -172
  8. data/lib/onfido.rb +4 -3
  9. data/lib/onfido/api.rb +21 -15
  10. data/lib/onfido/errors/connection_error.rb +2 -0
  11. data/lib/onfido/errors/onfido_error.rb +2 -0
  12. data/lib/onfido/errors/request_error.rb +2 -0
  13. data/lib/onfido/errors/server_error.rb +2 -0
  14. data/lib/onfido/options.rb +38 -0
  15. data/lib/onfido/resource.rb +44 -61
  16. data/lib/onfido/resources/address.rb +3 -4
  17. data/lib/onfido/resources/applicant.rb +8 -6
  18. data/lib/onfido/resources/check.rb +15 -19
  19. data/lib/onfido/resources/document.rb +13 -11
  20. data/lib/onfido/resources/extraction.rb +11 -0
  21. data/lib/onfido/resources/live_photo.rb +11 -14
  22. data/lib/onfido/resources/live_video.rb +7 -8
  23. data/lib/onfido/resources/report.rb +10 -9
  24. data/lib/onfido/resources/sdk_token.rb +5 -5
  25. data/lib/onfido/resources/webhook.rb +15 -11
  26. data/lib/onfido/version.rb +3 -1
  27. data/onfido.gemspec +10 -12
  28. data/spec/integrations/address_spec.rb +5 -2
  29. data/spec/integrations/applicant_spec.rb +29 -42
  30. data/spec/integrations/check_spec.rb +28 -69
  31. data/spec/integrations/document_spec.rb +22 -19
  32. data/spec/integrations/extraction_spec.rb +23 -0
  33. data/spec/integrations/live_photo_spec.rb +18 -15
  34. data/spec/integrations/live_video_spec.rb +13 -11
  35. data/spec/integrations/report_spec.rb +16 -13
  36. data/spec/integrations/resource_spec.rb +93 -0
  37. data/spec/integrations/sdk_token_spec.rb +10 -6
  38. data/spec/integrations/webhook_spec.rb +56 -37
  39. data/spec/onfido/api_spec.rb +14 -25
  40. data/spec/onfido/connection_error_spec.rb +4 -2
  41. data/spec/onfido/options_spec.rb +39 -0
  42. data/spec/onfido/request_error_spec.rb +4 -2
  43. data/spec/spec_helper.rb +3 -5
  44. data/spec/support/fake_onfido_api.rb +77 -88
  45. data/spec/support/fixtures/applicant.json +21 -42
  46. data/spec/support/fixtures/check.json +4 -4
  47. data/spec/support/fixtures/checks.json +4 -4
  48. data/spec/support/fixtures/document.json +2 -2
  49. data/spec/support/fixtures/documents.json +8 -8
  50. data/spec/support/fixtures/extraction.json +23 -0
  51. data/spec/support/fixtures/live_photo.json +3 -3
  52. data/spec/support/fixtures/live_photos.json +6 -6
  53. data/spec/support/fixtures/live_video.json +3 -3
  54. data/spec/support/fixtures/live_videos.json +4 -4
  55. data/spec/support/fixtures/report.json +4 -4
  56. data/spec/support/fixtures/reports.json +8 -8
  57. data/spec/support/fixtures/webhook.json +6 -5
  58. data/spec/support/fixtures/webhooks.json +17 -12
  59. metadata +25 -65
  60. data/Rakefile +0 -1
  61. data/lib/onfido/configuration.rb +0 -47
  62. data/lib/onfido/null_logger.rb +0 -5
  63. data/lib/onfido/resources/report_type_group.rb +0 -11
  64. data/spec/integrations/exceptions_spec.rb +0 -74
  65. data/spec/integrations/report_type_group_spec.rb +0 -19
  66. data/spec/onfido/resource_spec.rb +0 -137
  67. data/spec/onfido_spec.rb +0 -84
  68. data/spec/support/fixtures/check_with_expanded_reports.json +0 -30
  69. data/spec/support/fixtures/checks_with_expanded_reports.json +0 -34
  70. data/spec/support/fixtures/report_type_group.json +0 -25
  71. 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: 94d4e590e003b1ff219091a7690385782a3aa1ef7ee46000f185cf183a81702e
4
- data.tar.gz: 1961655f50cdf2f8148e83310b2d0bbebd0c3139ed3de5b63f3c001d398b02d3
3
+ metadata.gz: e01591b4bd8952e983ea3f65ad8b534dcc43efa6e4243c33c340150771081b49
4
+ data.tar.gz: c40818067b6634ac7af1a0e4472163fbbd2538a462730d364b0b7de82e5de405
5
5
  SHA512:
6
- metadata.gz: 490a955c369dd6934ac60685ef628cc6a821b461efa13113b7e381aa5bd1a6bb958996d1ed2add552f661d18236112a541fb900b2c6a54e09ef9eaa37f2a1346
7
- data.tar.gz: 72d9cdadfc3f73c75464cbe7fe7cb36b764ac2c420fa7afb2268e2a5d31b9c1139d5829faa2d9e830a3bd7b02d2ec12203c66e80b80c92947a0be0f58166c7e8
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,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,27 @@
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
+
8
+ ## v1.1.1, 12 March 2021
9
+
10
+ - Send the postcode in the query string for the address picker endpoint
11
+
12
+ ## v1.1.0, 14 Aug 2020
13
+
14
+ - Add User-Agent header
15
+ - Add support for CA region
16
+ - Add extractions endpoint
17
+ - Add webhook deletion endpoint
18
+
19
+ ## v1.0.0, 13 Jan 2020
20
+
21
+ - Support Onfido API version 3
22
+ - Drop support for Onfido API version 2
23
+ - To upgrade from 0.15.0 see the v2 to v3 migration [guide](https://developers.onfido.com/guide/v2-to-v3-migration-guide)
24
+
1
25
  ## v0.15.0, 4 Feb 2019
2
26
 
3
27
  - 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.0'
17
+ gem 'onfido', '~> 2.0.0'
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(params[:payload][:object][:href])
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
data/lib/onfido.rb CHANGED
@@ -1,28 +1,29 @@
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'
17
19
  require 'onfido/resources/check'
18
20
  require 'onfido/resources/document'
21
+ require 'onfido/resources/extraction'
19
22
  require 'onfido/resources/live_photo'
20
23
  require 'onfido/resources/live_video'
21
24
  require 'onfido/resources/report'
22
- require 'onfido/resources/report_type_group'
23
25
  require 'onfido/resources/sdk_token'
24
26
  require 'onfido/resources/webhook'
25
27
 
26
28
  module Onfido
27
- extend Configuration
28
29
  end