onfido 0.12.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +4 -3
  3. data/.travis.yml +8 -7
  4. data/CHANGELOG.md +23 -0
  5. data/LICENSE +2 -1
  6. data/README.md +70 -70
  7. data/lib/onfido.rb +1 -1
  8. data/lib/onfido/api.rb +4 -4
  9. data/lib/onfido/configuration.rb +12 -16
  10. data/lib/onfido/resource.rb +3 -6
  11. data/lib/onfido/resources/address.rb +1 -1
  12. data/lib/onfido/resources/applicant.rb +9 -5
  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 +8 -9
  23. data/spec/integrations/address_spec.rb +1 -0
  24. data/spec/integrations/applicant_spec.rb +38 -32
  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 -13
  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 +13 -13
  36. data/spec/support/fake_onfido_api.rb +60 -77
  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 +22 -42
  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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 8db5e90cf91e9eebbeed0ecb56e8e2940c430fa8ea742a5eef3959bafa3cec16
4
- data.tar.gz: 995f57f45b8c0109499b8167edf6ecc6b9212c5c0391676338ef3f23e5539361
2
+ SHA1:
3
+ metadata.gz: 8749aa43cbc394686f1ff769f0b0ada44c541a9c
4
+ data.tar.gz: f6e314d3f734e8eb315f97daa6765c0904bec8db
5
5
  SHA512:
6
- metadata.gz: 3f506b59b42c1b5639a402d369f99aee0bc9f59a9036c2257c0209c431e7a487b0b6e961a17b966c8ea0f928241c148233a0424b36b8fed4b04d91793722f961
7
- data.tar.gz: 72f1c306e8b8dc23e3d669f8968af77f319a7c46539aa8d2f4407b18bdbb2baafabb292bafd61211f249067deb8a56ad3d0d44ff3c78d78f05fcd6069dd43022
6
+ metadata.gz: f2db07995e16031cb9b04da83497400f082fb1fdac289761b46481ab83d283efbdf7bc12ac61508fa50583f081c53311c4dce8aa7cf90efda97d5c6bc4244435
7
+ data.tar.gz: 3e41ed2d4988192d230b67382e78b19209684a059aec2af1ca875234b3bf7787f17dbcdbd6004ca1ad0df12b051061d9413afffc85a6739c519d9eccfc89c1a9
@@ -2,9 +2,6 @@
2
2
 
3
3
  AllCops:
4
4
  DisplayCopNames: true
5
- Include:
6
- - Rakefile
7
- - lib/tasks/*.rake
8
5
  Exclude:
9
6
  - vendor/**/*
10
7
  - .*/**
@@ -54,3 +51,7 @@ Layout/DotPosition:
54
51
  # Allow class and message or instance raises
55
52
  Style/RaiseArgs:
56
53
  Enabled: false
54
+
55
+ Lint/AmbiguousBlockAssociation:
56
+ Exclude:
57
+ - "spec/**/*"
@@ -1,18 +1,19 @@
1
1
  language: ruby
2
-
3
- matrix:
4
- allow_failures:
5
- - rvm: jruby
6
- - rvm: rbx-2
2
+ cache: bundler
7
3
 
8
4
  rvm:
9
5
  - 2.2
10
6
  - 2.3
11
7
  - 2.4
12
8
  - 2.5
13
- - jruby
14
- - rbx-2
9
+ - 2.6
10
+ - 2.7
15
11
 
16
12
  script:
17
13
  - bundle exec rubocop
18
14
  - bundle exec rspec spec
