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
@@ -4,7 +4,7 @@
4
4
  "created_at": "2019-11-23T13:50:45Z",
5
5
  "status": "in_progress",
6
6
  "result": "pending",
7
- "href": "/v3/reports/6951786-123123-422221",
7
+ "href": "/v3.2/reports/6951786-123123-422221",
8
8
  "breakdown": {},
9
9
  "properties": {}
10
10
  }
@@ -6,7 +6,7 @@
6
6
  "created_at": "2019-11-23T13:50:45Z",
7
7
  "status": "in_progress",
8
8
  "result": "pending",
9
- "href": "/v3/reports/6951786-123123-422221",
9
+ "href": "/v3.2/reports/6951786-123123-422221",
10
10
  "breakdown": {},
11
11
  "properties": {}
12
12
  },
@@ -16,7 +16,7 @@
16
16
  "created_at": "2019-11-23T13:50:45Z",
17
17
  "status": "in_progress",
18
18
  "result": "pending",
19
- "href": "/v3/reports/6951786-123123-316712",
19
+ "href": "/v3.2/reports/6951786-123123-316712",
20
20
  "breakdown": {},
21
21
  "properties": {}
22
22
  }
@@ -3,7 +3,7 @@
3
3
  "url": "https://webhookendpoint.url",
4
4
  "token": "yV85IsmuYwmjQGlZ",
5
5
  "enabled": true,
6
- "href": "/v3/webhooks/fcb73186-0733-4f6f-9c57-d9d5ef979443",
6
+ "href": "/v3.2/webhooks/fcb73186-0733-4f6f-9c57-d9d5ef979443",
7
7
  "environments": [
8
8
  "live"
9
9
  ],
@@ -4,7 +4,7 @@
4
4
  "id": "dd0a89e4-d44e-417a-aec4-01137d01ae59",
5
5
  "url": "https://demo.com",
6
6
  "enabled":false,
7
- "href": "/v3/webhooks/dd0a89e4-d44e-417a-aec4-01137d01ae59",
7
+ "href": "/v3.2/webhooks/dd0a89e4-d44e-417a-aec4-01137d01ae59",
8
8
  "environments": [
9
9
  "live"
10
10
  ],
@@ -18,7 +18,7 @@
18
18
  "id": "bfc727a8-f7bf-4073-b123-ed70a70f58e5",
19
19
  "url": "https://demo2.com",
20
20
  "enabled": true,
21
- "href": "/v3/webhooks/bfc727a8-f7bf-4073-b123-ed70a70f58e5",
21
+ "href": "/v3.2/webhooks/bfc727a8-f7bf-4073-b123-ed70a70f58e5",
22
22
  "environments": [
23
23
  "live"
24
24
  ],
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onfido
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Onfido
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-14 00:00:00.000000000 Z
11
+ date: 2021-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rake
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '12.0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '12.0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: rspec
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -58,14 +44,14 @@ dependencies:
58
44
  requirements:
59
45
  - - "~>"
60
46
  - !ruby/object:Gem::Version
61
- version: 0.57.0
47
+ version: '1.11'
62
48
  type: :development
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
52
  - - "~>"
67
53
  - !ruby/object:Gem::Version
68
- version: 0.57.0
54
+ version: '1.11'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: sinatra
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -131,6 +117,8 @@ executables: []
131
117
  extensions: []
132
118
  extra_rdoc_files: []
133
119
  files:
120
+ - ".github/workflows/gem-push.yml"
121
+ - ".github/workflows/ruby.yml"
134
122
  - ".gitignore"
135
123
  - ".rspec"
136
124
  - ".rubocop.yml"
@@ -139,15 +127,13 @@ files:
139
127
  - Gemfile
140
128
  - LICENSE
141
129
  - README.md
142
- - Rakefile
143
130
  - lib/onfido.rb
144
131
  - lib/onfido/api.rb
145
- - lib/onfido/configuration.rb
146
132
  - lib/onfido/errors/connection_error.rb
147
133
  - lib/onfido/errors/onfido_error.rb
