onfido 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7f348aa18fa199997614263dda1be6a615a48191
4
- data.tar.gz: 8e8d3b9cefb576187b9c49666492958f8793a533
3
+ metadata.gz: e3159a3e9bff94cd01155eabee9d77b7785c3eab
4
+ data.tar.gz: a67a5dd889545159c742a15fe12ac89630fb31a1
5
5
  SHA512:
6
- metadata.gz: 69bda930664b166633e1454a7a48828d59a90c66ac9fc38b66bcbd0e4bfa52628660114e192cfa9b056986418fa05d191977617dc37718c7b3eb2adb8e0f84ec
7
- data.tar.gz: 8623820a91b599ef02c7508e311275e8cd71163e2c72770811c77cb79e5aa1ae4a838cd3c900a9fcd31e6990bce58835f639d2b7a8e9f4d310b52a88d1d3d9cd
6
+ metadata.gz: 8577a2bc2a1f1b176f3a487f6ae16a8a9ea3dfeff4db962f63475e5c5a1942bb92c80f076d7e2a78f2551b36208a905e3e6406f094be7df8660f03f287f864fc
7
+ data.tar.gz: 6eccfff6eb4d0b663420680d60034afbf9346559c74eea5a7f0cd059c458f320e7bb639f45456103f666bf1fb64800a91b27891863168659667b6eb848f2c583
data/CHANGELOG.md CHANGED
@@ -1,4 +1,10 @@
1
- ## v0.1.0 11 November 2015
1
+ ## v0.2.0, 9 February 2015
2
+
3
+ - BREAKING: adds `Onfido::ServerError`, which is raised whenever Onfido responds
4
+ with a 5xx code. Previously `Onfido::RequestError` would have been raised, but
5
+ this is now reserved for non-5xx responses.
6
+
7
+ ## v0.1.0, 11 November 2015
2
8
 
3
9
  - BREAKING: remove `throws_exceptions` option. We now always throw exceptions
4
10
  for errors. This option had become confusing since `Onfido::ConnectionError`
@@ -6,6 +12,6 @@
6
12
  - Add base errors class (`Onfido::OnfidoError`)
7
13
  - Add rubocop, and fix style inconsistencies
8
14
 
9
- ## v0.0.4 10 November 2015
15
+ ## v0.0.4, 10 November 2015
10
16
 
11
17
  - Split out connection errors so they can be automatically retried
data/README.md CHANGED
@@ -144,7 +144,12 @@ api.check.all('applicant_id', page: 2, per_page: 10)
144
144
 
145
145
  ## Error Handling
146
146
 
147
- If you rescue `Onfido::RequestError`, you are provided with the response code, response body and parsed JSON body, the type of error the the fields that have errored.
147
+ There are three classes of errors raised by the library, all of which subclass `Onfido::Error`.
148
+ - `Onfido::ServerError` is raised whenever Onfido returns a `5xx` response
149
+ - `Onfido::RequestError` is raised whenever Onfido returns any other kind of error
150
+ - `Onfido::ConnectionError` is raised whenever a network error occurs (e.g., a timeout)
151
+
152
+ 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`).
148
153
 
149
154
  ```ruby
150
155
  def create_applicant
@@ -156,8 +161,6 @@ If you rescue `Onfido::RequestError`, you are provided with the response code, r
156
161
  end
157
162
  ```
158
163
 
159
- You can also rescue `Onfido::ConnectionError`, which is raised when something goes wrong with the connection to Onfido. This is useful for adding automatic retries to your background jobs.
160
-
161
164
  ### Roadmap
162
165
 
163
166
  - Improve test coverage with more scenarios
data/lib/onfido.rb CHANGED
@@ -7,6 +7,7 @@ require 'onfido/version'
7
7
  require 'onfido/configuration'
8
8
  require 'onfido/errors/onfido_error'
9
9
  require 'onfido/errors/request_error'
10
+ require 'onfido/errors/server_error'
10
11
  require 'onfido/errors/connection_error'
11
12
  require 'onfido/null_logger'
12
13
  require 'onfido/resource'
@@ -0,0 +1,4 @@
1
+ module Onfido
2
+ class ServerError < OnfidoError
3
+ end
4
+ end
@@ -1,6 +1,6 @@
1
1
  module Onfido
2
2
  class Resource
3
- VALID_HTTP_METHODS = %i(get post)
3
+ VALID_HTTP_METHODS = %i(get post).freeze
4
4
 
5
5
  def url_for(path)
6
6
  Onfido.endpoint + path
@@ -77,7 +77,9 @@ module Onfido
77
77
  general_api_error(response.code, response.body)
78
78
  end
79
79
 
80
- raise RequestError.new(
80
+ error_class = response.code.to_i >= 500 ? ServerError : RequestError
81
+
82
+ raise error_class.new(
81
83
  parsed_response["error"]['message'],
82
84
  response_code: response.code,
83
85
  response_body: response.body
@@ -85,7 +87,9 @@ module Onfido
85
87
  end
86
88
 
87
89
  def general_api_error(response_code, response_body)
88
- raise RequestError.new(
90
+ error_class = response_code.to_i >= 500 ? ServerError : RequestError
91
+
92
+ raise error_class.new(
89
93
  "Invalid response object from API: #{response_body} " \
90
94
  "(HTTP response code was #{response_code})",
91
95
  response_code: response_code,
@@ -1,3 +1,3 @@
1
1
  module Onfido
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'.freeze
3
3
  end
data/onfido.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency 'bundler', '~> 1.7'
22
22
  spec.add_development_dependency 'rake', '~> 10.0'
23
23
  spec.add_development_dependency 'webmock', '~> 1.22'
24
- spec.add_development_dependency 'rubocop', '~> 0.35.1'
24
+ spec.add_development_dependency 'rubocop', '~> 0.37.0'
25
25
  spec.add_development_dependency 'rspec', '~> 3.1'
26
26
  spec.add_development_dependency 'rspec-its', '~> 1.2'
27
27
  spec.add_development_dependency 'sinatra', '~> 1.4'
@@ -24,12 +24,12 @@ describe Onfido::Resource do
24
24
  end
25
25
  end
26
26
 
27
- context 'unparseable JSON' do
27
+ context 'unparseable JSON 5xx' do
28
28
  let(:path) { 'unparseable_response' }
29
29
 
30
- it 'raises a custom error' do
30
+ it 'raises a server error' do
31
31
  expect { resource.get(url: url, payload: payload) }.
32
- to raise_error(Onfido::RequestError, /response code was 504/)
32
+ to raise_error(Onfido::ServerError, /response code was 504/)
33
33
  end
34
34
  end
35
35
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onfido
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pericles Theodorou
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-11-11 00:00:00.000000000 Z
12
+ date: 2016-02-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -59,14 +59,14 @@ dependencies:
59
59
  requirements:
60
60
  - - ~>
61
61
  - !ruby/object:Gem::Version
62
- version: 0.35.1
62
+ version: 0.37.0
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - ~>
68
68
  - !ruby/object:Gem::Version
69
- version: 0.35.1
69
+ version: 0.37.0
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: rspec
72
72
  requirement: !ruby/object:Gem::Requirement
@@ -150,6 +150,7 @@ files:
150
150
  - lib/onfido/errors/connection_error.rb
151
151
  - lib/onfido/errors/onfido_error.rb
152
152
  - lib/onfido/errors/request_error.rb
153
+ - lib/onfido/errors/server_error.rb
153
154
  - lib/onfido/null_logger.rb
154
155
  - lib/onfido/report.rb
155
156
  - lib/onfido/resource.rb