companies-house-gateway 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/companies_house_gateway/errors/api_error.rb +12 -0
- data/lib/companies_house_gateway/errors/invalid_request_error.rb +1 -1
- data/lib/companies_house_gateway/middleware/check_response.rb +13 -12
- data/lib/companies_house_gateway/version.rb +1 -1
- data/spec/request_spec.rb +4 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1849937f401ec3fe9197d91cc25f8ace31043df1
|
4
|
+
data.tar.gz: bbcfd60440e011fa247b5ba9aa324e3de76569a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d0b5788b304f5a6e380678910bb3416d6c917f80e783a7a76fc1fd63808c3d93b7f8878114938032e1afb012c8675fc3cdc5eea1e6839d40f5a533208503951
|
7
|
+
data.tar.gz: b6e03f18aea13bd71d6e082d09e7c13c4e54b4854e448e416b0c1e1b06ce415653628fd6c6866827d53a0c08cad95bba41d46a50b6823ec64543c86008da6262
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,16 @@
|
|
1
1
|
module CompaniesHouseGateway
|
2
2
|
class APIError < CompaniesHouseGatewayError
|
3
|
+
attr_accessor :error_code
|
4
|
+
|
5
|
+
def initialize(message, error_code=nil, status=nil, response_body=nil)
|
6
|
+
super(message, status, response_body)
|
7
|
+
@error_code = error_code
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_s
|
11
|
+
str = super
|
12
|
+
str += " [Error code: #{error_code}]" if error_code
|
13
|
+
str
|
14
|
+
end
|
3
15
|
end
|
4
16
|
end
|
@@ -2,7 +2,7 @@ module CompaniesHouseGateway
|
|
2
2
|
class InvalidRequestError < CompaniesHouseGatewayError
|
3
3
|
attr_accessor :param
|
4
4
|
|
5
|
-
def initialize(message, param, status=nil, response_body=nil)
|
5
|
+
def initialize(message=nil, param=nil, status=nil, response_body=nil)
|
6
6
|
super(message, status, response_body)
|
7
7
|
@param = param
|
8
8
|
end
|
@@ -3,18 +3,7 @@ module CompaniesHouseGateway
|
|
3
3
|
class CheckResponse < Faraday::Middleware
|
4
4
|
def call(env)
|
5
5
|
@app.call(env).on_complete do |env|
|
6
|
-
|
7
|
-
|
8
|
-
unless response_body && response_body["GovTalkDetails"]
|
9
|
-
raise InvalidResponseError.new(nil, env[:status], env)
|
10
|
-
end
|
11
|
-
|
12
|
-
if errors = response_body["GovTalkDetails"]["GovTalkErrors"]
|
13
|
-
errors = errors.values.flatten
|
14
|
-
messages = errors.map { |e| "(#{e['Number']}) #{e['Text']}" }
|
15
|
-
raise APIError.new(messages.join(" | "), env[:status], env)
|
16
|
-
end
|
17
|
-
|
6
|
+
check_for_errors(env)
|
18
7
|
response_values(env)
|
19
8
|
end
|
20
9
|
end
|
@@ -22,6 +11,18 @@ module CompaniesHouseGateway
|
|
22
11
|
def response_values(env)
|
23
12
|
{ status: env[:status], headers: env[:headers], body: env[:body] }
|
24
13
|
end
|
14
|
+
|
15
|
+
def check_for_errors(env)
|
16
|
+
body = env[:body]["GovTalkMessage"]
|
17
|
+
unless body && body["GovTalkDetails"]
|
18
|
+
raise InvalidResponseError.new(env[:body], env[:status], env)
|
19
|
+
end
|
20
|
+
|
21
|
+
if body["GovTalkDetails"]["GovTalkErrors"]
|
22
|
+
error = body["GovTalkDetails"]["GovTalkErrors"].values.flatten.first
|
23
|
+
raise APIError.new(error['Text'], error['Number'], env[:status], env)
|
24
|
+
end
|
25
|
+
end
|
25
26
|
end
|
26
27
|
|
27
28
|
Faraday.register_middleware :response, check_ch_response: CheckResponse
|
data/spec/request_spec.rb
CHANGED
@@ -79,8 +79,10 @@ describe CompaniesHouseGateway::Request do
|
|
79
79
|
|
80
80
|
it "wraps the error" do
|
81
81
|
expect { perform_check }.
|
82
|
-
to raise_error
|
83
|
-
|
82
|
+
to raise_error CompaniesHouseGateway::APIError do |error|
|
83
|
+
error.error_code.should == "604"
|
84
|
+
error.message.should == "Error text"
|
85
|
+
end
|
84
86
|
end
|
85
87
|
end
|
86
88
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: companies-house-gateway
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Grey Baker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|