148
134
  - lib/onfido/errors/request_error.rb
149
135
  - lib/onfido/errors/server_error.rb
150
- - lib/onfido/null_logger.rb
136
+ - lib/onfido/options.rb
151
137
  - lib/onfido/resource.rb
152
138
  - lib/onfido/resources/address.rb
153
139
  - lib/onfido/resources/applicant.rb
@@ -165,18 +151,17 @@ files:
165
151
  - spec/integrations/applicant_spec.rb
166
152
  - spec/integrations/check_spec.rb
167
153
  - spec/integrations/document_spec.rb
168
- - spec/integrations/exceptions_spec.rb
169
154
  - spec/integrations/extraction_spec.rb
170
155
  - spec/integrations/live_photo_spec.rb
171
156
  - spec/integrations/live_video_spec.rb
172
157
  - spec/integrations/report_spec.rb
158
+ - spec/integrations/resource_spec.rb
173
159
  - spec/integrations/sdk_token_spec.rb
174
160
  - spec/integrations/webhook_spec.rb
175
161
  - spec/onfido/api_spec.rb
176
162
  - spec/onfido/connection_error_spec.rb
163
+ - spec/onfido/options_spec.rb
177
164
  - spec/onfido/request_error_spec.rb
178
- - spec/onfido/resource_spec.rb
179
- - spec/onfido_spec.rb
180
165
  - spec/spec_helper.rb
181
166
  - spec/support/fake_onfido_api.rb
182
167
  - spec/support/fixtures/4xx_response.json
@@ -203,7 +188,7 @@ homepage: http://github.com/onfido/onfido-ruby
203
188
  licenses:
204
189
  - MIT
205
190
  metadata: {}
206
- post_install_message:
191
+ post_install_message:
207
192
  rdoc_options: []
208
193
  require_paths:
209
194
  - lib
@@ -211,16 +196,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
211
196
  requirements:
212
197
  - - ">="
213
198
  - !ruby/object:Gem::Version
214
- version: 2.2.0
199
+ version: 2.4.0
215
200
  required_rubygems_version: !ruby/object:Gem::Requirement
216
201
  requirements:
217
202
  - - ">="
218
203
  - !ruby/object:Gem::Version
219
204
  version: '0'
220
205
  requirements: []
221
- rubyforge_project:
222
- rubygems_version: 2.4.5.5
223
- signing_key:
206
+ rubygems_version: 3.0.3.1
207
+ signing_key:
224
208
  specification_version: 4
225
209
  summary: A wrapper for Onfido API
226
210
  test_files:
@@ -228,18 +212,17 @@ test_files:
228
212
  - spec/integrations/applicant_spec.rb
229
213
  - spec/integrations/check_spec.rb
230
214
  - spec/integrations/document_spec.rb
231
- - spec/integrations/exceptions_spec.rb
232
215
  - spec/integrations/extraction_spec.rb
233
216
  - spec/integrations/live_photo_spec.rb
234
217
  - spec/integrations/live_video_spec.rb
235
218
  - spec/integrations/report_spec.rb
219
+ - spec/integrations/resource_spec.rb
236
220
  - spec/integrations/sdk_token_spec.rb
237
221
  - spec/integrations/webhook_spec.rb
238
222
  - spec/onfido/api_spec.rb
239
223
  - spec/onfido/connection_error_spec.rb
224
+ - spec/onfido/options_spec.rb
240
225
  - spec/onfido/request_error_spec.rb
241
- - spec/onfido/resource_spec.rb
242
- - spec/onfido_spec.rb
243
226
  - spec/spec_helper.rb
244
227
  - spec/support/fake_onfido_api.rb
245
228
  - spec/support/fixtures/4xx_response.json
