onfido 0.14.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -0
  3. data/.travis.yml +3 -7
  4. data/CHANGELOG.md +21 -0
  5. data/LICENSE +2 -1
  6. data/README.md +59 -73
  7. data/lib/onfido.rb +1 -1
  8. data/lib/onfido/api.rb +4 -4
  9. data/lib/onfido/configuration.rb +4 -4
  10. data/lib/onfido/resource.rb +3 -6
  11. data/lib/onfido/resources/address.rb +1 -4
  12. data/lib/onfido/resources/applicant.rb +6 -6
  13. data/lib/onfido/resources/check.rb +10 -14
  14. data/lib/onfido/resources/document.rb +11 -11
  15. data/lib/onfido/resources/extraction.rb +9 -0
  16. data/lib/onfido/resources/live_photo.rb +9 -14
  17. data/lib/onfido/resources/live_video.rb +5 -8
  18. data/lib/onfido/resources/report.rb +8 -9
  19. data/lib/onfido/resources/sdk_token.rb +3 -5
  20. data/lib/onfido/resources/webhook.rb +11 -9
  21. data/lib/onfido/version.rb +1 -1
  22. data/onfido.gemspec +6 -7
  23. data/spec/integrations/address_spec.rb +1 -0
  24. data/spec/integrations/applicant_spec.rb +21 -37
  25. data/spec/integrations/check_spec.rb +13 -23
  26. data/spec/integrations/document_spec.rb +16 -17
  27. data/spec/integrations/exceptions_spec.rb +12 -14
  28. data/spec/integrations/extraction_spec.rb +19 -0
  29. data/spec/integrations/live_photo_spec.rb +12 -13
  30. data/spec/integrations/live_video_spec.rb +7 -10
  31. data/spec/integrations/report_spec.rb +11 -13
  32. data/spec/integrations/sdk_token_spec.rb +5 -5
  33. data/spec/integrations/webhook_spec.rb +35 -20
  34. data/spec/onfido/resource_spec.rb +10 -14
  35. data/spec/onfido_spec.rb +9 -10
  36. data/spec/support/fake_onfido_api.rb +53 -78
  37. data/spec/support/fixtures/applicant.json +21 -42
  38. data/spec/support/fixtures/check.json +4 -4
  39. data/spec/support/fixtures/checks.json +4 -4
  40. data/spec/support/fixtures/document.json +2 -2
  41. data/spec/support/fixtures/documents.json +8 -8
  42. data/spec/support/fixtures/extraction.json +23 -0
  43. data/spec/support/fixtures/live_photo.json +3 -3
  44. data/spec/support/fixtures/live_photos.json +6 -6
  45. data/spec/support/fixtures/live_video.json +3 -3
  46. data/spec/support/fixtures/live_videos.json +4 -4
  47. data/spec/support/fixtures/not_scheduled_for_deletion_error.json +7 -0
  48. data/spec/support/fixtures/report.json +4 -4
  49. data/spec/support/fixtures/reports.json +8 -8
  50. data/spec/support/fixtures/webhook.json +6 -5
  51. data/spec/support/fixtures/webhooks.json +17 -12
  52. metadata +19 -40
  53. data/lib/onfido/resources/report_type_group.rb +0 -11
  54. data/spec/integrations/report_type_group_spec.rb +0 -19
  55. data/spec/support/fixtures/check_with_expanded_reports.json +0 -30
  56. data/spec/support/fixtures/checks_with_expanded_reports.json +0 -34
  57. data/spec/support/fixtures/report_type_group.json +0 -25
  58. data/spec/support/fixtures/report_type_groups.json +0 -30
@@ -1,27 +1,27 @@
1
1
  module Onfido
2
2
  class Applicant < Resource
3
3
  def create(payload)
4
- post(url: url_for('applicants'), payload: payload)
4
+ post(path: 'applicants', payload: payload)
5
5
  end
6
6
 
7
7
  def update(applicant_id, payload)
8
- put(url: url_for("applicants/#{applicant_id}"), payload: payload)
8
+ put(path: "applicants/#{applicant_id}", payload: payload)
9
9
  end
10
10
 
11
11
  def destroy(applicant_id)
12
- delete(url: url_for("applicants/#{applicant_id}"))
12
+ delete(path: "applicants/#{applicant_id}")
13
13
  end
14
14
 
