onfido 0.15.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/LICENSE +2 -1
  4. data/README.md +18 -32
  5. data/lib/onfido.rb +0 -1
  6. data/lib/onfido/api.rb +0 -4
  7. data/lib/onfido/configuration.rb +2 -3
  8. data/lib/onfido/resource.rb +1 -5
  9. data/lib/onfido/resources/address.rb +1 -1
  10. data/lib/onfido/resources/applicant.rb +6 -6
  11. data/lib/onfido/resources/check.rb +9 -19
  12. data/lib/onfido/resources/document.rb +11 -11
  13. data/lib/onfido/resources/live_photo.rb +9 -14
  14. data/lib/onfido/resources/live_video.rb +5 -8
  15. data/lib/onfido/resources/report.rb +8 -9
  16. data/lib/onfido/resources/sdk_token.rb +3 -5
  17. data/lib/onfido/resources/webhook.rb +7 -9
  18. data/lib/onfido/version.rb +1 -1
  19. data/onfido.gemspec +6 -6
  20. data/spec/integrations/address_spec.rb +1 -0
  21. data/spec/integrations/applicant_spec.rb +18 -36
  22. data/spec/integrations/check_spec.rb +13 -67
  23. data/spec/integrations/document_spec.rb +16 -17
  24. data/spec/integrations/exceptions_spec.rb +12 -13
  25. data/spec/integrations/live_photo_spec.rb +12 -13
  26. data/spec/integrations/live_video_spec.rb +7 -10
  27. data/spec/integrations/report_spec.rb +11 -13
  28. data/spec/integrations/sdk_token_spec.rb +5 -5
  29. data/spec/integrations/webhook_spec.rb +26 -18
  30. data/spec/onfido/resource_spec.rb +6 -12
  31. data/spec/onfido_spec.rb +3 -11
  32. data/spec/support/fake_onfido_api.rb +44 -78
  33. data/spec/support/fixtures/applicant.json +21 -42
  34. data/spec/support/fixtures/check.json +4 -4
  35. data/spec/support/fixtures/checks.json +4 -4
  36. data/spec/support/fixtures/document.json +2 -2
  37. data/spec/support/fixtures/documents.json +8 -8
  38. data/spec/support/fixtures/live_photo.json +3 -3
  39. data/spec/support/fixtures/live_photos.json +6 -6
  40. data/spec/support/fixtures/live_video.json +3 -3
  41. data/spec/support/fixtures/live_videos.json +4 -4
  42. data/spec/support/fixtures/report.json +4 -4
  43. data/spec/support/fixtures/reports.json +8 -8
  44. data/spec/support/fixtures/webhook.json +6 -5
  45. data/spec/support/fixtures/webhooks.json +17 -12
  46. metadata +9 -22
  47. data/lib/onfido/resources/report_type_group.rb +0 -11
  48. data/spec/integrations/report_type_group_spec.rb +0 -19
  49. data/spec/support/fixtures/check_with_expanded_reports.json +0 -30
  50. data/spec/support/fixtures/checks_with_expanded_reports.json +0 -34
  51. data/spec/support/fixtures/report_type_group.json +0 -25
  52. data/spec/support/fixtures/report_type_groups.json +0 -30
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 94d4e590e003b1ff219091a7690385782a3aa1ef7ee46000f185cf183a81702e
4
- data.tar.gz: 1961655f50cdf2f8148e83310b2d0bbebd0c3139ed3de5b63f3c001d398b02d3
3
+ metadata.gz: 7c2b7ace145ea9b4804afb24664f452851753bb15dca4221e94c43cf1db6f96e
4
+ data.tar.gz: c0477b41310dc691e99a218d03a40777c5e91d3e1cc72d90884f9d6d01772a3e
5
5
  SHA512:
