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
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/v2/') }
14
+ it { is_expected.to eq('https://api.onfido.com/v3/') }
15
15
  end
16
16
 
17
17
  describe ".logger" do
@@ -27,18 +27,17 @@ describe Onfido do
27
27
  end
28
28
  end
29
29
 
30
- describe "setting the API version" do
31
- it 'changes the configuration to the new value' do
32
- onfido.api_version = 'v1'
33
- expect(onfido.api_version).to eq('v1')
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 the US region' do
37
+ describe 'using the CA region' do
39
38
  it 'should change endpoint' do
40
- onfido.region = 'us'
41
- expect(onfido.endpoint).to eq('https://api.us.onfido.com/v2/')
39
+ onfido.region = 'ca'
40
+ expect(onfido.endpoint).to eq('https://api.ca.onfido.com/v3/')
42
41
  end
43
42
  end
44
43
 
@@ -53,7 +52,7 @@ describe Onfido do
53
52
  describe 'using an old API token' do
54
53
  it 'should use old endpoint' do
55
54
  onfido.api_key = "live_asdfghjkl1234567890qwertyuiop"
56
- expect(onfido.endpoint).to eq('https://api.onfido.com/v2/')
55
+ expect(onfido.endpoint).to eq('https://api.onfido.com/v3/')
57
56
  end
58
57
  end
59
58
 
@@ -1,32 +1,32 @@
1
1
  require 'sinatra/base'
2
2
 
3
3
  class FakeOnfidoAPI < Sinatra::Base
4
- get '/v2/addresses/pick' do
4
+ get '/v3/addresses/pick' do
5
5
  json_response(200, 'addresses.json')
6
6
  end
7
7
 
8
- post '/v2/applicants' do
8
+ post '/v3/applicants' do
9
9
  json_response(201, 'applicant.json')
10
10
  end
11
11
 
12
- put '/v2/applicants/:id' do
12
+ put '/v3/applicants/:id' do
13
13
  json_response(200, 'applicant.json')
14
14
  end
15
15
 
16
- get '/v2/applicants/:id' do
16
+ get '/v3/applicants/:id' do
17
17
  json_response(200, 'applicant.json')
18
18
  end
19
19
 
20
- get '/v2/applicants' do
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 '/v2/applicants/:id' do
25
+ delete '/v3/applicants/:id' do
26
26
  status 204
27
27
  end
28
28
 
29
- post '/v2/applicants/:id/restore' do
29
+ post '/v3/applicants/:id/restore' do
30
30
  if params["id"] == "a2fb9c62-ab10-4898-a8ec-342c4b552ad5"
31
31
  json_response(422, 'not_scheduled_for_deletion_error.json')
32
32
  else
@@ -34,37 +34,37 @@ class FakeOnfidoAPI < Sinatra::Base
34
34
  end
35
35
  end
36
36
 
37
- post '/v2/applicants/:id/documents' do
37
+ post '/v3/documents' do
38
38
  json_response(201, 'document.json')
39
39
  end
40
40
 
41
- get '/v2/applicants/:id/documents/:id' do
41
+ post '/v3/extractions' do
42
+ json_response(201, 'extraction.json')
43
+ end
44
+
45
+ get '/v3/documents/:id' do
42
46
  json_response(200, 'document.json')
43
47
  end
44
48
 
45
- get '/v2/applicants/:id/documents' do
49
+ get '/v3/documents' do
46
50
  json_response(200, 'documents.json')
47
51
  end
48
52
 
49
- get '/v2/applicants/:id/documents/:id/download' do
53
+ get '/v3/documents/:id/download' do
50
54
  status 200
51
55
  content_type 'application/octet-stream'
52
56
  "\x01\x02\x03" # acts as binary file data
53
57
  end
54
58
 
55
- post '/v2/live_photos' do
59
+ post '/v3/live_photos' do
56
60
  json_response(201, 'live_photo.json')
57
61
  end
58
62
 
59
- get '/v2/live_photos/:id' do
60
- if params["applicant_id"] != "1030303-123123-123123"
61
- status 404
62
- else
63
- json_response(200, 'live_photo.json')
64
- end
63
+ get '/v3/live_photos/:id' do
64
+ json_response(200, 'live_photo.json')
65
65
  end
66
66
 
67
- get '/v2/live_photos' do
67
+ get '/v3/live_photos' do
68
68
  if params["applicant_id"] != "1030303-123123-123123"
69
69
  status 404
70
70
  else
@@ -72,25 +72,17 @@ class FakeOnfidoAPI < Sinatra::Base
72
72
  end
73
73
  end
74
74
 