15
+
16
+ # safelist
17
+ branches:
18
+ only:
19
+ - master
@@ -1,3 +1,26 @@
1
+ ## v1.1.0, 6 Aug 2020
2
+
3
+ - Add User-Agent header
4
+ - Add support for CA region
5
+
6
+ ## v1.0.0, 13 Jan 2020
7
+
8
+ - Support Onfido API version 3
9
+ - Drop support for Onfido API version 2
10
+ - To upgrade from 0.15.0 see the v2 to v3 migration [guide](https://developers.onfido.com/guide/v2-to-v3-migration-guide)
11
+
12
+ ## v0.15.0, 4 Feb 2019
13
+
14
+ - Add Check#find_by_url method (@ctrlaltdylan)
15
+
16
+ ## v0.14.0, 28 Jan 2019
17
+
18
+ - Add support for applicant deletion and restore endpoints
19
+
20
+ ## v0.13.0, 5 Nov 2018
21
+
22
+ - Add support for region-specific environments (@stephencookdev)
23
+
1
24
  ## v0.12.0, 29 May 2018
2
25
 
3
26
  - Add support for the Live Video resource (#55) (@Intrepidd)
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,75 +3,93 @@
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
7
 
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.
8
+ This gem supports only `v3` of Onfido's API from version `1.0.0` onwards. The latest version that supports `v2` of Onfido's API is `0.15.0`. `v1` of Onfido's API is deprecated.
9
+
10
+ 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.
11
+
12
+ Refer to Onfido's [API documentation](https://documentation.onfido.com) for details of the expected requests and responses.
9
13
 
10
14
  ## Installation
11
15
 
12
16
  Add this line to your application's Gemfile:
13
17
 
14
18
  ```ruby
15
- gem 'onfido', '~> 0.12.0'
19
+ gem 'onfido', '~> 1.1.0'
16
20
  ```
17
21
 
18
- 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
-
20
22
  ## Configuration
21
23
 
22
24
  There are 5 configuration options:
23
25
 
24
26
  ```ruby
25
27
  Onfido.configure do |config|
26
- config.api_key = 'MY_API_KEY'
27
- config.api_version = 'v2'
28
+ config.api_key = '<YOUR_API_KEY>'
28
29
  config.logger = Logger.new(STDOUT)
29
30
  config.open_timeout = 30
30
31
  config.read_timeout = 80
32
+ config.region = nil
31
33
  end
32
34
  ```
33
35
 
36
+ ### Regions
37
+
38
+ The gem will use the default region if no region is specified.
39
+
40
+ To specify the US region do:
41
+ `config.region = :us`
42
+
43
+ To specify the CA region do:
44
+ `config.region = :ca`
45
+
46
+ See https://documentation.onfido.com/#regions for supported regions.
47
+
34
48
  ## Usage
35
49
 
36
50
  You can make API calls by using an instance of the `API` class:
37
51
 
38
52
  ```ruby
39
- api = Onfido::API.new
53
+ onfido = Onfido::API.new
40
54
  ```
41
55
 
42
- Alternatively, you can set an API key here instead of in the initializer:
56
+ You can also set an API key as follows, instead of in the initializer configuration:
43
57
 
44
58
  ```ruby
45
- api = Onfido::API.new(api_key: 'API_KEY')
59
+ onfido = Onfido::API.new(api_key: '<YOUR_API_KEY>')
46
60
  ```
47
61
 
48
62
  ### Resources
49
63
 
50
64
  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.
51
65
 
52
- **Note:** *All param keys should be a symbol e.g. `{ type: 'express', reports: [{ name: 'identity' }] }`*
66
+ **Note:** *All param keys should be symbols e.g. `{ report_names: ['document'] }`*
53
67
 
54
68
  #### Applicants
55
69
 
56
70
  Applicants are the object upon which Onfido checks are performed.
57
71
 
58
72
  ```ruby
59
- api.applicant.create(params) # => Creates an applicant
60
- api.applicant.update('applicant_id', params) # => Updates an applicant
61
- api.applicant.destroy('applicant_id') # => Destroy an applicant
62
- api.applicant.find('applicant_id') # => Finds a single applicant
63
- api.applicant.all # => Returns all applicants
73
+ onfido.applicant.create(params) # => Creates an applicant
74
+ onfido.applicant.update('<APPLICANT_ID>', params) # => Updates an applicant
75
+ onfido.applicant.destroy('<APPLICANT_ID>') # => Schedule an applicant for deletion
76
+ onfido.applicant.restore('<APPLICANT_ID>') # => Restore an applicant scheduled for deletion
77
+ onfido.applicant.find('<APPLICANT_ID>') # => Finds a single applicant
78
+ onfido.applicant.all # => Returns all applicants
64
79
  ```
65
80
 
81
+ **Note:** Calling `onfido.applicant.destroy` adds the applicant and all associated documents, photos, videos, checks, and reports to the deletion queue. They will be deleted 20 days after the request is made. An applicant that is scheduled for deletion can be restored but applicants that have been permanently deleted cannot.
82
+ See https://documentation.onfido.com/#delete-applicant for more information.
83
+
66
84
  #### Documents
67
85
 
68
- Documents provide supporting evidence for Onfido checks.
86
+ Some report types require identity documents (passport, driving licence etc.) in order to be processed.
69
87
 
70
88
  ```ruby
71
- api.document.create('applicant_id', file: 'http://example.com', type: 'passport') # => Creates a document
72
- api.document.find('applicant_id', 'document_id') # => Finds a document
73
- api.document.download('applicant_id', 'document_id') # => Downloads a document as a binary data
74
- api.document.all('applicant_id') # => Returns all applicant's documents
89
+ onfido.document.create(applicant_id: '<APPLICANT_ID>', file: <FILE>, type: 'passport') # => Creates a document
90
+ onfido.document.find('<DOCUMENT_ID>') # => Finds a document
91
+ onfido.document.download('<DOCUMENT_ID>') # => Downloads a document as a binary data
92
+ onfido.document.all('<APPLICANT_ID>') # => Returns all documents belonging to an applicant
75
93
  ```
76
94
 
77
95
  **Note:** The file parameter must be a `File`-like object which responds to `#read` and `#path`.
@@ -79,15 +97,17 @@ Previous versions of this gem supported providing a URL to a file accessible ove
79
97
  to a file in the local filesystem. You should instead load the file yourself and then pass it in
80
98
  to `#create`.
81
99
 
100
+ See https://documentation.onfido.com/#document-types for example document types.
101
+
82
102
  #### Live Photos
83
103
 
84
- Live Photos, like documents, can provide supporting evidence for Onfido checks.
104
+ Live photos are images of the applicant’s face, typically taken at the same time as documents are provided. These photos are used to perform Facial Similarity Photo reports on the applicant.
85
105
 
86
106
  ```ruby
87
- api.live_photo.create('applicant_id', file: 'http://example.com')
88
- api.live_photo.find(applicant_id, live_photo_id) # => Finds a live photo
89
- api.live_photo.download(applicant_id, live_photo_id) # => Downloads a live photo as binary data
90
- api.live_photo.all(applicant_id) # => Returns all applicant's live photos
107
+ onfido.live_photo.create(applicant_id: '<APPLICANT_ID>', file: <FILE>) # => Creates a live photo
108
+ onfido.live_photo.find('<LIVE_PHOTO_ID>') # => Finds a live photo
109
+ onfido.live_photo.download('<LIVE_PHOTO_ID>') # => Downloads a live photo as binary data
110
+ onfido.live_photo.all('<APPLICANT_ID>') # => Returns all live photos belonging to an applicant
91
111
  ```
92
112
 
93
113
  **Note:** The file parameter must be a `File`-like object which responds to `#read` and `#path`.
@@ -97,48 +117,37 @@ to `#create`.
97
117
 
98
118
  #### Checks
99
119
 
100
- Checks are requests for Onfido to check an applicant, by commissioning one or
101
- more "reports" on them.
120
+ Checks are performed on an applicant. Depending on the type of check you wish to perform, different information will be required when you create an applicant. A check consists of one or more reports.
102
121
 
103
122
  ```ruby
104
- api.check.create('applicant_id', type: 'express', reports: [{ name: 'identity' }])
105
- api.check.find('applicant_id', 'check_id')
106
- api.check.resume('check_id')
107
- api.check.all('applicant_id')
123
+ onfido.check.create(applicant_id: '<APPLICANT_ID>', report_names: ['document', 'facial_similarity_photo']) # => Creates a check
124
+ onfido.check.find('<CHECK_ID>') # => Finds a check
125
+ onfido.check.resume('<CHECK_ID>') # => Resumes a paused check
126
+ onfido.check.all('<APPLICANT_ID>') # => Returns all an applicant's checks
108
127
  ```
109
128
 
110
129
  #### Reports
111
130
 
112
- Reports provide details of the results of some part of a "check". They are
131
+ Reports provide details of the results of some part of a check. They are
113
132
  created when a check is created, so the Onfido API only provides support for
114
133
  finding and listing them. For paused reports specifically, additional support for resuming and
115
134
  cancelling reports is also available.
116
135
 
117
136
  ```ruby
118
- api.report.find('check_id', 'report_id')
119
- api.report.all('check_id')
120
- api.report.resume('check_id', 'report_id')
121
- api.report.cancel('check_id', 'report_id')
122
- ```
123
-
124
- #### Report Type Groups
125
-
126
- Report type groups provide a convenient way to group and organize different types of reports.
127
- The Onfido API only provides support for finding and listing them.
128
-
129
- ```ruby
130
- api.report_type_group.find('report_type_group_id')
131
- api.report_type_group.all()
137
+ onfido.report.find('<REPORT_ID>') # => Finds a report
138
+ onfido.report.all('<CHECK_ID>') # => Returns all the reports in a check
139
+ onfido.report.resume('<REPORT_ID>') # => Resumes a paused report
140
+ onfido.report.cancel('<REPORT_ID>') # => Cancels a paused report
132
141
  ```
133
142
 
134
143
  #### Address Lookups
135
144
 
136
145
  Onfido provides an address lookup service, to help ensure well-formatted
137
- addresses are provided when creating "applicants". To search for addresses
146
+ addresses are provided when creating applicants. To search for addresses
138
147
  by postcode, use:
139
148
 
140
149
  ```ruby
141
- api.address.all('SE1 4NG')
150
+ onfido.address.all('SE1 4NG') # => Returns all addresses in a given postcode
142
151
  ```
143
152
 
144
153
  #### Webhook Endpoints
@@ -147,9 +156,9 @@ Onfido allows you to set up and view your webhook endpoints via the API, as well
147
156
  as through the dashboard.
148
157
 
149
158
  ```ruby
150
- api.webhook.create(params) # => Creates a webhook endpoint
151
- api.webhook.find('webhook_id') # => Finds a single webhook endpoint
152
- api.webhook.all # => Returns all webhook endpoints
159
+ onfido.webhook.create(url: "https://webhook.url", events: ['report.completed, check.completed']) # => Registers a webhook endpoint
160
+ onfido.webhook.find('<WEBHOOK_ID>') # => Finds a single webhook endpoint
161
+ onfido.webhook.all # => Returns all webhook endpoints
153
162
  ```
154
163
 
155
164
  #### SDK Tokens
@@ -158,26 +167,21 @@ Onfido allows you to generate JSON Web Tokens via the API in order to authentica
158
167
  with Onfido's [JavaScript SDK](https://github.com/onfido/onfido-sdk-ui).
159
168
 
160
169
  ```ruby
161
- api.sdk_token.create(applicant_id: 'applicant_id', referrer: 'referrer')
170
+ onfido.sdk_token.create(applicant_id: 'applicant_id', referrer: 'referrer') # => Creates a JWT
162
171
  ```
163
172
 
164
- ### Pagination
165
-
166
- All resources that support an `all` method also support pagination. By default,
167
- the first 20 records are fetched.
168
-
169
173
  ### Error Handling
170
174
 
171
- There are three classes of errors raised by the library, all of which subclass `Onfido::OnfidoError`:
175
+ There are 3 classes of errors raised by the library, all of which subclass `Onfido::OnfidoError`:
172
176
  - `Onfido::ServerError` is raised whenever Onfido returns a `5xx` response
173
177
  - `Onfido::RequestError` is raised whenever Onfido returns any other kind of error
174
178
  - `Onfido::ConnectionError` is raised whenever a network error occurs (e.g., a timeout)
175
179
 
176
- All three error classes provide the `response_code`, `response_body`, `json_body`, `type` and `fields` of the error (although for `Onfido::ServerError` and `Onfido::ConnectionError` the last three are likely to be `nil`).
180
+ All 3 error classes provide the `response_code`, `response_body`, `json_body`, `type` and `fields` of the error (although for `Onfido::ServerError` and `Onfido::ConnectionError` the last 3 are likely to be `nil`).
177
181
 
178
182
  ```ruby
179
183
  def create_applicant
180
- api.applicant.create(params)
184
+ onfido.applicant.create(params)
181
185
  rescue Onfido::RequestError => e
182
186
  e.type # => 'validation_error'
183
187
  e.fields # => { "email": { "messages": ["invalid format"] } }
@@ -187,13 +191,13 @@ end
187
191
 
188
192
  ## Webhooks
189
193
 
190
- Each webhook endpoint has a secret token, generated automatically and [exposed](https://onfido.com/documentation#register-webhook) in the API. When sending a request, Onfido includes a signature computed using the request body and this token in the `X-Signature` header.
194
+ Each webhook endpoint has a secret token, generated automatically and [exposed](https://onfido.com/documentation#register-webhook) in the API. When sending a request, Onfido includes a signature computed using the request body and this token in the `X-SHA2-Signature` header.
191
195
 
192
- This provided signature [should](https://onfido.com/documentation#webhook-security) be compared to one you generate yourself with the token to check that a webhook is a genuine request from Onfido.
196
+ You should compare this provided signature to one you generate yourself with the token to verify that a webhook is a genuine request from Onfido.
193
197
 
194
198
  ```ruby
195
199
  if Onfido::Webhook.valid?(request.raw_post,
196
- request.headers["X-Signature"],
200
+ request.headers["X-SHA2-Signature"],
197
201
  ENV['ONFIDO_WEBHOOK_TOKEN'])
198
202
  process_webhook
199
203
  else
@@ -201,15 +205,11 @@ else
201
205
  end
202
206
  ```
203
207
 
204
- ## Roadmap
205
-
206
- - Improve test coverage with more scenarios
207
- - Add custom errors based on the response code
208
- - Improve pagination handling (use information passed in link header)
208
+ Read more at https://onfido.com/documentation#webhook-security
209
209
 
210
210
  ## Contributing
211
211
 
212
- 1. Fork it ( https://github.com/hvssle/onfido/fork )
212
+ 1. Fork it ( https://github.com/onfido/onfido-ruby/fork )
213
213
  2. Create your feature branch (`git checkout -b my-new-feature`)
214
214
  3. Commit your changes (`git commit -am 'Add some feature'`)
215
215
  4. Push to the branch (`git push origin my-new-feature`)
@@ -16,10 +16,10 @@ require 'onfido/resources/address'
16
16
  require 'onfido/resources/applicant'
17
17
  require 'onfido/resources/check'
18
18
  require 'onfido/resources/document'
19
+ require 'onfido/resources/extraction'
19
20
  require 'onfido/resources/live_photo'
20
21
  require 'onfido/resources/live_video'
21
22
  require 'onfido/resources/report'
22
- require 'onfido/resources/report_type_group'
23
23
  require 'onfido/resources/sdk_token'
24
24
  require 'onfido/resources/webhook'
25
25
 
@@ -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
@@ -43,5 +39,9 @@ module Onfido
43
39
  def address
44
40
  Onfido::Address.new(@api_key)
45
41
  end
42
+
43
+ def extraction
44
+ Onfido::Extraction.new(@api_key)
45
+ end
46
46
  end
47
47
  end
@@ -1,6 +1,11 @@
1
1
  module Onfido
2
2
  module Configuration
3
- attr_accessor :api_key, :open_timeout, :read_timeout, :api_version
3
+ REGION_HOSTS = {
4
+ us: "api.us.onfido.com",
5
+ ca: "api.ca.onfido.com"
6
+ }.freeze
7
+
8
+ attr_accessor :api_key, :region, :open_timeout, :read_timeout
4
9
 
5
10
  def self.extended(base)
6
11
  base.reset
@@ -12,9 +17,9 @@ module Onfido
12
17
 
13
18
  def reset
14
19
  self.api_key = nil
20
+ self.region = nil
15
21
  self.open_timeout = 30
16
22
  self.read_timeout = 80
17
- self.api_version = 'v2'
18
23
  RestClient.log = nil
19
24
  end
20
25
 
@@ -30,22 +35,13 @@ module Onfido
30
35
  RestClient.log ||= NullLogger.new
31
36
  end
32
37
 
33
- def region
34
- return unless api_key
35
-
36
- first_bit = api_key.split("_")[0]
37
-
38
- return if %w(live test).include?(first_bit)
39
-
40
- first_bit
41
- end
42
-
43
38
  def endpoint
44
- if region
45
- "https://api.#{region}.onfido.com/#{api_version}/"
46
- else
47
- "https://api.onfido.com/#{api_version}/"
39
+ region_host = region ? REGION_HOSTS[region.downcase.to_sym] : "api.onfido.com"
40
+ unless region_host
41
+ raise "The region \"#{region.downcase}\" is not currently supported"
48
42
  end
43
+
44
+ "https://#{region_host}/v3/"
49
45
  end
50
46
  end
51
47
  end