giant_client 0.1.0
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/LICENSE +22 -0
- data/README.md +264 -0
- data/lib/giant_client.rb +105 -0
- data/lib/giant_client/abstract_adapter.rb +71 -0
- data/lib/giant_client/curb_adapter.rb +56 -0
- data/lib/giant_client/error.rb +8 -0
- data/lib/giant_client/excon_adapter.rb +42 -0
- data/lib/giant_client/mock_adapter.rb +57 -0
- data/lib/giant_client/mock_request.rb +11 -0
- data/lib/giant_client/net_http_adapter.rb +55 -0
- data/lib/giant_client/patron_adapter.rb +38 -0
- data/lib/giant_client/response.rb +12 -0
- data/lib/giant_client/typhoeus_adapter.rb +40 -0
- data/lib/giant_client/version.rb +3 -0
- data/spec/examples/giant_client_spec.rb +299 -0
- data/spec/examples/mock_adapter_spec.rb +276 -0
- data/spec/examples/spec_helper.rb +7 -0
- metadata +178 -0
@@ -0,0 +1,276 @@
|
|
1
|
+
require File.expand_path( '../spec_helper', __FILE__ )
|
2
|
+
|
3
|
+
describe 'Mock Adapter' do
|
4
|
+
let(:client){ GiantClient.new :host => 'example.com', :adapter => :mock }
|
5
|
+
|
6
|
+
context 'super simple request' do
|
7
|
+
before do
|
8
|
+
client.get('/')
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should record the url' do
|
12
|
+
client.last_request.url.should == 'http://example.com/'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
context 'request with all options set' do
|
16
|
+
before do
|
17
|
+
opts = {
|
18
|
+
:ssl => true,
|
19
|
+
:port => 9292,
|
20
|
+
:path => '/hey/there',
|
21
|
+
:query => { 'howya' => 'doing' },
|
22
|
+
:headers => { 'Content-Type' => 'application/awesome' },
|
23
|
+
:body => 'test body',
|
24
|
+
:timeout => 27
|
25
|
+
}
|
26
|
+
client.get(opts)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should record the (correct) url' do
|
30
|
+
url = 'https://example.com:9292/hey/there?howya=doing'
|
31
|
+
client.last_request.url.should == url
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should record the (correct) ssl' do
|
35
|
+
client.last_request.ssl.should == true
|
36
|
+
end
|
37
|
+
it 'should record the (correct) port' do
|
38
|
+
client.last_request.port.should == 9292
|
39
|
+
end
|
40
|
+
it 'should record the (correct) path' do
|
41
|
+
client.last_request.path.should == '/hey/there'
|
42
|
+
end
|
43
|
+
it 'should record the (correct) query' do
|
44
|
+
client.last_request.query.should == { 'howya' => 'doing' }
|
45
|
+
end
|
46
|
+
it 'should record the (correct) query_string' do
|
47
|
+
client.last_request.querystring.should == 'howya=doing'
|
48
|
+
end
|
49
|
+
it 'should record the (correct) headers' do
|
50
|
+
client.last_request.headers.should ==
|
51
|
+
{ 'Content-Type' => 'application/awesome' }
|
52
|
+
end
|
53
|
+
it 'should record the (correct) body' do
|
54
|
+
client.last_request.body.should == 'test body'
|
55
|
+
end
|
56
|
+
it 'should record the (correct) timeout' do
|
57
|
+
client.last_request.timeout.should == 27
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'multiple requests' do
|
62
|
+
before do
|
63
|
+
opts1 = {
|
64
|
+
:ssl => false,
|
65
|
+
:port => 4000,
|
66
|
+
:path => '/me/first/please.jsp',
|
67
|
+
:query => { 'say' => 'what', 'who' => 'me' },
|
68
|
+
:headers => { 'Content-Length' => 'infinity' },
|
69
|
+
:body => 'I\'m a request',
|
70
|
+
:timeout => 102
|
71
|
+
}
|
72
|
+
opts2 = {
|
73
|
+
:ssl => true,
|
74
|
+
:port => 9292,
|
75
|
+
:path => '/hey/there',
|
76
|
+
:query => { 'howya' => 'doing' },
|
77
|
+
:headers => { 'Content-Type' => 'application/awesome' },
|
78
|
+
:body => 'test body',
|
79
|
+
:timeout => 27
|
80
|
+
}
|
81
|
+
client.get(opts1)
|
82
|
+
client.get(opts2)
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'general' do
|
86
|
+
it 'should have stored two requests' do
|
87
|
+
client.requests.length.should == 2
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context 'last request' do
|
92
|
+
it 'should record the (correct) last url' do
|
93
|
+
url = 'https://example.com:9292/hey/there?howya=doing'
|
94
|
+
client.last_request.url.should == url
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'should record the (correct) last ssl' do
|
98
|
+
client.last_request.ssl.should == true
|
99
|
+
end
|
100
|
+
it 'should record the (correct) last port' do
|
101
|
+
client.last_request.port.should == 9292
|
102
|
+
end
|
103
|
+
it 'should record the (correct) last path' do
|
104
|
+
client.last_request.path.should == '/hey/there'
|
105
|
+
end
|
106
|
+
it 'should record the (correct) last query' do
|
107
|
+
client.last_request.query.should == { 'howya' => 'doing' }
|
108
|
+
end
|
109
|
+
it 'should record the (correct) last query_string' do
|
110
|
+
client.last_request.querystring.should == 'howya=doing'
|
111
|
+
end
|
112
|
+
it 'should record the (correct) last headers' do
|
113
|
+
client.last_request.headers.should ==
|
114
|
+
{ 'Content-Type' => 'application/awesome' }
|
115
|
+
end
|
116
|
+
it 'should record the (correct) last body' do
|
117
|
+
client.last_request.body.should == 'test body'
|
118
|
+
end
|
119
|
+
it 'should record the (correct) last timeout' do
|
120
|
+
client.last_request.timeout.should == 27
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
context 'second to last request' do
|
125
|
+
it 'should record the (correct) second to last url' do
|
126
|
+
url = 'http://example.com:4000/me/first/please.jsp?say=what&who=me'
|
127
|
+
client.requests[1].url.should == url
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'should record the (correct) second to last ssl' do
|
131
|
+
client.requests[1].ssl.should == false
|
132
|
+
end
|
133
|
+
it 'should record the (correct) second to last port' do
|
134
|
+
client.requests[1].port.should == 4000
|
135
|
+
end
|
136
|
+
it 'should record the (correct) second to last path' do
|
137
|
+
client.requests[1].path.should == '/me/first/please.jsp'
|
138
|
+
end
|
139
|
+
it 'should record the (correct) second to last query' do
|
140
|
+
client.requests[1].query.should == { 'say' => 'what', 'who' => 'me' }
|
141
|
+
end
|
142
|
+
it 'should record the (correct) second to last query_string' do
|
143
|
+
client.requests[1].querystring.should == 'say=what&who=me'
|
144
|
+
end
|
145
|
+
it 'should record the (correct) second to last headers' do
|
146
|
+
client.requests[1].headers.should ==
|
147
|
+
{ 'Content-Length' => 'infinity' }
|
148
|
+
end
|
149
|
+
it 'should record the (correct) second to last body' do
|
150
|
+
client.requests[1].body.should == 'I\'m a request'
|
151
|
+
end
|
152
|
+
it 'should record the (correct) second to last timeout' do
|
153
|
+
client.requests[1].timeout.should == 102
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
context 'setting responses' do
|
159
|
+
it 'should give the default response' do
|
160
|
+
client.get('/')
|
161
|
+
client.last_response.should == { :status_code => 200,
|
162
|
+
:headers => {},
|
163
|
+
:body => nil
|
164
|
+
}
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'should give the specified status' do
|
168
|
+
client.get('/').respond_with(:status_code => 404)
|
169
|
+
client.last_response.should == { :status_code => 404,
|
170
|
+
:headers => {},
|
171
|
+
:body => nil
|
172
|
+
}
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'should give the specified header' do
|
176
|
+
client.get('/').respond_with(:headers =>
|
177
|
+
{'Content-Type' => 'application/octet-stream'})
|
178
|
+
client.last_response.should == {
|
179
|
+
:status_code => 200,
|
180
|
+
:headers =>
|
181
|
+
{'Content-Type' => 'application/octet-stream'},
|
182
|
+
:body => nil
|
183
|
+
}
|
184
|
+
end
|
185
|
+
|
186
|
+
it 'should give multiple headers' do
|
187
|
+
client.get('/').respond_with(:headers =>
|
188
|
+
{'Content-Type' => 'application/octet-stream',
|
189
|
+
'Accepts' => '*/*',
|
190
|
+
'X-Powered-By' => 'The Internet'})
|
191
|
+
client.last_response.should == {
|
192
|
+
:status_code => 200,
|
193
|
+
:headers =>
|
194
|
+
{'Content-Type' => 'application/octet-stream',
|
195
|
+
'Accepts' => '*/*',
|
196
|
+
'X-Powered-By' => 'The Internet'},
|
197
|
+
:body => nil
|
198
|
+
}
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'should give multiple headers and status' do
|
202
|
+
client.get('/').respond_with(:headers =>
|
203
|
+
{'Content-Type' => 'application/octet-stream',
|
204
|
+
'Accepts' => '*/*',
|
205
|
+
'X-Powered-By' => 'The Internet'},
|
206
|
+
:status_code => 123)
|
207
|
+
client.last_response.should == {
|
208
|
+
:status_code => 123,
|
209
|
+
:headers =>
|
210
|
+
{'Content-Type' => 'application/octet-stream',
|
211
|
+
'Accepts' => '*/*',
|
212
|
+
'X-Powered-By' => 'The Internet'},
|
213
|
+
:body => nil
|
214
|
+
}
|
215
|
+
end
|
216
|
+
|
217
|
+
it 'should give the body' do
|
218
|
+
client.get('/').respond_with(:body => 'hey')
|
219
|
+
client.last_response.should == {
|
220
|
+
:status_code => 200,
|
221
|
+
:headers => {},
|
222
|
+
:body => 'hey'
|
223
|
+
}
|
224
|
+
end
|
225
|
+
|
226
|
+
it 'should give all three' do
|
227
|
+
client.get('/').respond_with(:headers =>
|
228
|
+
{'Content-Type' => 'application/octet-stream',
|
229
|
+
'Accepts' => '*/*',
|
230
|
+
'X-Powered-By' => 'The Internet'},
|
231
|
+
:status_code => 123,
|
232
|
+
:body => 'hey there')
|
233
|
+
client.last_response.should == {
|
234
|
+
:status_code => 123,
|
235
|
+
:headers =>
|
236
|
+
{'Content-Type' => 'application/octet-stream',
|
237
|
+
'Accepts' => '*/*',
|
238
|
+
'X-Powered-By' => 'The Internet'},
|
239
|
+
:body => 'hey there'
|
240
|
+
}
|
241
|
+
end
|
242
|
+
|
243
|
+
it 'should allow arbitrary fields' do
|
244
|
+
client.get('/').respond_with(:foo => 'bar')
|
245
|
+
client.last_response.should == {
|
246
|
+
:status_code => 200,
|
247
|
+
:headers => {},
|
248
|
+
:body => nil,
|
249
|
+
:foo => 'bar'
|
250
|
+
}
|
251
|
+
end
|
252
|
+
|
253
|
+
it 'should work with multiple responses' do
|
254
|
+
client.get('/').respond_with(:body => 'me first')
|
255
|
+
client.get('/').respond_with(:body => 'after you')
|
256
|
+
client.last_response.should == {
|
257
|
+
:status_code => 200,
|
258
|
+
:headers => {},
|
259
|
+
:body => 'after you',
|
260
|
+
}
|
261
|
+
|
262
|
+
client.responses[1].should == {
|
263
|
+
:status_code => 200,
|
264
|
+
:headers => {},
|
265
|
+
:body => 'me first',
|
266
|
+
}
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
|
276
|
+
|
metadata
ADDED
@@ -0,0 +1,178 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: giant_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Zack Reneau-Wedeen
|
9
|
+
- Mat Brown
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2012-10-13 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: curb
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '0'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: patron
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
type: :development
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: typhoeus
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: excon
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: rspec
|
81
|
+
requirement: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
type: :development
|
88
|
+
prerelease: false
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: webmock
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
type: :development
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: debugger
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ! '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ! '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
description: ! 'GiantClient is a lightweight adapter agnostic wrapper for major HTTP
|
128
|
+
client libraries.
|
129
|
+
|
130
|
+
'
|
131
|
+
email: z.reneau.wedeen@gmail.com
|
132
|
+
executables: []
|
133
|
+
extensions: []
|
134
|
+
extra_rdoc_files: []
|
135
|
+
files:
|
136
|
+
- lib/giant_client/abstract_adapter.rb
|
137
|
+
- lib/giant_client/curb_adapter.rb
|
138
|
+
- lib/giant_client/error.rb
|
139
|
+
- lib/giant_client/excon_adapter.rb
|
140
|
+
- lib/giant_client/mock_adapter.rb
|
141
|
+
- lib/giant_client/mock_request.rb
|
142
|
+
- lib/giant_client/net_http_adapter.rb
|
143
|
+
- lib/giant_client/patron_adapter.rb
|
144
|
+
- lib/giant_client/response.rb
|
145
|
+
- lib/giant_client/typhoeus_adapter.rb
|
146
|
+
- lib/giant_client/version.rb
|
147
|
+
- lib/giant_client.rb
|
148
|
+
- spec/examples/giant_client_spec.rb
|
149
|
+
- spec/examples/mock_adapter_spec.rb
|
150
|
+
- spec/examples/spec_helper.rb
|
151
|
+
- README.md
|
152
|
+
- LICENSE
|
153
|
+
homepage: https://github.com/xaq2892/giant_client
|
154
|
+
licenses:
|
155
|
+
- MIT
|
156
|
+
post_install_message:
|
157
|
+
rdoc_options: []
|
158
|
+
require_paths:
|
159
|
+
- lib
|
160
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
161
|
+
none: false
|
162
|
+
requirements:
|
163
|
+
- - ! '>='
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
|
+
none: false
|
168
|
+
requirements:
|
169
|
+
- - ! '>='
|
170
|
+
- !ruby/object:Gem::Version
|
171
|
+
version: '0'
|
172
|
+
requirements: []
|
173
|
+
rubyforge_project:
|
174
|
+
rubygems_version: 1.8.24
|
175
|
+
signing_key:
|
176
|
+
specification_version: 3
|
177
|
+
summary: Lightweight wrapper for major HTTP client libraries
|
178
|
+
test_files: []
|