onfido 0.12.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +4 -3
- data/.travis.yml +8 -7
- data/CHANGELOG.md +23 -0
- data/LICENSE +2 -1
- data/README.md +70 -70
- data/lib/onfido.rb +1 -1
- data/lib/onfido/api.rb +4 -4
- data/lib/onfido/configuration.rb +12 -16
- data/lib/onfido/resource.rb +3 -6
- data/lib/onfido/resources/address.rb +1 -1
- data/lib/onfido/resources/applicant.rb +9 -5
- data/lib/onfido/resources/check.rb +10 -14
- data/lib/onfido/resources/document.rb +11 -11
- data/lib/onfido/resources/extraction.rb +9 -0
- data/lib/onfido/resources/live_photo.rb +9 -14
- data/lib/onfido/resources/live_video.rb +5 -8
- data/lib/onfido/resources/report.rb +8 -9
- data/lib/onfido/resources/sdk_token.rb +3 -5
- data/lib/onfido/resources/webhook.rb +11 -9
- data/lib/onfido/version.rb +1 -1
- data/onfido.gemspec +8 -9
- data/spec/integrations/address_spec.rb +1 -0
- data/spec/integrations/applicant_spec.rb +38 -32
- data/spec/integrations/check_spec.rb +13 -23
- data/spec/integrations/document_spec.rb +16 -17
- data/spec/integrations/exceptions_spec.rb +12 -13
- data/spec/integrations/extraction_spec.rb +19 -0
- data/spec/integrations/live_photo_spec.rb +12 -13
- data/spec/integrations/live_video_spec.rb +7 -10
- data/spec/integrations/report_spec.rb +11 -13
- data/spec/integrations/sdk_token_spec.rb +5 -5
- data/spec/integrations/webhook_spec.rb +35 -20
- data/spec/onfido/resource_spec.rb +10 -14
- data/spec/onfido_spec.rb +13 -13
- data/spec/support/fake_onfido_api.rb +60 -77
- data/spec/support/fixtures/applicant.json +21 -42
- data/spec/support/fixtures/check.json +4 -4
- data/spec/support/fixtures/checks.json +4 -4
- data/spec/support/fixtures/document.json +2 -2
- data/spec/support/fixtures/documents.json +8 -8
- data/spec/support/fixtures/extraction.json +23 -0
- data/spec/support/fixtures/live_photo.json +3 -3
- data/spec/support/fixtures/live_photos.json +6 -6
- data/spec/support/fixtures/live_video.json +3 -3
- data/spec/support/fixtures/live_videos.json +4 -4
- data/spec/support/fixtures/not_scheduled_for_deletion_error.json +7 -0
- data/spec/support/fixtures/report.json +4 -4
- data/spec/support/fixtures/reports.json +8 -8
- data/spec/support/fixtures/webhook.json +6 -5
- data/spec/support/fixtures/webhooks.json +17 -12
- metadata +22 -42
- data/lib/onfido/resources/report_type_group.rb +0 -11
- data/spec/integrations/report_type_group_spec.rb +0 -19
- data/spec/support/fixtures/check_with_expanded_reports.json +0 -30
- data/spec/support/fixtures/checks_with_expanded_reports.json +0 -34
- data/spec/support/fixtures/report_type_group.json +0 -25
- data/spec/support/fixtures/report_type_groups.json +0 -30
@@ -3,7 +3,7 @@ require 'onfido/errors/connection_error'
|
|
3
3
|
describe Onfido::Resource do
|
4
4
|
subject(:resource) { described_class.new }
|
5
5
|
|
6
|
-
let(:endpoint) { 'https://api.onfido.com/
|
6
|
+
let(:endpoint) { 'https://api.onfido.com/v3/' }
|
7
7
|
let(:path) { 'addresses/pick' }
|
8
8
|
let(:url) { endpoint + path }
|
9
9
|
let(:payload) { { postcode: 'SE1 4NG' } }
|
@@ -25,18 +25,12 @@ describe Onfido::Resource do
|
|
25
25
|
before { allow(Onfido).to receive(:endpoint).and_return(endpoint) }
|
26
26
|
before { allow(Onfido).to receive(:api_key).and_return(api_key) }
|
27
27
|
|
28
|
-
describe '#url_for' do
|
29
|
-
it 'composes the full api url' do
|
30
|
-
expect(resource.url_for(path)).to eq(endpoint + path)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
28
|
describe '#method_missing' do
|
35
29
|
%i(patch).each do |method|
|
36
30
|
context "for unsupported HTTP method: #{method}" do
|
37
31
|
it 'raises an error' do
|
38
32
|
expect do
|
39
|
-
resource.public_send(method,
|
33
|
+
resource.public_send(method, path: endpoint)
|
40
34
|
end.to raise_error(NoMethodError)
|
41
35
|
end
|
42
36
|
end
|
@@ -64,12 +58,13 @@ describe Onfido::Resource do
|
|
64
58
|
let(:specific_api_key) { "specific_key" }
|
65
59
|
|
66
60
|
it "uses that key when making the request" do
|
67
|
-
resource.get(
|
61
|
+
resource.get(path: path, payload: payload)
|
68
62
|
|
69
63
|
expect(WebMock).to have_requested(:get, url).with(
|
70
64
|
headers: {
|
71
65
|
'Authorization' => "Token token=#{specific_api_key}",
|
72
|
-
'Accept' => "application/json"
|
66
|
+
'Accept' => "application/json",
|
67
|
+
'User-Agent' => "onfido-ruby/#{Onfido::VERSION}"
|
73
68
|
}
|
74
69
|
)
|
75
70
|
end
|
@@ -79,12 +74,13 @@ describe Onfido::Resource do
|
|
79
74
|
let(:specific_api_key) { nil }
|
80
75
|
|
81
76
|
it "uses the general config key when making the request" do
|
82
|
-
resource.get(
|
77
|
+
resource.get(path: path, payload: payload)
|
83
78
|
|
84
79
|
expect(WebMock).to have_requested(:get, url).with(
|
85
80
|
headers: {
|
86
81
|
'Authorization' => "Token token=#{api_key}",
|
87
|
-
'Accept' => "application/json"
|
82
|
+
'Accept' => "application/json",
|
83
|
+
'User-Agent' => "onfido-ruby/#{Onfido::VERSION}"
|
88
84
|
}
|
89
85
|
)
|
90
86
|
end
|
@@ -113,7 +109,7 @@ describe Onfido::Resource do
|
|
113
109
|
end
|
114
110
|
|
115
111
|
it 'makes a request to an endpoint' do
|
116
|
-
expect(resource.public_send(method,
|
112
|
+
expect(resource.public_send(method, path: path, payload: payload)).
|
117
113
|
to eq(response)
|
118
114
|
end
|
119
115
|
end
|
@@ -127,7 +123,7 @@ describe Onfido::Resource do
|
|
127
123
|
end
|
128
124
|
|
129
125
|
it "raises a ConnectionError" do
|
130
|
-
expect { resource.public_send(method,
|
126
|
+
expect { resource.public_send(method, path: path, payload: payload) }.
|
131
127
|
to raise_error(Onfido::ConnectionError)
|
132
128
|
end
|
133
129
|
end
|
data/spec/onfido_spec.rb
CHANGED
@@ -11,7 +11,7 @@ describe Onfido do
|
|
11
11
|
|
12
12
|
describe ".endpoint" do
|
13
13
|
subject { onfido.endpoint }
|
14
|
-
it { is_expected.to eq('https://api.onfido.com/
|
14
|
+
it { is_expected.to eq('https://api.onfido.com/v3/') }
|
15
15
|
end
|
16
16
|
|
17
17
|
describe ".logger" do
|
@@ -27,32 +27,32 @@ describe Onfido do
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
describe
|
31
|
-
it '
|
32
|
-
onfido.
|
33
|
-
expect(onfido.
|
34
|
-
expect(onfido.endpoint).to eq('https://api.onfido.com/v1/')
|
30
|
+
describe 'using the US region' do
|
31
|
+
it 'should change endpoint' do
|
32
|
+
onfido.region = 'us'
|
33
|
+
expect(onfido.endpoint).to eq('https://api.us.onfido.com/v3/')
|
35
34
|
end
|
36
35
|
end
|
37
36
|
|
38
|
-
describe 'using
|
37
|
+
describe 'using the CA region' do
|
39
38
|
it 'should change endpoint' do
|
40
|
-
onfido.
|
41
|
-
expect(onfido.endpoint).to eq('https://api.
|
39
|
+
onfido.region = 'ca'
|
40
|
+
expect(onfido.endpoint).to eq('https://api.ca.onfido.com/v3/')
|
42
41
|
end
|
43
42
|
end
|
44
43
|
|
45
|
-
describe 'using
|
44
|
+
describe 'using an unsupported region' do
|
46
45
|
it 'should change endpoint' do
|
47
|
-
onfido.
|
48
|
-
expect
|
46
|
+
onfido.region = 'de'
|
47
|
+
expect { onfido.endpoint }.
|
48
|
+
to raise_error('The region "de" is not currently supported')
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
describe 'using an old API token' do
|
53
53
|
it 'should use old endpoint' do
|
54
54
|
onfido.api_key = "live_asdfghjkl1234567890qwertyuiop"
|
55
|
-
expect(onfido.endpoint).to eq('https://api.onfido.com/
|
55
|
+
expect(onfido.endpoint).to eq('https://api.onfido.com/v3/')
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -1,62 +1,70 @@
|
|
1
1
|
require 'sinatra/base'
|
2
2
|
|
3
3
|
class FakeOnfidoAPI < Sinatra::Base
|
4
|
-
get '/
|
4
|
+
get '/v3/addresses/pick' do
|
5
5
|
json_response(200, 'addresses.json')
|
6
6
|
end
|
7
7
|
|
8
|
-
post '/
|
8
|
+
post '/v3/applicants' do
|
9
9
|
json_response(201, 'applicant.json')
|
10
10
|
end
|
11
11
|
|
12
|
-
put '/
|
12
|
+
put '/v3/applicants/:id' do
|
13
13
|
json_response(200, 'applicant.json')
|
14
14
|
end
|
15
15
|
|
16
|
-
get '/
|
16
|
+
get '/v3/applicants/:id' do
|
17
17
|
json_response(200, 'applicant.json')
|
18
18
|
end
|
19
19
|
|
20
|
-
get '/
|
20
|
+
get '/v3/applicants' do
|
21
21
|
response = json_response(200, 'applicants.json')
|
22
22
|
{ applicants: JSON.parse(response)['applicants'][pagination_range] }.to_json
|
23
23
|
end
|
24
24
|
|
25
|
-
delete '/
|
25
|
+
delete '/v3/applicants/:id' do
|
26
26
|
status 204
|
27
27
|
end
|
28
28
|
|
29
|
-
post '/
|
29
|
+
post '/v3/applicants/:id/restore' do
|
30
|
+
if params["id"] == "a2fb9c62-ab10-4898-a8ec-342c4b552ad5"
|
31
|
+
json_response(422, 'not_scheduled_for_deletion_error.json')
|
32
|
+
else
|
33
|
+
status 204
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
post '/v3/documents' do
|
30
38
|
json_response(201, 'document.json')
|
31
39
|
end
|
32
40
|
|
33
|
-
|
41
|
+
post '/v3/extractions' do
|
42
|
+
json_response(201, 'extraction.json')
|
43
|
+
end
|
44
|
+
|
45
|
+
get '/v3/documents/:id' do
|
34
46
|
json_response(200, 'document.json')
|
35
47
|
end
|
36
48
|
|
37
|
-
get '/
|
49
|
+
get '/v3/documents' do
|
38
50
|
json_response(200, 'documents.json')
|
39
51
|
end
|
40
52
|
|
41
|
-
get '/
|
53
|
+
get '/v3/documents/:id/download' do
|
42
54
|
status 200
|
43
55
|
content_type 'application/octet-stream'
|
44
56
|
"\x01\x02\x03" # acts as binary file data
|
45
57
|
end
|
46
58
|
|
47
|
-
post '/
|
59
|
+
post '/v3/live_photos' do
|
48
60
|
json_response(201, 'live_photo.json')
|
49
61
|
end
|
50
62
|
|
51
|
-
get '/
|
52
|
-
|
53
|
-
status 404
|
54
|
-
else
|
55
|
-
json_response(200, 'live_photo.json')
|
56
|
-
end
|
63
|
+
get '/v3/live_photos/:id' do
|
64
|
+
json_response(200, 'live_photo.json')
|
57
65
|
end
|
58
66
|
|
59
|
-
get '/
|
67
|
+
get '/v3/live_photos' do
|
60
68
|
if params["applicant_id"] != "1030303-123123-123123"
|
61
69
|
status 404
|
62
70
|
else
|
@@ -64,25 +72,17 @@ class FakeOnfidoAPI < Sinatra::Base
|
|
64
72
|
end
|
65
73
|
end
|
66
74
|
|
67
|
-
get '/
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
status 200
|
72
|
-
content_type 'image/jpeg'
|
73
|
-
"\x01\x02\x03" # acts as binary file data
|
74
|
-
end
|
75
|
+
get '/v3/live_photos/:id/download' do
|
76
|
+
status 200
|
77
|
+
content_type 'image/jpeg'
|
78
|
+
"\x01\x02\x03" # acts as binary file data
|
75
79
|
end
|
76
80
|
|
77
|
-
get '/
|
78
|
-
|
79
|
-
status 404
|
80
|
-
else
|
81
|
-
json_response(200, 'live_video.json')
|
82
|
-
end
|
81
|
+
get '/v3/live_videos/:id' do
|
82
|
+
json_response(200, 'live_video.json')
|
83
83
|
end
|
84
84
|
|
85
|
-
get '/
|
85
|
+
get '/v3/live_videos' do
|
86
86
|
if params["applicant_id"] != "1030303-123123-123123"
|
87
87
|
status 404
|
88
88
|
else
|
@@ -90,91 +90,74 @@ class FakeOnfidoAPI < Sinatra::Base
|
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
93
|
-
get '/
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
status 200
|
98
|
-
content_type 'video/quicktime'
|
99
|
-
"\x01\x02\x03" # acts as binary file data
|
100
|
-
end
|
93
|
+
get '/v3/live_videos/:id/download' do
|
94
|
+
status 200
|
95
|
+
content_type 'video/quicktime'
|
96
|
+
"\x01\x02\x03" # acts as binary file data
|
101
97
|
end
|
102
98
|
|
103
|
-
post '/
|
104
|
-
json_response(201, 'check.json')
|
99
|
+
post '/v3/checks' do
|
100
|
+
params["applicant_id"].nil? ? status(422) : json_response(201, 'check.json')
|
105
101
|
end
|
106
102
|
|
107
|
-
get '/
|
108
|
-
|
109
|
-
json_response(200, "check_with_expanded_reports.json")
|
110
|
-
else
|
111
|
-
json_response(200, "check.json")
|
112
|
-
end
|
103
|
+
get '/v3/checks/:id' do
|
104
|
+
json_response(200, "check.json")
|
113
105
|
end
|
114
106
|
|
115
|
-
get '/
|
116
|
-
|
117
|
-
json_response(200, "checks_with_expanded_reports.json")
|
118
|
-
else
|
119
|
-
json_response(200, "checks.json")
|
120
|
-
end
|
121
|
-
|
122
|
-
{ checks: JSON.parse(response)['checks'][pagination_range] }.to_json
|
107
|
+
get '/v3/checks' do
|
108
|
+
json_response(200, "checks.json")
|
123
109
|
end
|
124
110
|
|
125
|
-
post '/
|
111
|
+
post '/v3/checks/:id/resume' do
|
126
112
|
status 204 # no_content
|
127
113
|
end
|
128
114
|
|
129
|
-
get '/
|
115
|
+
get '/v3/reports' do
|
130
116
|
json_response(200, 'reports.json')
|
131
117
|
end
|
132
118
|
|
133
|
-
get '/
|
119
|
+
get '/v3/reports/:id' do
|
134
120
|
json_response(200, 'report.json')
|
135
121
|
end
|
136
122
|
|
137
|
-
post '/
|
123
|
+
post '/v3/reports/:id/resume' do
|
138
124
|
status 204
|
139
125
|
end
|
140
126
|
|
141
|
-
post '/
|
127
|
+
post '/v3/reports/:id/cancel' do
|
142
128
|
status 204
|
143
129
|
end
|
144
130
|
|
145
|
-
|
146
|
-
json_response(200, 'report_type_group.json')
|
147
|
-
end
|
148
|
-
|
149
|
-
get '/v2/report_type_groups' do
|
150
|
-
json_response(200, 'report_type_groups.json')
|
151
|
-
end
|
152
|
-
|
153
|
-
post '/v2/sdk_token' do
|
131
|
+
post '/v3/sdk_token' do
|
154
132
|
json_response(201, 'sdk_token.json')
|
155
133
|
end
|
156
134
|
|
157
|
-
post '/
|
135
|
+
post '/v3/webhooks' do
|
158
136
|
json_response(201, 'webhook.json')
|
159
137
|
end
|
160
138
|
|
161
|
-
get '/
|
139
|
+
get '/v3/webhooks/:id' do
|
162
140
|
json_response(200, 'webhook.json')
|
163
141
|
end
|
164
142
|
|
165
|
-
|
143
|
+
delete '/v3/webhooks/:id' do
|
144
|
+
content_type "application/json; charset=utf-8"
|
145
|
+
status 204
|
146
|
+
end
|
147
|
+
|
148
|
+
get '/v3/webhooks' do
|
166
149
|
json_response(200, 'webhooks.json')
|
167
150
|
end
|
168
151
|
|
169
|
-
get '/
|
152
|
+
get '/v3/4xx_response' do
|
170
153
|
json_response(422, '4xx_response.json')
|
171
154
|
end
|
172
155
|
|
173
|
-
get '/
|
156
|
+
get '/v3/unexpected_error_format' do
|
174
157
|
json_response(400, 'unexpected_error_format.json')
|
175
158
|
end
|
176
159
|
|
177
|
-
get '/
|
160
|
+
get '/v3/unparseable_response' do
|
178
161
|
content_type :json
|
179
162
|
status 504
|
180
163
|
''
|
@@ -1,44 +1,23 @@
|
|
1
1
|
{
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
"
|
14
|
-
"
|
15
|
-
"
|
16
|
-
"
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
"town":"London",
|
24
|
-
"state":"",
|
25
|
-
"postcode":"SW4 6EH",
|
26
|
-
"country":"GBR",
|
27
|
-
"start_date":"",
|
28
|
-
"end_date":""
|
29
|
-
},
|
30
|
-
{
|
31
|
-
"flat_number":"1",
|
32
|
-
"building_number":"10",
|
33
|
-
"building_name":"Great Building",
|
34
|
-
"street":"Old Street",
|
35
|
-
"sub_street":"Sub Street",
|
36
|
-
"town":"London",
|
37
|
-
"state":"",
|
38
|
-
"postcode":"SW1 4NG",
|
39
|
-
"country":"GBR",
|
40
|
-
"start_date":"",
|
41
|
-
"end_date":""
|
42
|
-
}
|
43
|
-
]
|
2
|
+
"id":"61f659cb-c90b-4067-808a-6136b5c01351",
|
3
|
+
"created_at":"2015-04-10T13:16:01Z",
|
4
|
+
"title":"Mr",
|
5
|
+
"first_name":"Chandler",
|
6
|
+
"middle_name":"Muriel",
|
7
|
+
"last_name":"Bing",
|
8
|
+
"email":"chandler_bing_6@friends.com",
|
9
|
+
"dob":"1968-04-08",
|
10
|
+
"href":"/v3/applicants/61f659cb-c90b-4067-808a-6136b5c01351",
|
11
|
+
"id_numbers":[],
|
12
|
+
"address": {
|
13
|
+
"flat_number":"4",
|
14
|
+
"building_number":"100",
|
15
|
+
"building_name":"Awesome Building",
|
16
|
+
"street":"Main Street",
|
17
|
+
"sub_street":"A sub street",
|
18
|
+
"town":"London",
|
19
|
+
"state":"",
|
20
|
+
"postcode":"SW4 6EH",
|
21
|
+
"country":"GBR"
|
22
|
+
}
|
44
23
|
}
|
@@ -1,11 +1,11 @@
|
|
1
1
|
{
|
2
2
|
"id": "8546921-123123-123123",
|
3
|
-
"created_at": "
|
4
|
-
"href": "/
|
5
|
-
"
|
3
|
+
"created_at": "2019-05-23T13:50:33Z",
|
4
|
+
"href": "/v3/checks/8546921-123123-123123",
|
5
|
+
"applicant_provides_data": "false",
|
6
6
|
"status": "pending",
|
7
7
|
"result": "pending",
|
8
|
-
"
|
8
|
+
"report_ids": [
|
9
9
|
"1030303-123123-375629",
|
10
10
|
"1030303-123123-456789"
|
11
11
|
]
|