web_client 0.0.4 → 0.0.5
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/.travis.yml +6 -0
- data/README.md +2 -0
- data/lib/web_client/connection.rb +4 -3
- data/lib/web_client/error.rb +5 -1
- data/lib/web_client/request.rb +1 -1
- data/lib/web_client/version.rb +1 -1
- data/lib/web_client.rb +0 -1
- data/spec/connection_spec.rb +29 -2
- metadata +4 -4
- data/lib/web_client/extensions/string.rb +0 -15
- data/spec/string_spec.rb +0 -17
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -39,6 +39,7 @@ module WebClient
|
|
39
39
|
response
|
40
40
|
end
|
41
41
|
rescue Timeout::Error,
|
42
|
+
Errno::EHOSTUNREACH,
|
42
43
|
Errno::EINVAL,
|
43
44
|
Errno::ECONNRESET,
|
44
45
|
EOFError,
|
@@ -47,7 +48,7 @@ module WebClient
|
|
47
48
|
ProtocolError,
|
48
49
|
SocketError,
|
49
50
|
Errno::ECONNREFUSED => e
|
50
|
-
WebClient.logger.error "[WebClient] #{e.class}: #{e.message}"
|
51
|
+
WebClient.logger.error "[WebClient] #{e.class}: #{e.message}\nServer: #{host}:#{port}\nRequest: #{request.to_json}"
|
51
52
|
raise Error, e
|
52
53
|
end
|
53
54
|
end
|
@@ -61,8 +62,8 @@ module WebClient
|
|
61
62
|
end
|
62
63
|
|
63
64
|
Request::TYPES.each do |request_type|
|
64
|
-
define_method "#{request_type}!" do |url, options={}|
|
65
|
-
request! Request.new(options.merge(type: request_type, url: url))
|
65
|
+
define_method "#{request_type}!" do |url, options={}, &block|
|
66
|
+
request! Request.new(options.merge(type: request_type, url: url)), &block
|
66
67
|
end
|
67
68
|
|
68
69
|
define_method request_type do |url, options={}, &block|
|
data/lib/web_client/error.rb
CHANGED
data/lib/web_client/request.rb
CHANGED
@@ -18,7 +18,7 @@ module WebClient
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def to_http
|
21
|
-
klass = eval("Net::HTTP::#{type.to_s.
|
21
|
+
klass = eval("Net::HTTP::#{type.to_s.capitalize}")
|
22
22
|
request = klass.new url
|
23
23
|
request.set_form_data(body) if body.is_a? Hash
|
24
24
|
request.body = body if body.is_a? String
|
data/lib/web_client/version.rb
CHANGED
data/lib/web_client.rb
CHANGED
data/spec/connection_spec.rb
CHANGED
@@ -120,12 +120,12 @@ describe WebClient::Connection do
|
|
120
120
|
|
121
121
|
it 'Invalid host exception' do
|
122
122
|
stub_request(:get, /.*/).to_raise(SocketError.new('getaddrinfo: No such host is known.'))
|
123
|
-
|
123
|
+
expect { connection.get! '/' }.to raise_error WebClient::Error
|
124
124
|
end
|
125
125
|
|
126
126
|
it 'Timeout exception' do
|
127
127
|
stub_request(:get, /.*/).to_timeout
|
128
|
-
|
128
|
+
expect { connection.get! '/' }.to raise_error WebClient::Error
|
129
129
|
end
|
130
130
|
|
131
131
|
end
|
@@ -161,4 +161,31 @@ describe WebClient::Connection do
|
|
161
161
|
|
162
162
|
end
|
163
163
|
|
164
|
+
context 'Unsafe mode' do
|
165
|
+
|
166
|
+
it 'Success response' do
|
167
|
+
stub_request(:get, "#{HOST}/get_stub").to_return(body: '{"id":1,"name":"John"}')
|
168
|
+
json = connection.get!('/get_stub') do |response|
|
169
|
+
JSON.parse response.body
|
170
|
+
end
|
171
|
+
|
172
|
+
json.should eq 'id' => 1, 'name' => 'John'
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'Invalid response' do
|
176
|
+
stub_request(:get, "#{HOST}/get_stub").to_return(status: 404)
|
177
|
+
json = connection.get!('/get_stub') do |response|
|
178
|
+
JSON.parse response.body
|
179
|
+
end
|
180
|
+
|
181
|
+
json.should be_nil
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'Request error' do
|
185
|
+
stub_request(:get, "#{HOST}/get_stub").to_timeout
|
186
|
+
expect { connection.get!('/get_stub') { |r| JSON.parse r.body } }.to raise_error WebClient::Error
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
190
|
+
|
164
191
|
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.5
|
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:
|
12
|
+
date: 2013-04-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -51,13 +51,13 @@ extensions: []
|
|
51
51
|
extra_rdoc_files: []
|
52
52
|
files:
|
53
53
|
- .gitignore
|
54
|
+
- .travis.yml
|
54
55
|
- Gemfile
|
55
56
|
- README.md
|
56
57
|
- Rakefile
|
57
58
|
- lib/web_client.rb
|
58
59
|
- lib/web_client/connection.rb
|
59
60
|
- lib/web_client/error.rb
|
60
|
-
- lib/web_client/extensions/string.rb
|
61
61
|
- lib/web_client/request.rb
|
62
62
|
- lib/web_client/response.rb
|
63
63
|
- lib/web_client/version.rb
|
@@ -66,7 +66,6 @@ files:
|
|
66
66
|
- spec/request_spec.rb
|
67
67
|
- spec/response_spec.rb
|
68
68
|
- spec/spec_helper.rb
|
69
|
-
- spec/string_spec.rb
|
70
69
|
- web_client.gemspec
|
71
70
|
homepage: https://github.com/gabynaiman/web_client
|
72
71
|
licenses: []
|
@@ -93,3 +92,4 @@ signing_key:
|
|
93
92
|
specification_version: 3
|
94
93
|
summary: Net::HTTP wrapper easy to use
|
95
94
|
test_files: []
|
95
|
+
has_rdoc:
|
data/spec/string_spec.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe String do
|
4
|
-
|
5
|
-
it 'Titleize single word' do
|
6
|
-
'hello'.titleize.should eq 'Hello'
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'Titleize phrase' do
|
10
|
-
'hello world'.titleize.should eq 'Hello world'
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'Titleize titleized word' do
|
14
|
-
'Hello'.titleize.should eq 'Hello'
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|