resourceful 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +34 -0
- data/README.markdown +3 -5
- data/Rakefile +23 -75
- data/lib/resourceful/authentication_manager.rb +25 -3
- data/lib/resourceful/cache_manager.rb +113 -104
- data/lib/resourceful/http_accessor.rb +20 -5
- data/lib/resourceful/memcache_cache_manager.rb +85 -0
- data/lib/resourceful/net_http_adapter.rb +1 -0
- data/lib/resourceful/request.rb +12 -0
- data/lib/resourceful/resource.rb +13 -9
- data/lib/resourceful/response.rb +2 -1
- data/resourceful.gemspec +52 -0
- data/spec/acceptance_spec.rb +46 -1
- data/spec/resourceful/authentication_manager_spec.rb +49 -4
- data/spec/resourceful/cache_manager_spec.rb +79 -67
- data/spec/resourceful/http_accessor_spec.rb +55 -11
- data/spec/resourceful/memcache_cache_manager_spec.rb +111 -0
- data/spec/resourceful/options_interpreter_spec.rb +9 -1
- data/spec/resourceful/request_spec.rb +9 -2
- data/spec/resourceful/resource_spec.rb +52 -11
- data/spec/simple_http_server_shared_spec.rb +3 -4
- data/spec/simple_http_server_shared_spec_spec.rb +9 -0
- data/spec/spec_helper.rb +1 -2
- metadata +81 -32
- data/lib/resourceful/version.rb +0 -1
@@ -50,7 +50,7 @@ describe Resourceful::Request do
|
|
50
50
|
@net_http_adapter_response = mock('net_http_adapter_response')
|
51
51
|
Resourceful::NetHttpAdapter.stub!(:make_request).and_return(@net_http_adapter_response)
|
52
52
|
|
53
|
-
@response = mock('response', :code => 200, :authoritative= => true, :was_unsuccessful? => false)
|
53
|
+
@response = mock('response', :code => 200, :authoritative= => true, :was_unsuccessful? => false, :request_time= => nil)
|
54
54
|
Resourceful::Response.stub!(:new).and_return(@response)
|
55
55
|
end
|
56
56
|
|
@@ -70,6 +70,13 @@ describe Resourceful::Request do
|
|
70
70
|
@request.request_time.should == now
|
71
71
|
end
|
72
72
|
|
73
|
+
it 'should set the response\'s request time' do
|
74
|
+
now = Time.now
|
75
|
+
Time.stub!(:now).and_return(now)
|
76
|
+
|
77
|
+
@response.should_receive(:request_time=).with(now)
|
78
|
+
@request.response
|
79
|
+
end
|
73
80
|
end
|
74
81
|
|
75
82
|
describe '#should_be_redirected?' do
|
@@ -77,7 +84,7 @@ describe Resourceful::Request do
|
|
77
84
|
@net_http_adapter_response = mock('net_http_adapter_response')
|
78
85
|
Resourceful::NetHttpAdapter.stub!(:make_request).and_return(@net_http_adapter_response)
|
79
86
|
|
80
|
-
@response = mock('response', :code => 200, :authoritative= => true, :was_unsuccessful? => false)
|
87
|
+
@response = mock('response', :code => 200, :authoritative= => true, :was_unsuccessful? => false, :request_time= => nil)
|
81
88
|
Resourceful::Response.stub!(:new).and_return(@response)
|
82
89
|
end
|
83
90
|
|
@@ -37,6 +37,15 @@ describe Resourceful::Resource do
|
|
37
37
|
it 'should take a uri' do
|
38
38
|
@resource.uri.should == @uri
|
39
39
|
end
|
40
|
+
|
41
|
+
it 'should take some default_options' do
|
42
|
+
r = Resourceful::Resource.new(@accessor, @uri, :foo => :bar)
|
43
|
+
r.default_options.should == {:foo => :bar}
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should default to an empty hash for options' do
|
47
|
+
@resource.default_options.should == {}
|
48
|
+
end
|
40
49
|
end
|
41
50
|
|
42
51
|
describe '#effective_uri' do
|
@@ -67,6 +76,22 @@ describe Resourceful::Resource do
|
|
67
76
|
@resource.do_read_request(:some_method, :foo => :bar)
|
68
77
|
end
|
69
78
|
|
79
|
+
describe 'default options' do
|
80
|
+
before do
|
81
|
+
@resource.default_options = {:foo => :bar}
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should merge the header with the default options' do
|
85
|
+
Resourceful::Request.should_receive(:new).with(anything, anything, anything, :foo => :bar).and_return(@request)
|
86
|
+
make_request
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should override any default header with the request header' do
|
90
|
+
Resourceful::Request.should_receive(:new).with(anything, anything, anything, :foo => :baz).and_return(@request)
|
91
|
+
@resource.do_read_request(:some_method, :foo => :baz)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
70
95
|
describe 'non-success responses' do
|
71
96
|
before do
|
72
97
|
@uri = 'http://www.example.com/code/404'
|
@@ -164,7 +189,7 @@ describe Resourceful::Resource do
|
|
164
189
|
end
|
165
190
|
|
166
191
|
it 'should make a new resource from the new location' do
|
167
|
-
new_resource = mock('resource', :do_read_request => @response)
|
192
|
+
new_resource = mock('resource', :do_read_request => @response, :uri => @uri)
|
168
193
|
Resourceful::Resource.should_receive(:new).with(@accessor, @redirected_uri).and_return(new_resource)
|
169
194
|
make_request
|
170
195
|
end
|
@@ -244,7 +269,7 @@ describe Resourceful::Resource do
|
|
244
269
|
describe '#do_write_request' do
|
245
270
|
|
246
271
|
def make_request
|
247
|
-
@resource.do_write_request(:some_method, "data"
|
272
|
+
@resource.do_write_request(:some_method, "data")
|
248
273
|
end
|
249
274
|
|
250
275
|
it 'should make a new request object from the method' do
|
@@ -252,33 +277,49 @@ describe Resourceful::Resource do
|
|
252
277
|
@resource.do_write_request(:some_method, "data")
|
253
278
|
end
|
254
279
|
|
280
|
+
describe 'default options' do
|
281
|
+
before do
|
282
|
+
@resource.default_options = {:foo => :bar}
|
283
|
+
end
|
284
|
+
|
285
|
+
it 'should merge the header with the default options' do
|
286
|
+
Resourceful::Request.should_receive(:new).with(anything, anything, anything, :foo => :bar).and_return(@request)
|
287
|
+
make_request
|
288
|
+
end
|
289
|
+
|
290
|
+
it 'should override any default header with the request header' do
|
291
|
+
Resourceful::Request.should_receive(:new).with(anything, anything, anything, :foo => :baz).and_return(@request)
|
292
|
+
@resource.do_write_request(:some_method, "data", :foo => :baz)
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
255
296
|
describe 'non-success responses' do
|
256
297
|
before do
|
257
298
|
@uri = 'http://www.example.com/code/404'
|
258
299
|
@resource = Resourceful::Resource.new(@accessor, @uri)
|
259
300
|
|
260
301
|
@redirected_uri = 'http://www.example.com/get'
|
261
|
-
@
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
302
|
+
@response = mock('response',
|
303
|
+
:header => {'Location' => [@redirected_uri]},
|
304
|
+
:is_redirect? => false,
|
305
|
+
:is_success? => false,
|
306
|
+
:is_not_authorized? => false,
|
307
|
+
:code => 404)
|
267
308
|
|
268
|
-
@request.stub!(:response).and_return(@
|
309
|
+
@request.stub!(:response).and_return(@response)
|
269
310
|
@request.stub!(:method).and_return(:post)
|
270
311
|
@request.stub!(:uri).and_return('http://www.example.com/code/404')
|
271
312
|
end
|
272
313
|
|
273
314
|
it 'should raise UnsuccessfulHttpRequestError' do
|
274
315
|
lambda {
|
275
|
-
@resource.do_write_request(:post, "data"
|
316
|
+
@resource.do_write_request(:post, "data")
|
276
317
|
}.should raise_error(Resourceful::UnsuccessfulHttpRequestError)
|
277
318
|
end
|
278
319
|
|
279
320
|
it 'should give a reasonable error message' do
|
280
321
|
lambda {
|
281
|
-
@resource.do_write_request(:post, "data"
|
322
|
+
@resource.do_write_request(:post, "data")
|
282
323
|
}.should raise_error("post request to <http://www.example.com/code/404> failed with code 404")
|
283
324
|
end
|
284
325
|
end
|
@@ -123,9 +123,8 @@ end unless defined? AuthorizationResponder
|
|
123
123
|
|
124
124
|
describe 'simple http server', :shared => true do
|
125
125
|
before(:all) do
|
126
|
-
#setup a thin http server we can connect to
|
127
|
-
require 'thin'
|
128
126
|
require 'rack'
|
127
|
+
require 'thin'
|
129
128
|
|
130
129
|
app = Rack::Builder.new do |env|
|
131
130
|
use Rack::ShowExceptions
|
@@ -147,8 +146,8 @@ describe 'simple http server', :shared => true do
|
|
147
146
|
#spawn the server in a separate thread
|
148
147
|
@httpd = Thread.new do
|
149
148
|
Thin::Logging.silent = true
|
150
|
-
#Thin::Logging.debug = true
|
151
|
-
Thin::Server.start(app)
|
149
|
+
# Thin::Logging.debug = true
|
150
|
+
Thin::Server.start(app)
|
152
151
|
end
|
153
152
|
#give the server a chance to initialize
|
154
153
|
sleep 0.05
|
@@ -56,6 +56,15 @@ describe 'http server' do
|
|
56
56
|
resp[1]['Foo'].should == ['bar']
|
57
57
|
end
|
58
58
|
|
59
|
+
it 'should allow the Date header to be overridden' do
|
60
|
+
uri = URI.escape("http://localhost:3000/header?{Date: \"Thu, 21 Aug 2008 20:00:00 GMT\"}")
|
61
|
+
resp = Resourceful::NetHttpAdapter.make_request(:get, uri)
|
62
|
+
|
63
|
+
resp[1].should have_key('Date')
|
64
|
+
resp[1]['Date'].should == ['Thu, 21 Aug 2008 20:00:00 GMT']
|
65
|
+
end
|
66
|
+
|
67
|
+
|
59
68
|
it 'should parse escaped uris properly' do
|
60
69
|
uri = URI.escape("http://localhost:3000/header?{Expire: \"#{Time.now.httpdate}\"}")
|
61
70
|
|
data/spec/spec_helper.rb
CHANGED
@@ -4,8 +4,7 @@ require 'spec'
|
|
4
4
|
require 'pp'
|
5
5
|
require 'facets'
|
6
6
|
|
7
|
-
|
8
|
-
$LOAD_PATH << File.dirname(__FILE__) + "../lib"
|
7
|
+
$LOAD_PATH << Pathname(__FILE__).dirname + "../lib"
|
9
8
|
require 'resourceful/util'
|
10
9
|
require 'resourceful'
|
11
10
|
require 'resourceful/http_accessor'
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resourceful
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Paul Sadauskas
|
7
|
+
- Paul Sadauskas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-12-05 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -52,26 +52,79 @@ dependencies:
|
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: "0"
|
54
54
|
version:
|
55
|
-
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: andand
|
57
|
+
type: :runtime
|
58
|
+
version_requirement:
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
version:
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: thin
|
67
|
+
type: :development
|
68
|
+
version_requirement:
|
69
|
+
version_requirements: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: "0"
|
74
|
+
version:
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: yard
|
77
|
+
type: :development
|
78
|
+
version_requirement:
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: "0"
|
84
|
+
version:
|
85
|
+
description: An HTTP library for Ruby that takes advantage of everything HTTP has to offer.
|
56
86
|
email: psadauskas@gmail.com
|
57
87
|
executables: []
|
58
88
|
|
59
89
|
extensions: []
|
60
90
|
|
61
|
-
extra_rdoc_files:
|
62
|
-
|
63
|
-
|
64
|
-
-
|
91
|
+
extra_rdoc_files:
|
92
|
+
- lib/resourceful.rb
|
93
|
+
- lib/resourceful/authentication_manager.rb
|
94
|
+
- lib/resourceful/util.rb
|
95
|
+
- lib/resourceful/resource.rb
|
96
|
+
- lib/resourceful/memcache_cache_manager.rb
|
97
|
+
- lib/resourceful/net_http_adapter.rb
|
98
|
+
- lib/resourceful/http_accessor.rb
|
99
|
+
- lib/resourceful/stubbed_resource_proxy.rb
|
100
|
+
- lib/resourceful/header.rb
|
101
|
+
- lib/resourceful/cache_manager.rb
|
102
|
+
- lib/resourceful/options_interpreter.rb
|
103
|
+
- lib/resourceful/response.rb
|
104
|
+
- lib/resourceful/request.rb
|
65
105
|
- README.markdown
|
66
|
-
|
106
|
+
files:
|
107
|
+
- lib/resourceful.rb
|
108
|
+
- lib/resourceful/authentication_manager.rb
|
109
|
+
- lib/resourceful/util.rb
|
110
|
+
- lib/resourceful/resource.rb
|
111
|
+
- lib/resourceful/memcache_cache_manager.rb
|
112
|
+
- lib/resourceful/net_http_adapter.rb
|
113
|
+
- lib/resourceful/http_accessor.rb
|
114
|
+
- lib/resourceful/stubbed_resource_proxy.rb
|
115
|
+
- lib/resourceful/header.rb
|
116
|
+
- lib/resourceful/cache_manager.rb
|
117
|
+
- lib/resourceful/options_interpreter.rb
|
118
|
+
- lib/resourceful/response.rb
|
119
|
+
- lib/resourceful/request.rb
|
67
120
|
- spec/acceptance_shared_specs.rb
|
68
121
|
- spec/spec.opts
|
69
122
|
- spec/acceptance_spec.rb
|
70
123
|
- spec/simple_http_server_shared_spec_spec.rb
|
71
124
|
- spec/spec_helper.rb
|
72
|
-
- spec/resourceful
|
73
125
|
- spec/resourceful/header_spec.rb
|
74
126
|
- spec/resourceful/authentication_manager_spec.rb
|
127
|
+
- spec/resourceful/memcache_cache_manager_spec.rb
|
75
128
|
- spec/resourceful/response_spec.rb
|
76
129
|
- spec/resourceful/options_interpreter_spec.rb
|
77
130
|
- spec/resourceful/http_accessor_spec.rb
|
@@ -81,45 +134,41 @@ files:
|
|
81
134
|
- spec/resourceful/cache_manager_spec.rb
|
82
135
|
- spec/resourceful/net_http_adapter_spec.rb
|
83
136
|
- spec/simple_http_server_shared_spec.rb
|
84
|
-
-
|
85
|
-
-
|
86
|
-
-
|
87
|
-
-
|
88
|
-
-
|
89
|
-
|
90
|
-
|
91
|
-
- lib/resourceful/http_accessor.rb
|
92
|
-
- lib/resourceful/stubbed_resource_proxy.rb
|
93
|
-
- lib/resourceful/header.rb
|
94
|
-
- lib/resourceful/cache_manager.rb
|
95
|
-
- lib/resourceful/options_interpreter.rb
|
96
|
-
- lib/resourceful/response.rb
|
97
|
-
- lib/resourceful/request.rb
|
98
|
-
has_rdoc: false
|
99
|
-
homepage: https://github.com/paul/resourceful/tree/master
|
137
|
+
- Manifest
|
138
|
+
- Rakefile
|
139
|
+
- README.markdown
|
140
|
+
- MIT-LICENSE
|
141
|
+
- resourceful.gemspec
|
142
|
+
has_rdoc: true
|
143
|
+
homepage: http://github.com/paul/resourceful
|
100
144
|
post_install_message:
|
101
|
-
rdoc_options:
|
102
|
-
|
145
|
+
rdoc_options:
|
146
|
+
- --line-numbers
|
147
|
+
- --inline-source
|
148
|
+
- --title
|
149
|
+
- Resourceful
|
150
|
+
- --main
|
151
|
+
- README.markdown
|
103
152
|
require_paths:
|
104
153
|
- lib
|
105
154
|
required_ruby_version: !ruby/object:Gem::Requirement
|
106
155
|
requirements:
|
107
156
|
- - ">="
|
108
157
|
- !ruby/object:Gem::Version
|
109
|
-
version:
|
158
|
+
version: "0"
|
110
159
|
version:
|
111
160
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
161
|
requirements:
|
113
162
|
- - ">="
|
114
163
|
- !ruby/object:Gem::Version
|
115
|
-
version: "
|
164
|
+
version: "1.2"
|
116
165
|
version:
|
117
166
|
requirements: []
|
118
167
|
|
119
168
|
rubyforge_project: resourceful
|
120
|
-
rubygems_version: 1.
|
169
|
+
rubygems_version: 1.3.1
|
121
170
|
signing_key:
|
122
171
|
specification_version: 2
|
123
|
-
summary:
|
172
|
+
summary: An HTTP library for Ruby that takes advantage of everything HTTP has to offer.
|
124
173
|
test_files: []
|
125
174
|
|
data/lib/resourceful/version.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
RESOURCEFUL_VERSION = '0.2'
|