15
15
  def find(applicant_id)
16
- get(url: url_for("applicants/#{applicant_id}"))
16
+ get(path: "applicants/#{applicant_id}")
17
17
  end
18
18
 
19
19
  def all(page: 1, per_page: 20)
20
- get(url: url_for("applicants?page=#{page}&per_page=#{per_page}"))
20
+ get(path: "applicants?page=#{page}&per_page=#{per_page}")
21
21
  end
22
22
 
23
23
  def restore(applicant_id)
24
- post(url: url_for("applicants/#{applicant_id}/restore"))
24
+ post(path: "applicants/#{applicant_id}/restore")
25
25
  end
26
26
  end
27
27
  end
@@ -1,26 +1,22 @@
1
1
  module Onfido
2
2
  class Check < Resource
3
- def create(applicant_id, payload)
4
- post(
5
- url: url_for("applicants/#{applicant_id}/checks"),
6
- payload: payload
7
- )
3
+ def create(applicant_id:, report_names:, **payload)
4
+ payload[:applicant_id] = applicant_id
5
+ payload[:report_names] = report_names
6
+
7
+ post(path: 'checks', payload: payload)
8
8
  end
9
9
 
10
- def find(applicant_id, check_id, expand: nil)
11
- querystring = "&expand=#{expand}" if expand
12
- get(url: url_for("applicants/#{applicant_id}/checks/#{check_id}?" \
13
- "#{querystring}"))
10
+ def find(check_id)
11
+ get(path: "checks/#{check_id}")
14
12
  end
15
13
 
16
- def all(applicant_id, page: 1, per_page: 20, expand: nil)
17
- querystring = "page=#{page}&per_page=#{per_page}"
18
- querystring += "&expand=#{expand}" if expand
19
- get(url: url_for("applicants/#{applicant_id}/checks?#{querystring}"))
14
+ def all(applicant_id)
15
+ get(path: "checks?applicant_id=#{applicant_id}")
20
16
  end
21
17
 
22
18
  def resume(check_id)
23
- post(url: url_for("checks/#{check_id}/resume"))
19
+ post(path: "checks/#{check_id}/resume")
24
20
  end
25
21
  end
26
22
  end
@@ -2,25 +2,25 @@ module Onfido
2
2
  class Document < Resource
3
3
  # with open-uri the file can be a link or an actual file
4
4
 
5
- def create(applicant_id, payload)
6
- validate_file!(payload.fetch(:file))
5
+ def create(applicant_id:, file:, type:, **payload)
6
+ validate_file!(file)
7
+ payload[:applicant_id] = applicant_id
8
+ payload[:file] = file
9
+ payload[:type] = type
7
10
 
8
- post(
9
- url: url_for("applicants/#{applicant_id}/documents"),
10
- payload: payload
11
- )
11
+ post(path: 'documents', payload: payload)
12
12
  end
13
13
 
14
- def find(applicant_id, document_id)
15
- get(url: url_for("applicants/#{applicant_id}/documents/#{document_id}"))
14
+ def find(document_id)
15
+ get(path: "documents/#{document_id}")
16
16
  end
17
17
 
18
- def download(applicant_id, document_id)
19
- get(url: url_for("applicants/#{applicant_id}/documents/#{document_id}/download"))
18
+ def download(document_id)
19
+ get(path: "documents/#{document_id}/download")
20
20
  end
21
21
 
22
22
  def all(applicant_id)
23
- get(url: url_for("applicants/#{applicant_id}/documents"))
23
+ get(path: "documents?applicant_id=#{applicant_id}")
24
24
  end
25
25
  end
26
26
  end
@@ -0,0 +1,9 @@
1
+ module Onfido
2
+ class Extraction < Resource
3
+ def create(document_id:)
4
+ payload = { document_id: document_id }
5
+
6
+ post(path: 'extractions', payload: payload)
7
+ end
8
+ end
9
+ end
@@ -2,29 +2,24 @@ module Onfido
2
2
  class LivePhoto < Resource
3
3
  # with open-uri the file can be a link or an actual file
4
4
 
5
- def create(applicant_id, payload)
6
- validate_file!(payload.fetch(:file))
5
+ def create(applicant_id:, file:, **payload)
6
+ validate_file!(file)
7
7
  payload[:applicant_id] = applicant_id