75
- get '/v2/live_photos/:id/download' do
76
- if params["applicant_id"] != "1030303-123123-123123"
77
- status 404
78
- else
79
- status 200
80
- content_type 'image/jpeg'
81
- "\x01\x02\x03" # acts as binary file data
82
- 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
83
79
  end
84
80
 
85
- get '/v2/live_videos/:id' do
86
- if params["applicant_id"] != "1030303-123123-123123"
87
- status 404
88
- else
89
- json_response(200, 'live_video.json')
90
- end
81
+ get '/v3/live_videos/:id' do
82
+ json_response(200, 'live_video.json')
91
83
  end
92
84
 
93
- get '/v2/live_videos' do
85
+ get '/v3/live_videos' do
94
86
  if params["applicant_id"] != "1030303-123123-123123"
95
87
  status 404
96
88
  else
@@ -98,91 +90,74 @@ class FakeOnfidoAPI < Sinatra::Base
98
90
  end
99
91
  end
100
92
 
101
- get '/v2/live_videos/:id/download' do
102
- if params["applicant_id"] != "1030303-123123-123123"
103
- status 404
104
- else
105
- status 200
106
- content_type 'video/quicktime'
107
- "\x01\x02\x03" # acts as binary file data
108
- 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
109
97
  end
110
98
 
111
- post '/v2/applicants/:id/checks' do
112
- json_response(201, 'check.json')
99
+ post '/v3/checks' do
100
+ params["applicant_id"].nil? ? status(422) : json_response(201, 'check.json')
113
101
  end
114
102
 
115
- get '/v2/applicants/:id/checks/:id' do
116
- if params["expand"] == "reports"
117
- json_response(200, "check_with_expanded_reports.json")
118
- else
119
- json_response(200, "check.json")
120
- end
103
+ get '/v3/checks/:id' do
104
+ json_response(200, "check.json")
121
105
  end
122
106
 
123
- get '/v2/applicants/:id/checks' do
124
- response = if params["expand"] == "reports"
125
- json_response(200, "checks_with_expanded_reports.json")
126
- else
127
- json_response(200, "checks.json")
128
- end
129
-
130
- { checks: JSON.parse(response)['checks'][pagination_range] }.to_json
107
+ get '/v3/checks' do
108
+ json_response(200, "checks.json")
131
109
  end
132
110
 
133
- post '/v2/checks/:id/resume' do
111
+ post '/v3/checks/:id/resume' do
134
112
  status 204 # no_content
135
113
  end
136
114
 
137
- get '/v2/checks/:id/reports' do
115
+ get '/v3/reports' do
138
116
  json_response(200, 'reports.json')
139
117
  end
140
118
 
141
- get '/v2/checks/:id/reports/:id' do
119
+ get '/v3/reports/:id' do
142
120
  json_response(200, 'report.json')
143
121
  end
144
122
 
145
- post '/v2/checks/:id/reports/:id/resume' do
123
+ post '/v3/reports/:id/resume' do
146
124
  status 204
147
125
  end
148
126
 
149
- post '/v2/checks/:id/reports/:id/cancel' do
127
+ post '/v3/reports/:id/cancel' do
150
128
  status 204
151
129
  end
152
130
 
153
- get '/v2/report_type_groups/:id' do
154
- json_response(200, 'report_type_group.json')
155
- end
156
-
157
- get '/v2/report_type_groups' do
158
- json_response(200, 'report_type_groups.json')
159
- end
160
-
161
- post '/v2/sdk_token' do
131
+ post '/v3/sdk_token' do
162
132
  json_response(201, 'sdk_token.json')
163
133
  end
164
134
 
165
- post '/v2/webhooks' do
135
+ post '/v3/webhooks' do
166
136
  json_response(201, 'webhook.json')
167
137
  end
168
138
 
169
- get '/v2/webhooks/:id' do
139
+ get '/v3/webhooks/:id' do
170
140
  json_response(200, 'webhook.json')
171
141
  end
172
142
 
173
- get '/v2/webhooks' do
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
174
149
  json_response(200, 'webhooks.json')
175
150
  end
176
151
 
177
- get '/v2/4xx_response' do
152
+ get '/v3/4xx_response' do
178
153
  json_response(422, '4xx_response.json')
179
154
  end
180
155
 
181
- get '/v2/unexpected_error_format' do
156
+ get '/v3/unexpected_error_format' do
182
157
  json_response(400, 'unexpected_error_format.json')
183
158
  end
184
159
 
185
- get '/v2/unparseable_response' do
160
+ get '/v3/unparseable_response' do
186
161
  content_type :json
187
162
  status 504
188
163
  ''
