alephant-publisher-request 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/alephant/publisher/request.rb +2 -0
- data/lib/alephant/publisher/request/data_mapper.rb +4 -2
- data/lib/alephant/publisher/request/error.rb +9 -0
- data/lib/alephant/publisher/request/version.rb +1 -1
- data/spec/data_mapper_spec.rb +13 -1
- data/spec/integration/rack_server_spec.rb +13 -1
- 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: 212638793ae63c57e1e7884d4b9734a366e2a87c
|
4
|
+
data.tar.gz: d1150ed44ef1be7842248ebb986c29eca9e85e35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14e04aac1d08505fdfceb01d1752eb3f19d390400a0770d6ffa77c80fa414708988554afecafe90f9a70cd0aeb8291da100c9c44bb7b394f4ede71b4daa342f8
|
7
|
+
data.tar.gz: 15796375af93d17e6922f02e602819e787ea16d1ae655eab6782eb34dfc9ed6981575d11d8a89557d8ab2db192e9537b7ce2c6fd2ad6501f4a2ce8ecd47e55d8
|
@@ -23,8 +23,8 @@ module Alephant
|
|
23
23
|
def get(uri)
|
24
24
|
before = Time.new
|
25
25
|
response = connection.get(uri)
|
26
|
-
raise InvalidApiResponse, "Status: #{response.status}" unless response.status == 200
|
27
26
|
logger.metric(:name => "PublisherRequestDataMapperRequestHTTPTime", :unit => 'Seconds', :value => Time.new - before)
|
27
|
+
raise InvalidApiStatus, response.status unless response.status == 200
|
28
28
|
JSON::parse(response.body, :symbolize_names => true)
|
29
29
|
rescue Faraday::ConnectionFailed
|
30
30
|
logger.metric(:name => "PublisherRequestDataMapperConnectionFailed", :unit => "Count", :value => 1)
|
@@ -32,11 +32,13 @@ module Alephant
|
|
32
32
|
rescue JSON::ParserError
|
33
33
|
logger.metric(:name => "PublisherRequestDataMapperInvalidApiResponse", :unit => "Count", :value => 1)
|
34
34
|
raise InvalidApiResponse, "JSON parsing error: #{response.body}"
|
35
|
+
rescue InvalidApiStatus => e
|
36
|
+
logger.metric(:name => "PublisherRequestDataMapperInvalidStatus#{e.status}", :unit => "Count", :value => 1)
|
37
|
+
raise e
|
35
38
|
rescue StandardError => e
|
36
39
|
logger.metric(:name => "PublisherRequestDataMapperApiError", :unit => "Count", :value => 1)
|
37
40
|
raise ApiError, e.message
|
38
41
|
end
|
39
|
-
|
40
42
|
end
|
41
43
|
end
|
42
44
|
end
|
@@ -9,6 +9,15 @@ module Alephant
|
|
9
9
|
class InvalidComponentBasePath < InvalidComponent; end
|
10
10
|
class InvalidComponentName < InvalidComponent; end
|
11
11
|
class InvalidComponentClassName < InvalidComponent; end
|
12
|
+
class InvalidApiStatus < ApiError
|
13
|
+
attr_accessor :status
|
14
|
+
|
15
|
+
def initialize(status)
|
16
|
+
@status = status
|
17
|
+
super("Status: #{status}")
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
12
21
|
end
|
13
22
|
end
|
14
23
|
end
|
data/spec/data_mapper_spec.rb
CHANGED
@@ -35,7 +35,19 @@ describe FooMapper do
|
|
35
35
|
allow(connection).to receive(:get).and_raise(faraday_exception)
|
36
36
|
end
|
37
37
|
|
38
|
-
specify { expect{ subject.data }.to raise_error expected_exception }
|
38
|
+
specify { expect { subject.data }.to raise_error expected_exception }
|
39
39
|
end
|
40
|
+
|
41
|
+
context "invalid status code" do
|
42
|
+
let (:status_code) { 503 }
|
43
|
+
let (:expected_exception) { Alephant::Publisher::Request::InvalidApiStatus }
|
44
|
+
before(:each) do
|
45
|
+
allow(connection).to receive(:get).and_return(OpenStruct.new(:status => status_code))
|
46
|
+
end
|
47
|
+
|
48
|
+
specify { expect { subject.data }.to raise_error expected_exception }
|
49
|
+
end
|
50
|
+
|
51
|
+
|
40
52
|
end
|
41
53
|
end
|
@@ -47,14 +47,26 @@ describe Alephant::Publisher::Request do
|
|
47
47
|
specify { expect(last_response.status).to eq 404 }
|
48
48
|
end
|
49
49
|
|
50
|
+
context "with an invalid status code" do
|
51
|
+
let (:status_code) { 503 }
|
52
|
+
let (:expected_exception) { Alephant::Publisher::Request::InvalidApiStatus.new(status_code) }
|
53
|
+
before(:each) do
|
54
|
+
allow(connection).to receive(:get).and_raise expected_exception
|
55
|
+
get "/component/#{component_id}"
|
56
|
+
end
|
57
|
+
|
58
|
+
specify { expect(last_response.status).to eq status_code }
|
59
|
+
end
|
60
|
+
|
50
61
|
context "with an invalid API endpoint" do
|
62
|
+
let (:status_code) { 502 }
|
51
63
|
let (:expected_exception) { Alephant::Publisher::Request::InvalidApiResponse }
|
52
64
|
before(:each) do
|
53
65
|
allow(connection).to receive(:get).and_raise expected_exception
|
54
66
|
get "/component/#{component_id}"
|
55
67
|
end
|
56
68
|
|
57
|
-
specify { expect(last_response.status).to eq
|
69
|
+
specify { expect(last_response.status).to eq status_code }
|
58
70
|
end
|
59
71
|
|
60
72
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alephant-publisher-request
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Integralist
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|