data/Rakefile DELETED
@@ -1 +0,0 @@
1
- require 'bundler/gem_tasks'
@@ -1,47 +0,0 @@
1
- module Onfido
2
- module Configuration
3
- REGION_HOSTS = {
4
- us: "api.us.onfido.com",
5
- ca: "api.ca.onfido.com"
6
- }.freeze
7
-
8
- attr_accessor :api_key, :region, :open_timeout, :read_timeout
9
-
10
- def self.extended(base)
11
- base.reset
12
- end
13
-
14
- def configure
15
- yield self
16
- end
17
-
18
- def reset
19
- self.api_key = nil
20
- self.region = nil
21
- self.open_timeout = 30
22
- self.read_timeout = 80
23
- RestClient.log = nil
24
- end
25
-
26
- def logger=(log)
27
- unless log.respond_to?(:<<)
28
- raise "#{log.class} doesn't seem to behave like a logger!"
29
- end
30
-
31
- RestClient.log = log
32
- end
33
-
34
- def logger
35
- RestClient.log ||= NullLogger.new
36
- end
37
-
38
- def endpoint
39
- region_host = region ? REGION_HOSTS[region.downcase.to_sym] : "api.onfido.com"
40
- unless region_host
41
- raise "The region \"#{region.downcase}\" is not currently supported"
42
- end
43
-
44
- "https://#{region_host}/v3/"
45
- end
46
- end
47
- end
@@ -1,5 +0,0 @@
1
- module Onfido
2
- class NullLogger
3
- def <<(*args); end
4
- end
5
- end
@@ -1,73 +0,0 @@
1
- describe Onfido::Resource do
2
- let(:resource) { described_class.new }
3
- let(:api_key) { 'some_key' }
4
- let(:payload) { { postcode: 'SE1 4NG' } }
5
-
6
- before { allow(Onfido).to receive(:api_key).and_return(api_key) }
7
-
8
- context '4xx response' do
9
- it 'raises a custom error' do
10
- path = '4xx_response'
11
-
12
- expect { resource.get(path: path, payload: payload) }.
13
- to raise_error(Onfido::RequestError, 'Something went wrong')
14
- end
15
- end
16
-
17
- context 'unexpected error format' do
18
- it 'raises a custom error' do
19
- path = 'unexpected_error_format'
20
-
21
- expect { resource.get(path: path, payload: payload) }.
22
- to raise_error(Onfido::RequestError, /response code was 400/)
23
- end
24
- end
25
-
26
- context 'unparseable JSON 5xx' do
27
- it 'raises a server error' do
28
- path = 'unparseable_response'
29
-
30
- expect { resource.get(path: path, payload: payload) }.
31
- to raise_error(Onfido::ServerError, /response code was 504/)
32
- end
33
- end
34
-
35
- context 'timeout' do
36
- before do
37
- allow(RestClient::Request).
38
- to receive(:execute).
39
- and_raise(RestClient::RequestTimeout)
40
- end
41
-
42
- it 'raises a ConnectionError' do
43
- expect { resource.get(path: Onfido.endpoint, payload: payload) }.
44
- to raise_error(Onfido::ConnectionError, /Could not connect/)
45
- end
46
- end
47
-
48
- context 'broken connection' do
49
- before do
50
- allow(RestClient::Request).
51
- to receive(:execute).
52
- and_raise(RestClient::ServerBrokeConnection)
53
- end
54
-
55
- it 'raises a ConnectionError' do
56
- expect { resource.get(path: Onfido.endpoint, payload: payload) }.
57
- to raise_error(Onfido::ConnectionError, /connection to the server/)
58
- end
59
- end
60
-
61
- context "bad SSL certificate" do
62
- before do
63
- allow(RestClient::Request).
64
- to receive(:execute).
65
- and_raise(RestClient::SSLCertificateNotVerified.new(nil))
66
- end
67
-
68
- it 'raises a ConnectionError' do
69
- expect { resource.get(path: Onfido.endpoint, payload: payload) }.
70
- to raise_error(Onfido::ConnectionError, /SSL certificate/)
71
- end
72
- end
73
- end
@@ -1,133 +0,0 @@
1
- require 'onfido/errors/connection_error'
2
-
3
- describe Onfido::Resource do
4
- subject(:resource) { described_class.new }
5
-
6
- let(:endpoint) { 'https://api.onfido.com/v3/' }
7
- let(:path) { 'addresses/pick' }
8
- let(:url) { endpoint + path }
9
- let(:payload) { { postcode: 'SE1 4NG' } }
10
- let(:api_key) { 'some_key' }
11
-
12
- let(:response) do
13
- {
14
- 'addresses' => [
15
- {
16
- 'street' => 'Main Street',
17
- 'town' => 'London',
18
- 'postcode' => 'SW4 6EH',
19
- 'country' => 'GBR'
20
- }
21
- ]
22
- }
23
- end
24
-
25
- before { allow(Onfido).to receive(:endpoint).and_return(endpoint) }
26
- before { allow(Onfido).to receive(:api_key).and_return(api_key) }
27
-
28
- describe '#method_missing' do
29
- %i(patch).each do |method|
30
- context "for unsupported HTTP method: #{method}" do
31
- it 'raises an error' do
32
- expect do
33
- resource.public_send(method, path: endpoint)
34
- end.to raise_error(NoMethodError)
35
- end
36
- end
37
- end
38
- end
39
-
40
- describe "API key" do
41
- subject(:resource) { described_class.new(specific_api_key) }
42
-
43
- before do
44
- expect(RestClient::Request).to receive(:execute).with(
45
- url: url,
46
- payload: Rack::Utils.build_query(payload),
47
- method: :get,
48
- headers: resource.send(:headers),
49
- open_timeout: 30,
50
- timeout: 80
51
- ).and_call_original
52
-
53
- WebMock.stub_request(:get, url).
54
- to_return(body: response.to_json, status: 200)
55
- end
56
-
57
- context "when using a specific key" do
58
- let(:specific_api_key) { "specific_key" }
59
-
60
- it "uses that key when making the request" do
61
- resource.get(path: path, payload: payload)
62
-
63
- expect(WebMock).to have_requested(:get, url).with(
64
- headers: {
65
- 'Authorization' => "Token token=#{specific_api_key}",
66
- 'Accept' => "application/json",
67
- 'User-Agent' => "onfido-ruby/#{Onfido::VERSION}"
68
- }
69
- )
70
- end
71
- end
72
-
73
- context "when not using a specific key" do
74
- let(:specific_api_key) { nil }
75
-
76
- it "uses the general config key when making the request" do
77
- resource.get(path: path, payload: payload)
78
-
79
- expect(WebMock).to have_requested(:get, url).with(
80
- headers: {
81
- 'Authorization' => "Token token=#{api_key}",
82
- 'Accept' => "application/json",
83
- 'User-Agent' => "onfido-ruby/#{Onfido::VERSION}"
84
- }
85
- )
86
- end
87
- end
88
- end
89
-
90
- describe "valid http methods" do
91
- %i(get post put delete).each do |method|
92
- context "for supported HTTP method: #{method}" do
93
- context "with a success response" do
94
- before do
95
- expect(RestClient::Request).to receive(:execute).
96
- with(
97
- url: url,
98
- payload: Rack::Utils.build_query(payload),
99
- method: method,
100
- headers: resource.send(:headers),
101
- open_timeout: 30,
102
- timeout: 80
103
- ).and_call_original
104
-
105
- WebMock.stub_request(method, url).
106
- to_return(body: response.to_json,
107
- status: 200,
108
- headers: { "Content-Type" => "application/json" })
109
- end
110
-
111
- it 'makes a request to an endpoint' do
112
- expect(resource.public_send(method, path: path, payload: payload)).
113
- to eq(response)
114
- end
115
- end
116
-
117
- context "with a timeout error response" do
118
- before do
119
- allow_any_instance_of(RestClient::ExceptionWithResponse).
120
- to receive(:response).and_return(double(body: "", code: "408"))
121
- expect(RestClient::Request).to receive(:execute).
122
- and_raise(RestClient::ExceptionWithResponse)
123
- end
124
-
125
- it "raises a ConnectionError" do
126
- expect { resource.public_send(method, path: path, payload: payload) }.
127
- to raise_error(Onfido::ConnectionError)
128
- end
129
- end
130
- end
131
- end
132
- end
133
- end