web_client 0.0.5 → 0.0.6
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.
- data/lib/web_client/connection.rb +8 -10
- data/lib/web_client/error.rb +3 -0
- data/lib/web_client/version.rb +1 -1
- data/spec/connection_spec.rb +4 -8
- metadata +2 -2
@@ -28,16 +28,14 @@ module WebClient
|
|
28
28
|
WebClient.logger.debug "[WebClient] #{request.type.to_s.upcase} Url: http://#{host}#{(port != 80) ? ":#{port}" : ''}#{request.url} | Body: #{request.body} | Headers: #{request.headers}"
|
29
29
|
response = Response.new @http.request(request.to_http)
|
30
30
|
WebClient.logger.debug "[WebClient] RESPONSE Status: #{response.code} | Content: #{response.body}"
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
WebClient.logger.error "[WebClient] #{response.code} - Unexpected error\n#{response.body}"
|
36
|
-
nil
|
37
|
-
end
|
38
|
-
else
|
39
|
-
response
|
31
|
+
|
32
|
+
unless response.success?
|
33
|
+
WebClient.logger.error "[WebClient] #{response.code} - Unexpected error\n#{response.body}"
|
34
|
+
raise Error, response.body ? response.body.force_encoding('utf-8') : 'Unexpected error'
|
40
35
|
end
|
36
|
+
|
37
|
+
block_given? ? yield(response) : response
|
38
|
+
|
41
39
|
rescue Timeout::Error,
|
42
40
|
Errno::EHOSTUNREACH,
|
43
41
|
Errno::EINVAL,
|
@@ -49,7 +47,7 @@ module WebClient
|
|
49
47
|
SocketError,
|
50
48
|
Errno::ECONNREFUSED => e
|
51
49
|
WebClient.logger.error "[WebClient] #{e.class}: #{e.message}\nServer: #{host}:#{port}\nRequest: #{request.to_json}"
|
52
|
-
raise
|
50
|
+
raise ConnectionFail, e
|
53
51
|
end
|
54
52
|
end
|
55
53
|
|
data/lib/web_client/error.rb
CHANGED
data/lib/web_client/version.rb
CHANGED
data/spec/connection_spec.rb
CHANGED
@@ -172,18 +172,14 @@ describe WebClient::Connection do
|
|
172
172
|
json.should eq 'id' => 1, 'name' => 'John'
|
173
173
|
end
|
174
174
|
|
175
|
-
it '
|
175
|
+
it 'Client error' do
|
176
176
|
stub_request(:get, "#{HOST}/get_stub").to_return(status: 404)
|
177
|
-
|
178
|
-
JSON.parse response.body
|
179
|
-
end
|
180
|
-
|
181
|
-
json.should be_nil
|
177
|
+
expect { connection.get!('/get_stub') }.to raise_error WebClient::Error
|
182
178
|
end
|
183
179
|
|
184
|
-
it '
|
180
|
+
it 'Server error' do
|
185
181
|
stub_request(:get, "#{HOST}/get_stub").to_timeout
|
186
|
-
expect { connection.get!('/get_stub')
|
182
|
+
expect { connection.get!('/get_stub') }.to raise_error WebClient::ConnectionFail
|
187
183
|
end
|
188
184
|
|
189
185
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: web_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|