6
- metadata.gz: 490a955c369dd6934ac60685ef628cc6a821b461efa13113b7e381aa5bd1a6bb958996d1ed2add552f661d18236112a541fb900b2c6a54e09ef9eaa37f2a1346
7
- data.tar.gz: 72d9cdadfc3f73c75464cbe7fe7cb36b764ac2c420fa7afb2268e2a5d31b9c1139d5829faa2d9e830a3bd7b02d2ec12203c66e80b80c92947a0be0f58166c7e8
6
+ metadata.gz: 598a9e0fcf166be224cf0b28dd0f8ca92f8e285ac3955d7ff06ad450bd018741ce580f99de6e506100f879ef5002e485926fec8d741d7bb313d496486f4ffb48
7
+ data.tar.gz: 1786150e8f9b3d8d7b1bec8aad0ff35565c77e3000c70534757aec49ae85fff9c15deb398e53d2676337b3ff9432a25ed48a690833112304ad91d249ae82f550
@@ -1,3 +1,8 @@
1
+ ## v1.0.0, 13 Jan 2020
2
+
3
+ - Support Onfido API version 3
4
+ - Drop support for Onfido API version 2
5
+
1
6
  ## v0.15.0, 4 Feb 2019
2
7
 
3
8
  - Add Check#find_by_url method (@ctrlaltdylan)
data/LICENSE CHANGED
@@ -1,6 +1,7 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015 Hassle
3
+ Original work Copyright (c) 2015 Hassle
4
+ Modified work Copyright 2019 Onfido
4
5
 
5
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
7
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -3,28 +3,30 @@
3
3
  A thin wrapper for Onfido's API.
4
4
 
