onfido 0.15.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/LICENSE +2 -1
- data/README.md +18 -32
- data/lib/onfido.rb +0 -1
- data/lib/onfido/api.rb +0 -4
- data/lib/onfido/configuration.rb +2 -3
- data/lib/onfido/resource.rb +1 -5
- data/lib/onfido/resources/address.rb +1 -1
- data/lib/onfido/resources/applicant.rb +6 -6
- data/lib/onfido/resources/check.rb +9 -19
- data/lib/onfido/resources/document.rb +11 -11
- 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 +7 -9
- data/lib/onfido/version.rb +1 -1
- data/onfido.gemspec +6 -6
- data/spec/integrations/address_spec.rb +1 -0
- data/spec/integrations/applicant_spec.rb +18 -36
- data/spec/integrations/check_spec.rb +13 -67
- data/spec/integrations/document_spec.rb +16 -17
- data/spec/integrations/exceptions_spec.rb +12 -13
- 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 +26 -18
- data/spec/onfido/resource_spec.rb +6 -12
- data/spec/onfido_spec.rb +3 -11
- data/spec/support/fake_onfido_api.rb +44 -78
- 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/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/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 +9 -22
- 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
@@ -1,18 +1,16 @@
|
|
1
1
|
module Onfido
|
2
2
|
class Webhook < Resource
|
3
|
-
def create(payload)
|
4
|
-
|
5
|
-
|
6
|
-
payload: payload
|
7
|
-
)
|
3
|
+
def create(url:, **payload)
|
4
|
+
payload[:url] = url
|
5
|
+
post(path: 'webhooks', payload: payload)
|
8
6
|
end
|
9
7
|
|
10
8
|
def find(webhooks_id)
|
11
|
-
get(
|
9
|
+
get(path: "webhooks/#{webhooks_id}")
|
12
10
|
end
|
13
11
|
|
14
|
-
def all
|
15
|
-
get(
|
12
|
+
def all
|
13
|
+
get(path: 'webhooks')
|
16
14
|
end
|
17
15
|
|
18
16
|
# As well as being a normal resource, Onfido::Webhook also supports
|
@@ -29,7 +27,7 @@ module Onfido
|
|
29
27
|
end
|
30
28
|
|
31
29
|
def self.generate_signature(request_body, token)
|
32
|
-
OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('
|
30
|
+
OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), token, request_body)
|
33
31
|
end
|
34
32
|
private_class_method :generate_signature
|
35
33
|
end
|
data/lib/onfido/version.rb
CHANGED
data/onfido.gemspec
CHANGED
@@ -7,14 +7,14 @@ require 'onfido/version'
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
8
|
spec.name = 'onfido'
|
9
9
|
spec.version = Onfido::VERSION
|
10
|
-
spec.authors = ['
|
11
|
-
spec.email = ['
|
10
|
+
spec.authors = ['Onfido']
|
11
|
+
spec.email = ['engineering@onfido.com']
|
12
12
|
spec.summary = 'A wrapper for Onfido API'
|
13
|
-
spec.description = "A thin wrapper for Onfido's API. This gem supports "\
|
14
|
-
"
|
13
|
+
spec.description = "A thin wrapper for Onfido's API. This gem only supports "\
|
14
|
+
"v3 of the Onfido API. Refer to Onfido's "\
|
15
15
|
"API documentation for details of the expected "\
|
16
|
-
"requests and responses
|
17
|
-
spec.homepage = 'http://github.com/
|
16
|
+
"requests and responses."
|
17
|
+
spec.homepage = 'http://github.com/onfido/onfido-ruby'
|
18
18
|
spec.license = 'MIT'
|
19
19
|
|
20
20
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -1,38 +1,24 @@
|
|
1
1
|
describe Onfido::Applicant do
|
2
2
|
subject(:applicant) { described_class.new }
|
3
|
+
let(:applicant_id) { '61f659cb-c90b-4067-808a-6136b5c01351' }
|
3
4
|
let(:params) do
|
4
5
|
{
|
5
6
|
'title' => 'Mr',
|
6
7
|
'first_name' => 'Chandler',
|
7
8
|
'last_name' => 'Bing',
|
8
|
-
'gender' => 'male',
|
9
9
|
'middle_name' => 'Muriel',
|
10
10
|
'dob' => '1968-04-08',
|
11
|
-
'telephone' => '555555555',
|
12
|
-
'mobile' => '77777777',
|
13
11
|
'email' => 'chandler_bing_6@friends.com',
|
14
|
-
'
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
},
|
25
|
-
{
|
26
|
-
'flat_number' => '1',
|
27
|
-
'building_number' => '10',
|
28
|
-
'building_name' => 'Great Building',
|
29
|
-
'street' => 'Old Street',
|
30
|
-
'sub_street' => 'Sub Street',
|
31
|
-
'town' => 'London',
|
32
|
-
'postcode' => 'SW1 4NG',
|
33
|
-
'country' => 'GBR'
|
34
|
-
}
|
35
|
-
]
|
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
|
+
'postcode' => 'SW4 6EH',
|
20
|
+
'country' => 'GBR'
|
21
|
+
}
|
36
22
|
}
|
37
23
|
end
|
38
24
|
|
@@ -43,7 +29,7 @@ describe Onfido::Applicant do
|
|
43
29
|
|
44
30
|
it 'serializes the payload correctly' do
|
45
31
|
WebMock.after_request do |request_signature, _response|
|
46
|
-
if request_signature.uri.path == '
|
32
|
+
if request_signature.uri.path == 'v3/applicants'
|
47
33
|
expect(Rack::Utils.parse_nested_query(request_signature.body)).
|
48
34
|
to eq(params)
|
49
35
|
end
|
@@ -57,26 +43,22 @@ describe Onfido::Applicant do
|
|
57
43
|
end
|
58
44
|
|
59
45
|
describe '#update' do
|
60
|
-
let(:applicant_id) { '61f659cb-c90b-4067-808a-6136b5c01351' }
|
61
|
-
|
62
46
|
it 'updates an applicant' do
|
63
47
|
response = applicant.update(applicant_id, params)
|
48
|
+
|
64
49
|
expect(response['id']).to eq(applicant_id)
|
65
50
|
end
|
66
51
|
end
|
67
52
|
|
68
53
|
describe '#find' do
|
69
|
-
let(:applicant_id) { '61f659cb-c90b-4067-808a-6136b5c01351' }
|
70
|
-
|
71
54
|
it 'returns the applicant' do
|
72
55
|
response = applicant.find(applicant_id)
|
56
|
+
|
73
57
|
expect(response['id']).to eq(applicant_id)
|
74
58
|
end
|
75
59
|
end
|
76
60
|
|
77
61
|
describe '#destroy' do
|
78
|
-
let(:applicant_id) { '61f659cb-c90b-4067-808a-6136b5c01351' }
|
79
|
-
|
80
62
|
it 'returns success code' do
|
81
63
|
expect { applicant.destroy(applicant_id) }.not_to raise_error
|
82
64
|
end
|
@@ -86,6 +68,7 @@ describe Onfido::Applicant do
|
|
86
68
|
context 'with the default page and per page params' do
|
87
69
|
it 'returns all the applicants' do
|
88
70
|
response = applicant.all
|
71
|
+
|
89
72
|
expect(response['applicants'].size).to eq(2)
|
90
73
|
end
|
91
74
|
end
|
@@ -93,6 +76,7 @@ describe Onfido::Applicant do
|
|
93
76
|
context 'with specific range of results for a page' do
|
94
77
|
it 'returns the specified applicants' do
|
95
78
|
response = applicant.all(page: 1, per_page: 1)
|
79
|
+
|
96
80
|
expect(response['applicants'].size).to eq(1)
|
97
81
|
end
|
98
82
|
end
|
@@ -100,17 +84,15 @@ describe Onfido::Applicant do
|
|
100
84
|
|
101
85
|
describe '#restore' do
|
102
86
|
context 'an applicant scheduled for deletion' do
|
103
|
-
let(:applicant_id) { '61f659cb-c90b-4067-808a-6136b5c01351' }
|
104
|
-
|
105
87
|
it 'returns nil' do
|
106
88
|
expect(applicant.restore(applicant_id)).to be_nil
|
107
89
|
end
|
108
90
|
end
|
109
91
|
|
110
92
|
context 'an applicant not scheduled for deletion' do
|
111
|
-
let(:applicant_id) { 'a2fb9c62-ab10-4898-a8ec-342c4b552ad5' }
|
112
|
-
|
113
93
|
it 'returns an error' do
|
94
|
+
applicant_id = 'a2fb9c62-ab10-4898-a8ec-342c4b552ad5'
|
95
|
+
|
114
96
|
expect { applicant.restore(applicant_id) }.to raise_error { |error|
|
115
97
|
expect(error).to be_a(Onfido::RequestError)
|
116
98
|
expect(error.message).to eq('There was a validation error on this request')
|
@@ -1,103 +1,49 @@
|
|
1
1
|
describe Onfido::Check do
|
2
2
|
subject(:check) { described_class.new }
|
3
3
|
let(:applicant_id) { '61f659cb-c90b-4067-808a-6136b5c01351' }
|
4
|
+
let(:check_id) { '8546921-123123-123123' }
|
4
5
|
|
5
6
|
describe '#create' do
|
6
|
-
let(:params) { { type: 'express', reports: [{ name: 'identity' }] } }
|
7
|
-
|
8
7
|
it 'creates a new check for an applicant' do
|
9
|
-
response = check.create(
|
8
|
+
response = check.create(
|
9
|
+
applicant_id: applicant_id,
|
10
|
+
report_names: ['identity_enhanced']
|
11
|
+
)
|
10
12
|
expect(response['id']).not_to be_nil
|
11
13
|
end
|
12
14
|
end
|
13
15
|
|
14
16
|
describe '#find' do
|
15
|
-
let(:check_id) { '8546921-123123-123123' }
|
16
|
-
|
17
17
|
it 'returns an existing check for the applicant' do
|
18
|
-
response = check.find(
|
19
|
-
expect(response['id']).to eq(check_id)
|
20
|
-
end
|
21
|
-
|
22
|
-
it "returns unexpanded reports" do
|
23
|
-
response = check.find(applicant_id, check_id)
|
24
|
-
expect(response['reports'].first).to be_a(String)
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'allows you to expand the reports' do
|
28
|
-
response = check.find(applicant_id, check_id, expand: "reports")
|
29
|
-
expect(response['reports'].first).to be_a(Hash)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe '#find_by_url' do
|
34
|
-
let(:check_id) { '8546921-123123-123123' }
|
35
|
-
|
36
|
-
context 'partial url' do
|
37
|
-
let(:url) { "applicants/#{applicant_id}/checks/#{check_id}" }
|
18
|
+
response = check.find(check_id)
|
38
19
|
|
39
|
-
|
40
|
-
response = check.find_by_url(url)
|
41
|
-
expect(response['id']).to eq(check_id)
|
42
|
-
end
|
43
|
-
|
44
|
-
it "returns unexpanded reports" do
|
45
|
-
response = check.find_by_url(url)
|
46
|
-
expect(response['reports'].first).to be_a(String)
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'allows you to expand the reports' do
|
50
|
-
response = check.find_by_url(url, expand: "reports")
|
51
|
-
expect(response['reports'].first).to be_a(Hash)
|
52
|
-
end
|
20
|
+
expect(response['id']).to eq(check_id)
|
53
21
|
end
|
54
22
|
|
55
|
-
|
56
|
-
|
57
|
-
"https://api.onfido.com/v2/applicants/#{applicant_id}/checks/#{check_id}"
|
58
|
-
end
|
23
|
+
it "returns report_ids" do
|
24
|
+
response = check.find(check_id)
|
59
25
|
|
60
|
-
|
61
|
-
response = check.find_by_url(url)
|
62
|
-
expect(response['id']).to eq(check_id)
|
63
|
-
end
|
64
|
-
|
65
|
-
it "returns unexpanded reports" do
|
66
|
-
response = check.find_by_url(url)
|
67
|
-
expect(response['reports'].first).to be_a(String)
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'allows you to expand the reports' do
|
71
|
-
response = check.find_by_url(url, expand: "reports")
|
72
|
-
expect(response['reports'].first).to be_a(Hash)
|
73
|
-
end
|
26
|
+
expect(response['report_ids'].first).to be_a(String)
|
74
27
|
end
|
75
28
|
end
|
76
29
|
|
77
30
|
describe '#all' do
|
78
|
-
let(:check_id) { '8546921-123123-123123' }
|
79
|
-
|
80
31
|
context 'with the default page and per page params' do
|
81
32
|
it 'returns all existing checks for the applicant' do
|
82
33
|
response = check.all(applicant_id)
|
34
|
+
|
83
35
|
expect(response['checks'].size).to eq(1)
|
84
36
|
end
|
85
37
|
end
|
86
38
|
|
87
|
-
it "returns
|
39
|
+
it "returns report_ids" do
|
88
40
|
response = check.all(applicant_id)
|
89
|
-
expect(response['checks'].first['reports'].first).to be_a(String)
|
90
|
-
end
|
91
41
|
|
92
|
-
|
93
|
-
response = check.all(applicant_id, expand: "reports")
|
94
|
-
expect(response['checks'].first['reports'].first).to be_a(Hash)
|
42
|
+
expect(response['checks'].first['report_ids'].first).to be_a(String)
|
95
43
|
end
|
96
44
|
end
|
97
45
|
|
98
46
|
describe "#resume" do
|
99
|
-
let(:check_id) { '8546921-123123-123123' }
|
100
|
-
|
101
47
|
it 'returns success response' do
|
102
48
|
expect { check.resume(check_id) }.not_to raise_error
|
103
49
|
end
|
@@ -6,15 +6,15 @@ describe Onfido::Document do
|
|
6
6
|
describe '#create' do
|
7
7
|
let(:params) do
|
8
8
|
{
|
9
|
-
|
10
|
-
|
11
|
-
file: file
|
9
|
+
applicant_id: '1030303-123123-123123',
|
10
|
+
type: 'driving_licence',
|
11
|
+
file: file,
|
12
|
+
side: 'front'
|
12
13
|
}
|
13
14
|
end
|
14
|
-
let(:applicant_id) { '1030303-123123-123123' }
|
15
15
|
|
16
16
|
context 'with a File-like object to upload' do
|
17
|
-
let(:file) { Tempfile.new(['
|
17
|
+
let(:file) { Tempfile.new(['driving_licence', '.jpg']) }
|
18
18
|
|
19
19
|
after do
|
20
20
|
file.close
|
@@ -22,7 +22,8 @@ describe Onfido::Document do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'creates a new document' do
|
25
|
-
response = document.create(
|
25
|
+
response = document.create(params)
|
26
|
+
|
26
27
|
expect(response['id']).not_to be_nil
|
27
28
|
end
|
28
29
|
end
|
@@ -31,37 +32,35 @@ describe Onfido::Document do
|
|
31
32
|
let(:file) { 'https://onfido.com/images/logo.png' }
|
32
33
|
|
33
34
|
it 'raises an ArgumentError' do
|
34
|
-
expect { document.create(
|
35
|
+
expect { document.create(params) }.
|
35
36
|
to raise_error(ArgumentError, /must be a `File`-like object/)
|
36
37
|
end
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
40
41
|
describe '#find' do
|
41
|
-
let(:applicant_id) { '1030303-123123-123123' }
|
42
|
-
let(:document_id) { '7568415-123123-123123' }
|
43
|
-
|
44
42
|
it 'returns the expected document' do
|
45
|
-
|
43
|
+
document_id = '7568415-123123-123123'
|
44
|
+
response = document.find(document_id)
|
45
|
+
|
46
46
|
expect(response['id']).to eq(document_id)
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
50
|
describe '#all' do
|
51
|
-
let(:applicant_id) { '1030303-123123-123123' }
|
52
|
-
|
53
51
|
it 'returns list of documents' do
|
52
|
+
applicant_id = '1030303-123123-123123'
|
54
53
|
response = document.all(applicant_id)
|
54
|
+
|
55
55
|
expect(response['documents']).not_to be_empty
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
59
|
describe '#download' do
|
60
|
-
let(:applicant_id) { '1030303-123123-123123' }
|
61
|
-
let(:document_id) { '1212121-123123-123123' }
|
62
|
-
|
63
60
|
it 'returns the file data' do
|
64
|
-
|
61
|
+
document_id = '1212121-123123-123123'
|
62
|
+
response = document.download(document_id)
|
63
|
+
|
65
64
|
expect(response).not_to be_nil
|
66
65
|
end
|
67
66
|
end
|
@@ -1,34 +1,33 @@
|
|
1
1
|
describe Onfido::Resource do
|
2
2
|
let(:resource) { described_class.new }
|
3
|
-
let(:url) { Onfido.endpoint + path }
|
4
3
|
let(:api_key) { 'some_key' }
|
5
4
|
let(:payload) { { postcode: 'SE1 4NG' } }
|
6
5
|
|
7
6
|
before { allow(Onfido).to receive(:api_key).and_return(api_key) }
|
8
7
|
|
9
8
|
context '4xx response' do
|
10
|
-
let(:path) { '4xx_response' }
|
11
|
-
|
12
9
|
it 'raises a custom error' do
|
13
|
-
|
10
|
+
path = '4xx_response'
|
11
|
+
|
12
|
+
expect { resource.get(path: path, payload: payload) }.
|
14
13
|
to raise_error(Onfido::RequestError, 'Something went wrong')
|
15
14
|
end
|
16
15
|
end
|
17
16
|
|
18
17
|
context 'unexpected error format' do
|
19
|
-
let(:path) { 'unexpected_error_format' }
|
20
|
-
|
21
18
|
it 'raises a custom error' do
|
22
|
-
|
19
|
+
path = 'unexpected_error_format'
|
20
|
+
|
21
|
+
expect { resource.get(path: path, payload: payload) }.
|
23
22
|
to raise_error(Onfido::RequestError, /response code was 400/)
|
24
23
|
end
|
25
24
|
end
|
26
25
|
|
27
26
|
context 'unparseable JSON 5xx' do
|
28
|
-
let(:path) { 'unparseable_response' }
|
29
|
-
|
30
27
|
it 'raises a server error' do
|
31
|
-
|
28
|
+
path = 'unparseable_response'
|
29
|
+
|
30
|
+
expect { resource.get(path: path, payload: payload) }.
|
32
31
|
to raise_error(Onfido::ServerError, /response code was 504/)
|
33
32
|
end
|
34
33
|
end
|
@@ -41,7 +40,7 @@ describe Onfido::Resource do
|
|
41
40
|
end
|
42
41
|
|
43
42
|
it 'raises a ConnectionError' do
|
44
|
-
expect { resource.get(
|
43
|
+
expect { resource.get(path: Onfido.endpoint, payload: payload) }.
|
45
44
|
to raise_error(Onfido::ConnectionError, /Could not connect/)
|
46
45
|
end
|
47
46
|
end
|
@@ -54,7 +53,7 @@ describe Onfido::Resource do
|
|
54
53
|
end
|
55
54
|
|
56
55
|
it 'raises a ConnectionError' do
|
57
|
-
expect { resource.get(
|
56
|
+
expect { resource.get(path: Onfido.endpoint, payload: payload) }.
|
58
57
|
to raise_error(Onfido::ConnectionError, /connection to the server/)
|
59
58
|
end
|
60
59
|
end
|
@@ -67,7 +66,7 @@ describe Onfido::Resource do
|
|
67
66
|
end
|
68
67
|
|
69
68
|
it 'raises a ConnectionError' do
|
70
|
-
expect { resource.get(
|
69
|
+
expect { resource.get(path: Onfido.endpoint, payload: payload) }.
|
71
70
|
to raise_error(Onfido::ConnectionError, /SSL certificate/)
|
72
71
|
end
|
73
72
|
end
|