8
+ payload[:file] = file
8
9
 
9
- post(
10
- url: url_for("/live_photos"),
11
- payload: payload
12
- )
10
+ post(path: 'live_photos', payload: payload)
13
11
  end
14
12
 
15
- def find(applicant_id, live_photo_id)
16
- query_string = "applicant_id=#{applicant_id}"
17
- get(url: url_for("live_photos/#{live_photo_id}?#{query_string}"))
13
+ def find(live_photo_id)
14
+ get(path: "live_photos/#{live_photo_id}")
18
15
  end
19
16
 
20
- def download(applicant_id, live_photo_id)
21
- query_string = "applicant_id=#{applicant_id}"
22
- get(url: url_for("live_photos/#{live_photo_id}/download?#{query_string}"))
17
+ def download(live_photo_id)
18
+ get(path: "live_photos/#{live_photo_id}/download")
23
19
  end
24
20
 
25
21
  def all(applicant_id)
26
- query_string = "applicant_id=#{applicant_id}"
27
- get(url: url_for("live_photos?#{query_string}"))
22
+ get(path: "live_photos?applicant_id=#{applicant_id}")
28
23
  end
29
24
  end
30
25
  end
@@ -1,18 +1,15 @@
1
1
  module Onfido
2
2
  class LiveVideo < Resource
3
- def find(applicant_id, live_video_id)
4
- query_string = "applicant_id=#{applicant_id}"
5
- get(url: url_for("live_videos/#{live_video_id}?#{query_string}"))
3
+ def find(live_video_id)
4
+ get(path: "live_videos/#{live_video_id}")
6
5
  end
7
6
 
8
- def download(applicant_id, live_video_id)
9
- query_string = "applicant_id=#{applicant_id}"
10
- get(url: url_for("live_videos/#{live_video_id}/download?#{query_string}"))
7
+ def download(live_video_id)
8
+ get(path: "live_videos/#{live_video_id}/download")
11
9
  end
12
10
 
13
11
  def all(applicant_id)
14
- query_string = "applicant_id=#{applicant_id}"
15
- get(url: url_for("live_videos?#{query_string}"))
12
+ get(path: "live_videos?applicant_id=#{applicant_id}")
16
13
  end
17
14
  end
18
15
  end
@@ -1,20 +1,19 @@
1
1
  module Onfido
2
2
  class Report < Resource
3
- def find(check_id, report_id)
4
- get(url: url_for("checks/#{check_id}/reports/#{report_id}"))
3
+ def find(report_id)
4
+ get(path: "reports/#{report_id}")
5
5
  end
6
6
 
7
- def all(check_id, page: 1, per_page: 20)
8
- querystring = "page=#{page}&per_page=#{per_page}"
9
- get(url: url_for("checks/#{check_id}/reports?#{querystring}"))
7
+ def all(check_id)
8
+ get(path: "reports?check_id=#{check_id}")
10
9
  end
11
10
 
12
- def resume(check_id, report_id)
13
- post(url: url_for("checks/#{check_id}/reports/#{report_id}/resume"))
11
+ def resume(report_id)
12
+ post(path: "reports/#{report_id}/resume")
14
13
  end
15
14
 
16
- def cancel(check_id, report_id)
17
- post(url: url_for("checks/#{check_id}/reports/#{report_id}/cancel"))
15
+ def cancel(report_id)
16
+ post(path: "reports/#{report_id}/cancel")
18
17
  end
19
18
  end
20
19
  end
@@ -1,10 +1,8 @@
1
1
  module Onfido
2
2
  class SdkToken < Resource
3
- def create(payload)
4
- post(
5
- url: url_for("sdk_token"),
6
- payload: payload
7
- )
3
+ def create(applicant_id:, **payload)
4
+ payload[:applicant_id] = applicant_id
5
+ post(path: 'sdk_token', payload: payload)
8
6
  end
9
7
  end
10
8
  end
@@ -1,18 +1,20 @@
1
1
  module Onfido
2
2
  class Webhook < Resource
