pezra-resourceful 0.5.4
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/MIT-LICENSE +21 -0
- data/Manifest +34 -0
- data/README.markdown +84 -0
- data/Rakefile +91 -0
- data/lib/resourceful.rb +18 -0
- data/lib/resourceful/authentication_manager.rb +108 -0
- data/lib/resourceful/cache_manager.rb +240 -0
- data/lib/resourceful/exceptions.rb +34 -0
- data/lib/resourceful/header.rb +126 -0
- data/lib/resourceful/http_accessor.rb +104 -0
- data/lib/resourceful/memcache_cache_manager.rb +75 -0
- data/lib/resourceful/multipart_form_data.rb +51 -0
- data/lib/resourceful/net_http_adapter.rb +78 -0
- data/lib/resourceful/options_interpretation.rb +72 -0
- data/lib/resourceful/request.rb +234 -0
- data/lib/resourceful/resource.rb +178 -0
- data/lib/resourceful/response.rb +222 -0
- data/lib/resourceful/stubbed_resource_proxy.rb +47 -0
- data/lib/resourceful/util.rb +6 -0
- data/resourceful.gemspec +49 -0
- data/spec/acceptance/authorization_spec.rb +16 -0
- data/spec/acceptance/caching_spec.rb +190 -0
- data/spec/acceptance/header_spec.rb +24 -0
- data/spec/acceptance/redirecting_spec.rb +12 -0
- data/spec/acceptance/resource_spec.rb +84 -0
- data/spec/acceptance_shared_specs.rb +44 -0
- data/spec/caching_spec.rb +89 -0
- data/spec/old_acceptance_specs.rb +378 -0
- data/spec/resourceful/multipart_form_data_spec.rb +79 -0
- data/spec/resourceful/resource_spec.rb +20 -0
- data/spec/simple_sinatra_server.rb +74 -0
- data/spec/simple_sinatra_server_spec.rb +98 -0
- data/spec/spec.opts +3 -0
- data/spec/spec_helper.rb +29 -0
- metadata +167 -0
@@ -0,0 +1,79 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../spec_helper"
|
2
|
+
require 'tempfile'
|
3
|
+
require "resourceful/multipart_form_data.rb"
|
4
|
+
|
5
|
+
describe Resourceful::MultipartFormData do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@form_data = Resourceful::MultipartFormData.new
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should know its content-type" do
|
12
|
+
@form_data.content_type.should match(/^multipart\/form-data/i)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should know its boundary string" do
|
16
|
+
@form_data.content_type.should match(/; boundary=[0-9A-Za-z]{10,}/i)
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
describe "with simple parameters" do
|
21
|
+
|
22
|
+
it "should all simple parameters to be added" do
|
23
|
+
@form_data.add(:foo, "testing")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should render a multipart form-data document when #read is called" do
|
27
|
+
@form_data.add('foo', 'bar')
|
28
|
+
@form_data.add('baz', 'this')
|
29
|
+
|
30
|
+
boundary = /boundary=(\w+)/.match(@form_data.content_type)[1]
|
31
|
+
@form_data.read.should eql(<<MPFD[0..-2])
|
32
|
+
\r
|
33
|
+
--#{boundary}\r
|
34
|
+
Content-Disposition: form-data; name="foo"\r
|
35
|
+
\r
|
36
|
+
bar\r
|
37
|
+
--#{boundary}\r
|
38
|
+
Content-Disposition: form-data; name="baz"\r
|
39
|
+
\r
|
40
|
+
this\r
|
41
|
+
--#{boundary}--
|
42
|
+
MPFD
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "with file parameter" do
|
47
|
+
it "should add file parameters to be added" do
|
48
|
+
Tempfile.open('resourceful-post-file-tests') do |file_to_upload|
|
49
|
+
file_to_upload << "This is a test"
|
50
|
+
file_to_upload.flush
|
51
|
+
|
52
|
+
@form_data.add_file(:foo, file_to_upload.path)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should render a multipart form-data document when #read is called" do
|
57
|
+
Tempfile.open('resourceful-post-file-tests') do |file_to_upload|
|
58
|
+
file_to_upload << "This is a test"
|
59
|
+
file_to_upload.flush
|
60
|
+
|
61
|
+
@form_data.add_file(:foo, file_to_upload.path)
|
62
|
+
|
63
|
+
boundary = /boundary=(\w+)/.match(@form_data.content_type)[1]
|
64
|
+
@form_data.read.should eql(<<MPFD[0..-2])
|
65
|
+
\r
|
66
|
+
--#{boundary}\r
|
67
|
+
Content-Disposition: form-data; name="foo"; filename="#{File.basename(file_to_upload.path)}"\r
|
68
|
+
Content-Type: application/octet-stream\r
|
69
|
+
\r
|
70
|
+
This is a test\r
|
71
|
+
--#{boundary}--
|
72
|
+
MPFD
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../spec_helper"
|
2
|
+
|
3
|
+
module Resourceful
|
4
|
+
describe Resource do
|
5
|
+
before do
|
6
|
+
@http_adapter = stub(:http_adapter)
|
7
|
+
http = Resourceful::HttpAccessor.new(:http_adapter => @http_adapter)
|
8
|
+
@resource = http.resource('http://foo.example')
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "POSTing" do
|
12
|
+
it "should use bodies content type as the request content-type if it is known" do
|
13
|
+
@http_adapter.should_receive(:make_request).with(anything, anything, anything, hash_including('Content-Type' => 'application/x-special-type')).and_return([200, {}, ""])
|
14
|
+
body = stub(:body, :content_type => 'application/x-special-type', :read => "hello there")
|
15
|
+
@resource.post(body)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
|
2
|
+
require 'sinatra'
|
3
|
+
|
4
|
+
def any(path, opts={}, &blk)
|
5
|
+
%w[head get post put delete].each do |verb|
|
6
|
+
send verb, path, opts, &blk
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def set_request_params_as_response_header!
|
11
|
+
params.each { |k,v| response[k] = v }
|
12
|
+
end
|
13
|
+
|
14
|
+
def set_request_header_in_body!
|
15
|
+
response['Content-Type'] ||= "application/yaml"
|
16
|
+
headers = request.env.reject { |k,v| !v.is_a?(String) }
|
17
|
+
headers.to_yaml
|
18
|
+
end
|
19
|
+
|
20
|
+
get '/' do
|
21
|
+
"Hello, world!"
|
22
|
+
end
|
23
|
+
|
24
|
+
post '/' do
|
25
|
+
request.body
|
26
|
+
end
|
27
|
+
|
28
|
+
put '/' do
|
29
|
+
request.body
|
30
|
+
end
|
31
|
+
|
32
|
+
delete '/' do
|
33
|
+
"Deleted"
|
34
|
+
end
|
35
|
+
|
36
|
+
# Responds with the method used for the request
|
37
|
+
any '/method' do
|
38
|
+
request.env['REQUEST_METHOD']
|
39
|
+
end
|
40
|
+
|
41
|
+
# Responds with the response code in the url
|
42
|
+
any '/code/:code' do
|
43
|
+
status params[:code]
|
44
|
+
set_request_params_as_response_header!
|
45
|
+
set_request_header_in_body!
|
46
|
+
end
|
47
|
+
|
48
|
+
# Sets the response header from the query string, and
|
49
|
+
# dumps the request header into the body as yaml for inspection
|
50
|
+
any '/header' do
|
51
|
+
set_request_params_as_response_header!
|
52
|
+
set_request_header_in_body!
|
53
|
+
end
|
54
|
+
|
55
|
+
# Takes a modified=httpdate as a query param, and a If-Modified-Since header,
|
56
|
+
# and responds 304 if they're the same
|
57
|
+
get '/cached' do
|
58
|
+
set_request_params_as_response_header!
|
59
|
+
set_request_header_in_body!
|
60
|
+
|
61
|
+
response['Last-Modified'] = params[:modified]
|
62
|
+
|
63
|
+
modtime = params[:modified]
|
64
|
+
imstime = request.env['HTTP_IF_MODIFIED_SINCE']
|
65
|
+
|
66
|
+
if modtime && imstime && modtime == imstime
|
67
|
+
status 304
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
Sinatra::Default.set(
|
72
|
+
:port => 42682
|
73
|
+
)
|
74
|
+
|
@@ -0,0 +1,98 @@
|
|
1
|
+
|
2
|
+
require 'rubygems'
|
3
|
+
require 'sinatra'
|
4
|
+
require 'sinatra/test/rspec'
|
5
|
+
|
6
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
7
|
+
|
8
|
+
describe "GET /" do
|
9
|
+
it 'should render "Hello, world!"' do
|
10
|
+
get '/'
|
11
|
+
@response.should be_ok
|
12
|
+
@response.body.should == "Hello, world!"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "POST /" do
|
17
|
+
it 'should be 201 with no body' do
|
18
|
+
post '/'
|
19
|
+
@response.should be_ok
|
20
|
+
@response.body.should == ""
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should return the request body as the response body' do
|
24
|
+
body = "Some text"
|
25
|
+
post '/', body
|
26
|
+
@response.should be_ok
|
27
|
+
@response.body.should == body
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "PUT /" do
|
32
|
+
it 'should be 200 with no body' do
|
33
|
+
put '/'
|
34
|
+
@response.should be_ok
|
35
|
+
@response.body.should == ""
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should return the request body as the response body' do
|
39
|
+
body = "Some text"
|
40
|
+
put '/', body
|
41
|
+
@response.should be_ok
|
42
|
+
@response.body.should == body
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "DELETE /" do
|
47
|
+
it 'should render "Deleted"' do
|
48
|
+
delete '/'
|
49
|
+
@response.should be_ok
|
50
|
+
@response.body.should == "Deleted"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "/method" do
|
55
|
+
it 'should respond with the method used to make the request' do
|
56
|
+
%w[get post put delete].each do |verb|
|
57
|
+
send verb, '/method'
|
58
|
+
@response.body.should == verb.upcase
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "/code/nnn" do
|
64
|
+
it 'should respond with the code provided in the url' do
|
65
|
+
# Just try a handful
|
66
|
+
[200, 201, 301, 302, 304, 403, 404, 500].each do |code|
|
67
|
+
get "/code/#{code}"
|
68
|
+
@response.status.should == code
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "/header" do
|
74
|
+
it 'should set response headers from the query string' do
|
75
|
+
get "/header", "X-Foo" => "Bar"
|
76
|
+
@response['X-Foo'].should == "Bar"
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should dump the request headers into the body as yaml' do
|
80
|
+
get '/header', {}, "X-Foo" => "Bar"
|
81
|
+
body = YAML.load(@response.body)
|
82
|
+
body['X-Foo'].should == "Bar"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "/cache" do
|
87
|
+
it 'should be normal 200 if the modified query param and the ims header dont match' do
|
88
|
+
now = Time.now
|
89
|
+
get '/cached', {"modified" => now.httpdate}, {"HTTP_IF_MODIFIED_SINCE" => (now - 3600).httpdate}
|
90
|
+
@response.should be_ok
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'should be 304 if the modified query param and the ims header are the same' do
|
94
|
+
now = Time.now
|
95
|
+
get '/cached', {"modified" => now.httpdate}, {"HTTP_IF_MODIFIED_SINCE" => now.httpdate}
|
96
|
+
@response.status.should == 304
|
97
|
+
end
|
98
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spec'
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
$LOAD_PATH << File.join(File.dirname(__FILE__), "..", "lib")
|
6
|
+
require 'resourceful'
|
7
|
+
|
8
|
+
$LOAD_PATH << File.dirname(__FILE__) # ./spec
|
9
|
+
|
10
|
+
# Spawn the server in another process
|
11
|
+
|
12
|
+
@server = Thread.new do
|
13
|
+
|
14
|
+
require 'simple_sinatra_server'
|
15
|
+
Sinatra::Default.set(
|
16
|
+
:run => true,
|
17
|
+
:logging => false
|
18
|
+
)
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
# Kill the server process when rspec finishes
|
23
|
+
at_exit { @server.exit }
|
24
|
+
|
25
|
+
|
26
|
+
# Give the app a change to initialize
|
27
|
+
$stderr.puts "Waiting for thin to initialize..."
|
28
|
+
sleep 0.2
|
29
|
+
|
metadata
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pezra-resourceful
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Paul Sadauskas
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-08-07 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: addressable
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.1.0
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: httpauth
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: thin
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: yard
|
47
|
+
type: :development
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sinatra
|
57
|
+
type: :development
|
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: rspec
|
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
|
+
description: An HTTP library for Ruby that takes advantage of everything HTTP has to offer.
|
76
|
+
email: psadauskas@gmail.com
|
77
|
+
executables: []
|
78
|
+
|
79
|
+
extensions: []
|
80
|
+
|
81
|
+
extra_rdoc_files:
|
82
|
+
- lib/resourceful/authentication_manager.rb
|
83
|
+
- lib/resourceful/cache_manager.rb
|
84
|
+
- lib/resourceful/exceptions.rb
|
85
|
+
- lib/resourceful/header.rb
|
86
|
+
- lib/resourceful/http_accessor.rb
|
87
|
+
- lib/resourceful/memcache_cache_manager.rb
|
88
|
+
- lib/resourceful/multipart_form_data.rb
|
89
|
+
- lib/resourceful/net_http_adapter.rb
|
90
|
+
- lib/resourceful/options_interpretation.rb
|
91
|
+
- lib/resourceful/request.rb
|
92
|
+
- lib/resourceful/resource.rb
|
93
|
+
- lib/resourceful/response.rb
|
94
|
+
- lib/resourceful/stubbed_resource_proxy.rb
|
95
|
+
- lib/resourceful/util.rb
|
96
|
+
- lib/resourceful.rb
|
97
|
+
- README.markdown
|
98
|
+
files:
|
99
|
+
- lib/resourceful/authentication_manager.rb
|
100
|
+
- lib/resourceful/cache_manager.rb
|
101
|
+
- lib/resourceful/exceptions.rb
|
102
|
+
- lib/resourceful/header.rb
|
103
|
+
- lib/resourceful/http_accessor.rb
|
104
|
+
- lib/resourceful/memcache_cache_manager.rb
|
105
|
+
- lib/resourceful/multipart_form_data.rb
|
106
|
+
- lib/resourceful/net_http_adapter.rb
|
107
|
+
- lib/resourceful/options_interpretation.rb
|
108
|
+
- lib/resourceful/request.rb
|
109
|
+
- lib/resourceful/resource.rb
|
110
|
+
- lib/resourceful/response.rb
|
111
|
+
- lib/resourceful/stubbed_resource_proxy.rb
|
112
|
+
- lib/resourceful/util.rb
|
113
|
+
- lib/resourceful.rb
|
114
|
+
- Manifest
|
115
|
+
- MIT-LICENSE
|
116
|
+
- Rakefile
|
117
|
+
- README.markdown
|
118
|
+
- resourceful.gemspec
|
119
|
+
- spec/acceptance/authorization_spec.rb
|
120
|
+
- spec/acceptance/caching_spec.rb
|
121
|
+
- spec/acceptance/header_spec.rb
|
122
|
+
- spec/acceptance/redirecting_spec.rb
|
123
|
+
- spec/acceptance/resource_spec.rb
|
124
|
+
- spec/acceptance_shared_specs.rb
|
125
|
+
- spec/caching_spec.rb
|
126
|
+
- spec/old_acceptance_specs.rb
|
127
|
+
- spec/resourceful/multipart_form_data_spec.rb
|
128
|
+
- spec/resourceful/resource_spec.rb
|
129
|
+
- spec/simple_sinatra_server.rb
|
130
|
+
- spec/simple_sinatra_server_spec.rb
|
131
|
+
- spec/spec.opts
|
132
|
+
- spec/spec_helper.rb
|
133
|
+
has_rdoc: true
|
134
|
+
homepage: http://github.com/paul/resourceful
|
135
|
+
licenses:
|
136
|
+
post_install_message:
|
137
|
+
rdoc_options:
|
138
|
+
- --line-numbers
|
139
|
+
- --inline-source
|
140
|
+
- --title
|
141
|
+
- Resourceful
|
142
|
+
- --main
|
143
|
+
- README.markdown
|
144
|
+
require_paths:
|
145
|
+
- lib
|
146
|
+
- ext
|
147
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: "0"
|
152
|
+
version:
|
153
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: "1.2"
|
158
|
+
version:
|
159
|
+
requirements: []
|
160
|
+
|
161
|
+
rubyforge_project: resourceful
|
162
|
+
rubygems_version: 1.3.5
|
163
|
+
signing_key:
|
164
|
+
specification_version: 2
|
165
|
+
summary: An HTTP library for Ruby that takes advantage of everything HTTP has to offer.
|
166
|
+
test_files: []
|
167
|
+
|