passfort 0.2.0 → 0.2.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/lib/passfort/errors.rb +1 -0
- data/lib/passfort/errors/api_error.rb +3 -2
- data/lib/passfort/errors/chargeable_limit_reached_error.rb +2 -2
- data/lib/passfort/errors/invalid_api_key_error.rb +2 -2
- data/lib/passfort/errors/invalid_input_data_error.rb +2 -2
- data/lib/passfort/errors/request_error.rb +2 -2
- data/lib/passfort/errors/unknown_api_error.rb +12 -0
- data/lib/passfort/http.rb +10 -13
- data/lib/passfort/version.rb +1 -1
- data/spec/passfort/http_spec.rb +6 -16
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aad8b4d28916b07b98a185e5770cdde81ca59353d71284171eb8d4a5fa4c240b
|
4
|
+
data.tar.gz: ef28d85a96a8c5393deb1b8d4a0ba4ed477897239d43a0d5a73294648ffcea88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf10cfef404e40a8f935fa4e8b68f2f0a1a27517f5a5f4bda1f82ee98e9df192792089a01cd8f02a6a85f51a35088e0745081945c989d0ff887dfb40fc9c91e9
|
7
|
+
data.tar.gz: e31d726cf74c4d37b7f9626cf7c647e791ceac7dccfb5d00c49a62cd741249744aea26d7b768f8e740e830eeb303ac2471e771affbefaf7dd47c4f27811ad3e5
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/lib/passfort/errors.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "passfort/errors/api_error"
|
4
|
+
require "passfort/errors/unknown_api_error"
|
4
5
|
require "passfort/errors/chargeable_limit_reached_error"
|
5
6
|
require "passfort/errors/invalid_api_key_error"
|
6
7
|
require "passfort/errors/invalid_input_data_error"
|
@@ -4,11 +4,12 @@ module Passfort
|
|
4
4
|
module Errors
|
5
5
|
# Represents any response from the API which is not a 200 OK
|
6
6
|
class APIError < StandardError
|
7
|
-
attr_reader :response
|
7
|
+
attr_reader :response, :errors
|
8
8
|
|
9
|
-
def initialize(msg, response = nil)
|
9
|
+
def initialize(msg, errors = [], response = nil)
|
10
10
|
super(msg)
|
11
11
|
@response = response
|
12
|
+
@errors = errors
|
12
13
|
end
|
13
14
|
end
|
14
15
|
end
|
@@ -4,8 +4,8 @@ module Passfort
|
|
4
4
|
module Errors
|
5
5
|
# Specific error class for when the chargeable limit has been reached
|
6
6
|
class ChargeableLimitReachedError < APIError
|
7
|
-
def initialize(
|
8
|
-
super("Rate limit exceeded",
|
7
|
+
def initialize(*args)
|
8
|
+
super("Rate limit exceeded", *args)
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
@@ -4,8 +4,8 @@ module Passfort
|
|
4
4
|
module Errors
|
5
5
|
# Specific error class for when an invalid API key is used to access the service
|
6
6
|
class InvalidAPIKeyError < APIError
|
7
|
-
def initialize(
|
8
|
-
super("Invalid API key",
|
7
|
+
def initialize(*args)
|
8
|
+
super("Invalid API key", *args)
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
@@ -4,8 +4,8 @@ module Passfort
|
|
4
4
|
module Errors
|
5
5
|
# Specific error class for when an invalid input data is used to query the service
|
6
6
|
class InvalidInputDataError < APIError
|
7
|
-
def initialize(
|
8
|
-
super("Invalid input data",
|
7
|
+
def initialize(*args)
|
8
|
+
super("Invalid input data", *args)
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
@@ -4,8 +4,8 @@ module Passfort
|
|
4
4
|
module Errors
|
5
5
|
# Specific error class for when an HTTP request error has occurred
|
6
6
|
class RequestError < APIError
|
7
|
-
def initialize(response)
|
8
|
-
super("Request API error - HTTP #{response.status}", response)
|
7
|
+
def initialize(errors, response)
|
8
|
+
super("Request API error - HTTP #{response.status}", errors, response)
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
data/lib/passfort/http.rb
CHANGED
@@ -36,25 +36,22 @@ module Passfort
|
|
36
36
|
# error codes: https://passfort.com/developer/v4/data-reference/ErrorCodes
|
37
37
|
def handle_error(response, body)
|
38
38
|
unless [200, 201].include?(response.status)
|
39
|
-
raise Passfort::Errors::RequestError, response
|
39
|
+
raise Passfort::Errors::RequestError.new([], response)
|
40
40
|
end
|
41
41
|
|
42
42
|
errors = body["errors"].is_a?(Array) ? body["errors"] : [body["errors"]]
|
43
43
|
|
44
|
-
handle_response_error(errors
|
44
|
+
handle_response_error(errors, response) if errors.any?
|
45
45
|
end
|
46
46
|
|
47
|
-
def handle_response_error(
|
48
|
-
case
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
else
|
56
|
-
raise Passfort::Errors::APIError.new("Unknown API error", response)
|
57
|
-
end
|
47
|
+
def handle_response_error(errors, response)
|
48
|
+
error_class = case errors[0]["code"]
|
49
|
+
when 201 then Passfort::Errors::InvalidInputDataError
|
50
|
+
when 204 then Passfort::Errors::InvalidAPIKeyError
|
51
|
+
when 104 then Passfort::Errors::ChargeableLimitReachedError
|
52
|
+
else Passfort::Errors::UnknownApiError
|
53
|
+
end
|
54
|
+
raise error_class.new(errors, response)
|
58
55
|
end
|
59
56
|
end
|
60
57
|
end
|
data/lib/passfort/version.rb
CHANGED
data/spec/passfort/http_spec.rb
CHANGED
@@ -18,45 +18,35 @@ RSpec.describe Passfort::Http do
|
|
18
18
|
let(:status) { 404 }
|
19
19
|
let(:error_class) { Passfort::Errors::RequestError }
|
20
20
|
|
21
|
-
it
|
22
|
-
is_expected.to raise_error(instance_of(error_class))
|
23
|
-
end
|
21
|
+
it { is_expected.to raise_error(error_class) }
|
24
22
|
end
|
25
23
|
|
26
24
|
context "when returning an invalid API Key error" do
|
27
25
|
let(:error_code) { 204 }
|
28
26
|
let(:error_class) { Passfort::Errors::InvalidAPIKeyError }
|
29
27
|
|
30
|
-
it
|
31
|
-
is_expected.to raise_error(instance_of(error_class))
|
32
|
-
end
|
28
|
+
it { is_expected.to raise_error(error_class) }
|
33
29
|
end
|
34
30
|
|
35
31
|
context "when returning an invalid input data error" do
|
36
32
|
let(:error_code) { 201 }
|
37
33
|
let(:error_class) { Passfort::Errors::InvalidInputDataError }
|
38
34
|
|
39
|
-
it
|
40
|
-
is_expected.to raise_error(instance_of(error_class))
|
41
|
-
end
|
35
|
+
it { is_expected.to raise_error(error_class) }
|
42
36
|
end
|
43
37
|
|
44
38
|
context "when returning a chargeable limit reached error" do
|
45
39
|
let(:error_code) { 104 }
|
46
40
|
let(:error_class) { Passfort::Errors::ChargeableLimitReachedError }
|
47
41
|
|
48
|
-
it
|
49
|
-
is_expected.to raise_error(instance_of(error_class))
|
50
|
-
end
|
42
|
+
it { is_expected.to raise_error(error_class) }
|
51
43
|
end
|
52
44
|
|
53
45
|
context "when returning an unknown API error" do
|
54
46
|
let(:error_code) { 203 }
|
55
|
-
let(:error_class) { Passfort::Errors::
|
47
|
+
let(:error_class) { Passfort::Errors::UnknownApiError }
|
56
48
|
|
57
|
-
it
|
58
|
-
is_expected.to raise_error(instance_of(error_class))
|
59
|
-
end
|
49
|
+
it { is_expected.to raise_error(error_class) }
|
60
50
|
end
|
61
51
|
|
62
52
|
context "when returning a successful result" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: passfort
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GoCardless
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -135,6 +135,7 @@ files:
|
|
135
135
|
- lib/passfort/errors/invalid_api_key_error.rb
|
136
136
|
- lib/passfort/errors/invalid_input_data_error.rb
|
137
137
|
- lib/passfort/errors/request_error.rb
|
138
|
+
- lib/passfort/errors/unknown_api_error.rb
|
138
139
|
- lib/passfort/http.rb
|
139
140
|
- lib/passfort/resource.rb
|
140
141
|
- lib/passfort/resource/base.rb
|