3
- def create(payload)
4
- post(
5
- url: url_for('webhooks'),
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(url: url_for("webhooks/#{webhooks_id}"))
9
+ get(path: "webhooks/#{webhooks_id}")
12
10
  end
13
11
 
14
- def all(page: 1, per_page: 20)
15
- get(url: url_for("webhooks?page=#{page}&per_page=#{per_page}"))
12
+ def all
13
+ get(path: 'webhooks')
14
+ end
15
+
16
+ def destroy(webhook_id)
17
+ delete(path: "webhooks/#{webhook_id}")
16
18
  end
17
19
 
18
20
  # As well as being a normal resource, Onfido::Webhook also supports
@@ -29,7 +31,7 @@ module Onfido
29
31
  end
30
32
 
31
33
  def self.generate_signature(request_body, token)
32
- OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), token, request_body)
34
+ OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), token, request_body)
33
35
  end
34
36
  private_class_method :generate_signature
35
37
  end
@@ -1,3 +1,3 @@
1
1
  module Onfido
2
- VERSION = '0.14.0'.freeze
2
+ VERSION = '1.1.1'.freeze
3
3
  end
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 = ['Pericles Theodorou', 'Grey Baker']
11
- spec.email = ['periclestheo@gmail.com', 'grey@gocardless.com']
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
- "both v1 and v2 of the Onfido API. Refer to Onfido's "\
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 for both."
17
- spec.homepage = 'http://github.com/hvssle/onfido'
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")
@@ -23,7 +23,6 @@ Gem::Specification.new do |spec|
23
23
  spec.require_paths = ['lib']
24
24
  spec.required_ruby_version = ">= 2.2.0"
25
25
 
26
- spec.add_development_dependency 'bundler', '~> 1.7'
27
26
  spec.add_development_dependency 'rake', '~> 12.0'
28
27
  spec.add_development_dependency 'rspec', '~> 3.1'
29
28
  spec.add_development_dependency 'rspec-its', '~> 1.2'
@@ -4,6 +4,7 @@ describe Onfido::Address do
4
4
  describe '#all' do
5
5
  it 'returns the addresses matching the postcode' do
6
6
  response = api.address.all('SW1 4NG')
7
+
7
8
  expect(response['addresses'].count).to eq(2)
8
9
  end
9
10
  end
@@ -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
- 'addresses' => [
15
- {
16
- 'flat_number' => '4',
17
- 'building_number' => '100',
18
- 'building_name' => 'Awesome Building',
19
- 'street' => 'Main Street',
20
- 'sub_street' => 'A sub street',
21
- 'town' => 'London',
22
- 'postcode' => 'SW4 6EH',
23
- 'country' => 'GBR'
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 == 'v2/applicants'
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,21 +84,21 @@ 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')
117
- expect(error.fields).to eq("Applicant #{applicant_id} is not scheduled for deletion")
99
+ expect(error.fields).to eq(
100
+ "Applicant a2fb9c62-ab10-4898-a8ec-342c4b552ad5 is not scheduled for deletion"
101
+ )
118
102
  }
119
103
  end
120
104
  end
@@ -1,59 +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(applicant_id, params)
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(applicant_id, check_id)
18
+ response = check.find(check_id)
19
+
19
20
  expect(response['id']).to eq(check_id)
20
21
  end
21
22
 
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
23
+ it "returns report_ids" do
24
+ response = check.find(check_id)
26
25
 
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)
26
+ expect(response['report_ids'].first).to be_a(String)
30
27
  end
31
28
  end
32
29
 
33
30
  describe '#all' do
34
- let(:check_id) { '8546921-123123-123123' }
35
-
36
31
  context 'with the default page and per page params' do
37
32
  it 'returns all existing checks for the applicant' do
38
33
  response = check.all(applicant_id)
34
+
39
35
  expect(response['checks'].size).to eq(1)
40
36
  end
41
37
  end
42
38
 
43
- it "returns unexpanded reports" do
39
+ it "returns report_ids" do
44
40
  response = check.all(applicant_id)
45
- expect(response['checks'].first['reports'].first).to be_a(String)
46
- end
47
41
 
48
- it 'allows you to expand the reports' do
49
- response = check.all(applicant_id, expand: "reports")
50
- expect(response['checks'].first['reports'].first).to be_a(Hash)
42
+ expect(response['checks'].first['report_ids'].first).to be_a(String)
51
43
  end
52
44
  end
53
45
 
54
46
  describe "#resume" do
55
- let(:check_id) { '8546921-123123-123123' }
56
-
57
47
  it 'returns success response' do
58
48
  expect { check.resume(check_id) }.not_to raise_error
59
49
  end