5
5
  [![Gem Version](https://badge.fury.io/rb/onfido.svg)](http://badge.fury.io/rb/onfido)
6
- [![Build Status](https://travis-ci.org/hvssle/onfido.svg?branch=master)](https://travis-ci.org/hvssle/onfido)
6
+ [![Build Status](https://travis-ci.org/onfido/onfido-ruby.svg?branch=master)](https://travis-ci.org/onfido/onfido-ruby)
7
+
8
+ This gem supports only `v3` of Onfido's API from version `1.0.0` ownards.
9
+ The latest version that supports `v2` of Onfido's API is `0.15.0`. `v1` of Onfido's API is deprecated
10
+ Refer to Onfido's [API documentation](https://documentation.onfido.com) for details of the expected requests and responses.
7
11
 
8
- This gem supports both `v1` and `v2` of the Onfido API. Refer to Onfido's [API documentation](https://onfido.com/documentation#introduction) for details of the expected requests and responses for both.
9
12
 
10
13
  ## Installation
11
14
 
12
15
  Add this line to your application's Gemfile:
13
16
 
14
17
  ```ruby
15
- gem 'onfido', '~> 0.15.0'
18
+ gem 'onfido', '~> 1.0.0'
16
19
  ```
17
20
 
18
21
  The gem is compatible with Ruby 2.2.0 and onwards. Earlier versions of Ruby have [reached end-of-life](https://www.ruby-lang.org/en/news/2017/04/01/support-of-ruby-2-1-has-ended/), are no longer supported and no longer receive security fixes.
19
22
 
20
23
  ## Configuration
21
24
 
22
- There are 6 configuration options:
25
+ There are 5 configuration options:
23
26
 
24
27
  ```ruby
25
28
  Onfido.configure do |config|
26
29
  config.api_key = 'MY_API_KEY'
27
- config.api_version = 'v2'
28
30
  config.logger = Logger.new(STDOUT)
29
31
  config.open_timeout = 30
30
32
  config.read_timeout = 80
@@ -59,7 +61,7 @@ api = Onfido::API.new(api_key: 'API_KEY')
59
61
 
60
62
  All resources share the same interface when making API calls. Use `.create` to create a resource, `.find` to find one, and `.all` to fetch all resources.
61
63
 
62
- **Note:** *All param keys should be a symbol e.g. `{ type: 'express', reports: [{ name: 'identity' }] }`*
64
+ **Note:** *All param keys should be a symbol e.g. `{ report_names: ['document'] }`*
63
65
 
64
66
  #### Applicants
65
67
 
@@ -83,8 +85,8 @@ Documents provide supporting evidence for Onfido checks.
83
85
 
84
86
  ```ruby
85
87
  api.document.create('applicant_id', file: 'http://example.com', type: 'passport') # => Creates a document
86
- api.document.find('applicant_id', 'document_id') # => Finds a document
87
- api.document.download('applicant_id', 'document_id') # => Downloads a document as a binary data
88
+ api.document.find('document_id') # => Finds a document
89
+ api.document.download('document_id') # => Downloads a document as a binary data
88
90
  api.document.all('applicant_id') # => Returns all applicant's documents
89
91
  ```
90
92
 
@@ -99,8 +101,8 @@ Live Photos, like documents, can provide supporting evidence for Onfido checks.
99
101
 
100
102
  ```ruby
101
103
  api.live_photo.create('applicant_id', file: 'http://example.com')
102
- api.live_photo.find(applicant_id, live_photo_id) # => Finds a live photo
103
- api.live_photo.download(applicant_id, live_photo_id) # => Downloads a live photo as binary data
104
+ api.live_photo.find(live_photo_id) # => Finds a live photo
105
+ api.live_photo.download(live_photo_id) # => Downloads a live photo as binary data
104
106
  api.live_photo.all(applicant_id) # => Returns all applicant's live photos
105
107
  ```
106
108
 
@@ -115,9 +117,8 @@ Checks are requests for Onfido to check an applicant, by commissioning one or
115
117
  more "reports" on them.
116
118
 
117
119
  ```ruby
118
- api.check.create('applicant_id', type: 'express', reports: [{ name: 'identity' }])
119
- api.check.find('applicant_id', 'check_id')
120
- api.check.find_by_url(params[:payload][:object][:href])
120
+ api.check.create('applicant_id', report_names: ['document'])
121
+ api.check.find('check_id')
121
122
  api.check.resume('check_id')
122
123
  api.check.all('applicant_id')
123
124
  ```
@@ -130,20 +131,10 @@ finding and listing them. For paused reports specifically, additional support fo
130
131
  cancelling reports is also available.
131
132
 
132
133
  ```ruby
133
- api.report.find('check_id', 'report_id')
134
+ api.report.find('report_id')
134
135
  api.report.all('check_id')
135
- api.report.resume('check_id', 'report_id')
136
- api.report.cancel('check_id', 'report_id')
137
- ```
138
-
139
- #### Report Type Groups
140
-
141
- Report type groups provide a convenient way to group and organize different types of reports.
142
- The Onfido API only provides support for finding and listing them.
143
-
144
- ```ruby
145
- api.report_type_group.find('report_type_group_id')
146
- api.report_type_group.all()
136
+ api.report.resume('report_id')
137
+ api.report.cancel('report_id')
147
138
  ```
148
139
 
149
140
  #### Address Lookups
@@ -176,11 +167,6 @@ with Onfido's [JavaScript SDK](https://github.com/onfido/onfido-sdk-ui).
176
167
  api.sdk_token.create(applicant_id: 'applicant_id', referrer: 'referrer')
177
168
  ```
178
169
 
179
- ### Pagination
180
-
181
- All resources that support an `all` method also support pagination. By default,
182
- the first 20 records are fetched.
183
-
184
170
  ### Error Handling
185
171
 
186
172
  There are three classes of errors raised by the library, all of which subclass `Onfido::OnfidoError`:
@@ -224,7 +210,7 @@ end
224
210
 
225
211
  ## Contributing
226
212
 
227
- 1. Fork it ( https://github.com/hvssle/onfido/fork )
213
+ 1. Fork it ( https://github.com/onfido/onfido/fork )
228
214
  2. Create your feature branch (`git checkout -b my-new-feature`)
229
215
  3. Commit your changes (`git commit -am 'Add some feature'`)
230
216
  4. Push to the branch (`git push origin my-new-feature`)
@@ -19,7 +19,6 @@ require 'onfido/resources/document'
19
19
  require 'onfido/resources/live_photo'
20
20
  require 'onfido/resources/live_video'
21
21
  require 'onfido/resources/report'
22
- require 'onfido/resources/report_type_group'
23
22
  require 'onfido/resources/sdk_token'
24
23
  require 'onfido/resources/webhook'
25
24
 
@@ -28,10 +28,6 @@ module Onfido
28
28
  Onfido::Report.new(@api_key)
29
29
  end
30
30
 
31
- def report_type_group
32
- Onfido::ReportTypeGroup.new(@api_key)
33
- end
34
-
35
31
  def sdk_token
36
32
  Onfido::SdkToken.new(@api_key)
37
33
  end
@@ -4,7 +4,7 @@ module Onfido
4
4
  us: "api.us.onfido.com"
5
5
  }.freeze
6
6
 
7
- attr_accessor :api_key, :region, :open_timeout, :read_timeout, :api_version
7
+ attr_accessor :api_key, :region, :open_timeout, :read_timeout
8
8
 
9
9
  def self.extended(base)
10
10
  base.reset
@@ -19,7 +19,6 @@ module Onfido
19
19
  self.region = nil
20
20
  self.open_timeout = 30
21
21
  self.read_timeout = 80
22
- self.api_version = 'v2'
23
22
  RestClient.log = nil
24
23
  end
25
24
 
@@ -41,7 +40,7 @@ module Onfido
41
40
  raise "The region \"#{region.downcase}\" is not currently supported"
42
41
  end
43
42
 
44
- "https://#{region_host}/#{api_version}/"
43
+ "https://#{region_host}/v3/"
45
44
  end
46
45
  end
47
46
  end
@@ -7,15 +7,11 @@ module Onfido
7
7
  @api_key = api_key || Onfido.api_key
8
8
  end
9
9
 
10
- def url_for(path)
11
- Onfido.endpoint + path
12
- end
13
-
14
10
  VALID_HTTP_METHODS.each do |method|
15
11
  define_method method do |*args|
16
12
  make_request(
17
13
  method: method.to_sym,
18
- url: args.first.fetch(:url),
14
+ url: Onfido.endpoint + args.first.fetch(:path),
19
15
  payload: build_query(args.first.fetch(:payload, {}))
20
16
  )
21
17
  end
@@ -2,7 +2,7 @@ module Onfido
2
2
  class Address < Resource
3
3
  def all(postcode)
4
4
  get(
5
- url: url_for('addresses/pick'),
5
+ path: 'addresses/pick',
6
6
  payload: { postcode: postcode.delete(' ') }
7
7
  )
8
8
  end
@@ -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,32 +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
- )
8
- end
3
+ def create(applicant_id:, report_names:, **payload)
4
+ payload[:applicant_id] = applicant_id
5
+ payload[:report_names] = report_names
9
6
 
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}"))
7
+ post(path: 'checks', payload: payload)
14
8
  end
15
9
 
16
- def find_by_url(url, expand: nil)
17
- url_path = url.sub(%r/^https\:\/\/api\.onfido\.com\/v2\//, '')
18
- querystring = "&expand=#{expand}" if expand
19
- get(url: url_for("#{url_path}?#{querystring}"))
10
+ def find(check_id)
11
+ get(path: "checks/#{check_id}")
20
12
  end
21
13
 
22
- def all(applicant_id, page: 1, per_page: 20, expand: nil)
23
- querystring = "page=#{page}&per_page=#{per_page}"
24
- querystring += "&expand=#{expand}" if expand
25
- get(url: url_for("applicants/#{applicant_id}/checks?#{querystring}"))
14
+ def all(applicant_id)
15
+ get(path: "checks?applicant_id=#{applicant_id}")
26
16
  end
27
17
 
28
18
  def resume(check_id)
29
- post(url: url_for("checks/#{check_id}/resume"))
19
+ post(path: "checks/#{check_id}/resume")
30
20
  end
31
21
  end
32
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
@@ -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