@@ -1,44 +1,23 @@
1
1
  {
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
- "gender":"Male",
10
- "dob":"1968-04-08",
11
- "telephone":"555555555",
12
- "mobile":"77777777",
13
- "country":"gbr",
14
- "href":"/v2/applicants/61f659cb-c90b-4067-808a-6136b5c01351",
15
- "id_numbers":[],
16
- "addresses": [
17
- {
18
- "flat_number":"4",
19
- "building_number":"100",
20
- "building_name":"Awesome Building",
21
- "street":"Main Street",
22
- "sub_street":"A sub street",
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": "2014-05-23T13:50:33Z",
4
- "href": "/v2/applicants/61f659cb-c90b-4067-808a-6136b5c01351/checks/8546921-123123-123123",
5
- "type": "standard",
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
- "reports": [
8
+ "report_ids": [
9
9
  "1030303-123123-375629",
10
10
  "1030303-123123-456789"
11
11
  ]
@@ -2,12 +2,12 @@
2
2
  "checks": [
3
3
  {
4
4
  "id": "8546921-123123-123123",
5
- "created_at": "2014-05-23T13:50:33Z",
6
- "href": "/v2/applicants/61f659cb-c90b-4067-808a-6136b5c01351/checks/8546921-123123-123123",
7
- "type": "standard",
5
+ "created_at": "2019-11-23T13:50:33Z",
6
+ "href": "/v3/checks/8546921-123123-123123",
7
+ "applicant_provides_data": "false",
8
8
  "status": "pending",
9
9
  "result": "pending",
10
- "reports": [
10
+ "report_ids": [
11
11
  "1030303-123123-375629",
12
12
  "1030303-123123-456789"
13
13
  ]
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "id": "7568415-123123-123123",
3
- "created_at": "2014-05-23 13:50:33Z",
4
- "href": "/v2/applicants/1030303-123123-123123/documents/7568415-123123-123123",
3
+ "created_at": "2019-11-23 13:50:33Z",
4
+ "href": "/v3/documents/7568415-123123-123123",
5
5
  "file_name": "passport.jpg",
6
6
  "file_type": "png",
7
7
  "file_size": 282870,
@@ -2,22 +2,22 @@
2
2
  "documents": [
3
3
  {
4
4
  "id": "7568415-123123-123123",
5
- "created_at": "2014-05-23 13:50:33Z",
6
- "href": "/v2/applicants/1030303-123123-123123/documents/7568415-123123-123123",
5
+ "created_at": "2019-11-23 13:50:33Z",
6
+ "href": "/v3/documents/7568415-123123-123123",
7
7
  "file_name": "passport.jpg",
8
8
  "file_type": "png",
9
9
  "file_size": 282870,
10
- "type": "passport",
11
- "side": "back"
10
+ "type": "passport"
12
11
  },
13
12
  {
14
13
  "id": "121122-123123-123123",
15
- "created_at": "2014-05-23 13:50:33Z",
16
- "href": "/v2/applicants/1030303-123123-123123/documents/7568415-123123-123123",
17
- "file_name": "right_to_work.png",
14
+ "created_at": "2019-11-23 13:50:40Z",
15
+ "href": "/v3/documents/7568415-123123-123123",
16
+ "file_name": "driving_licence.png",
18
17
  "file_type": "png",
19
18
  "file_size": 282870,
20
- "type": "right_to_work"
19
+ "type": "driving_licence",
20
+ "side": "front"
21
21
  }
22
22
  ]
23
23
  }
@@ -0,0 +1,23 @@
1
+ {
2
+ "document_id": "7568415-123123-123123",
3
+ "document_classification": {
4
+ "issuing_country": "FRA",
5
+ "document_type": "national_identity_card"
6
+ },
7
+ "extracted_data": {
8
+ "date_of_birth": "1965-09-08",
9
+ "document_number": "400925733",
10
+ "first_name": "MARIE",
11
+ "gender": "Female",
12
+ "last_name": "MAVARINE",
13
+ "mrz_line1": "P<GBRDU<MARIE<<MAVARINE<<<<<<<<<<<<<<<<<<<<<",
14
+ "mrz_line2": "4009257333GBR6509088F1307072<<<<<<<<<<<<<<06",
15
+ "nationality": "BRITISH CITIZEN",
16
+ "full_name": "MAVARINE DU MARIE",
17
+ "date_of_expiry": "2013-07-07",
18
+ "middle_name": "DU",
19
+ "address_line_1": "52 RUE DES FLEURS",
20
+ "address_line_2": "33500 BORDEAUX",
21
+ "address_line_3": "FRANCE"
22
+ }
23
+ }