restfulie 0.9.1 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -4
- data/Gemfile.lock +128 -0
- data/README.textile +10 -12
- data/Rakefile +67 -104
- data/lib/restfulie/server/action_controller/base.rb +4 -3
- data/lib/restfulie/server/action_controller/cacheable_responder.rb +7 -1
- data/lib/restfulie/server/action_controller/created_responder.rb +1 -1
- data/lib/restfulie/server/action_controller/params_parser.rb +69 -31
- data/lib/restfulie/server/action_view/helpers.rb +1 -2
- data/lib/restfulie/server/action_view/template_handlers.rb +12 -7
- data/lib/restfulie/server/core_ext/array.rb +12 -2
- data/lib/restfulie/server.rb +0 -1
- data/lib/restfulie/version.rb +1 -1
- data/lib/restfulie.rb +1 -0
- metadata +8 -23
data/Gemfile
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
# A sample Gemfile
|
2
2
|
source :gemcutter
|
3
3
|
#
|
4
|
-
gem "rails"
|
4
|
+
gem "rails", ">= 3.0.0"
|
5
5
|
gem "libxml-ruby"
|
6
6
|
|
7
7
|
gem "rack-conneg"
|
8
|
-
gem "responders_backport"
|
9
8
|
gem "json_pure"
|
10
9
|
gem "sqlite3-ruby"
|
11
10
|
gem "yard"
|
@@ -18,11 +17,10 @@ end
|
|
18
17
|
|
19
18
|
group :test do
|
20
19
|
gem "nokogiri"
|
21
|
-
gem "rspec-rails"
|
20
|
+
gem "rspec-rails", ">= 2.0.0.beta.19"
|
22
21
|
gem "rcov"
|
23
22
|
gem "sinatra"
|
24
23
|
gem "state_machine"
|
25
24
|
gem "test-unit", "= 1.2.3"
|
26
|
-
gem "rails", "= 2.3.5"
|
27
25
|
gem "fakeweb"
|
28
26
|
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
abstract (1.0.0)
|
5
|
+
actionmailer (3.0.0)
|
6
|
+
actionpack (= 3.0.0)
|
7
|
+
mail (~> 2.2.5)
|
8
|
+
actionpack (3.0.0)
|
9
|
+
activemodel (= 3.0.0)
|
10
|
+
activesupport (= 3.0.0)
|
11
|
+
builder (~> 2.1.2)
|
12
|
+
erubis (~> 2.6.6)
|
13
|
+
i18n (~> 0.4.1)
|
14
|
+
rack (~> 1.2.1)
|
15
|
+
rack-mount (~> 0.6.12)
|
16
|
+
rack-test (~> 0.5.4)
|
17
|
+
tzinfo (~> 0.3.23)
|
18
|
+
activemodel (3.0.0)
|
19
|
+
activesupport (= 3.0.0)
|
20
|
+
builder (~> 2.1.2)
|
21
|
+
i18n (~> 0.4.1)
|
22
|
+
activerecord (3.0.0)
|
23
|
+
activemodel (= 3.0.0)
|
24
|
+
activesupport (= 3.0.0)
|
25
|
+
arel (~> 1.0.0)
|
26
|
+
tzinfo (~> 0.3.23)
|
27
|
+
activeresource (3.0.0)
|
28
|
+
activemodel (= 3.0.0)
|
29
|
+
activesupport (= 3.0.0)
|
30
|
+
activesupport (3.0.0)
|
31
|
+
arel (1.0.1)
|
32
|
+
activesupport (~> 3.0.0)
|
33
|
+
builder (2.1.2)
|
34
|
+
columnize (0.3.1)
|
35
|
+
diff-lcs (1.1.2)
|
36
|
+
erubis (2.6.6)
|
37
|
+
abstract (>= 1.0.0)
|
38
|
+
fakeweb (1.2.8)
|
39
|
+
hoe (2.6.1)
|
40
|
+
rake (>= 0.8.7)
|
41
|
+
rubyforge (>= 2.0.4)
|
42
|
+
i18n (0.4.1)
|
43
|
+
json_pure (1.4.6)
|
44
|
+
libxml-ruby (1.1.4)
|
45
|
+
linecache (0.43)
|
46
|
+
mail (2.2.5)
|
47
|
+
activesupport (>= 2.3.6)
|
48
|
+
mime-types
|
49
|
+
treetop (>= 1.4.5)
|
50
|
+
mime-types (1.16)
|
51
|
+
nokogiri (1.4.3.1)
|
52
|
+
polyglot (0.3.1)
|
53
|
+
rack (1.2.1)
|
54
|
+
rack-conneg (0.1.4)
|
55
|
+
rack (>= 1.0)
|
56
|
+
rack-mount (0.6.12)
|
57
|
+
rack (>= 1.0.0)
|
58
|
+
rack-test (0.5.4)
|
59
|
+
rack (>= 1.0)
|
60
|
+
rails (3.0.0)
|
61
|
+
actionmailer (= 3.0.0)
|
62
|
+
actionpack (= 3.0.0)
|
63
|
+
activerecord (= 3.0.0)
|
64
|
+
activeresource (= 3.0.0)
|
65
|
+
activesupport (= 3.0.0)
|
66
|
+
bundler (~> 1.0.0)
|
67
|
+
railties (= 3.0.0)
|
68
|
+
railties (3.0.0)
|
69
|
+
actionpack (= 3.0.0)
|
70
|
+
activesupport (= 3.0.0)
|
71
|
+
rake (>= 0.8.4)
|
72
|
+
thor (~> 0.14.0)
|
73
|
+
rake (0.8.7)
|
74
|
+
rcov (0.9.8)
|
75
|
+
responders_backport (0.1.2)
|
76
|
+
rspec (2.0.0.beta.19)
|
77
|
+
rspec-core (= 2.0.0.beta.19)
|
78
|
+
rspec-expectations (= 2.0.0.beta.19)
|
79
|
+
rspec-mocks (= 2.0.0.beta.19)
|
80
|
+
rspec-core (2.0.0.beta.19)
|
81
|
+
rspec-expectations (2.0.0.beta.19)
|
82
|
+
diff-lcs (>= 1.1.2)
|
83
|
+
rspec-mocks (2.0.0.beta.19)
|
84
|
+
rspec-rails (2.0.0.beta.19)
|
85
|
+
rspec (= 2.0.0.beta.19)
|
86
|
+
webrat (>= 0.7.2.beta.1)
|
87
|
+
ruby-debug (0.10.3)
|
88
|
+
columnize (>= 0.1)
|
89
|
+
ruby-debug-base (~> 0.10.3.0)
|
90
|
+
ruby-debug-base (0.10.3)
|
91
|
+
linecache (>= 0.3)
|
92
|
+
rubyforge (2.0.4)
|
93
|
+
json_pure (>= 1.1.7)
|
94
|
+
sinatra (1.0)
|
95
|
+
rack (>= 1.0)
|
96
|
+
sqlite3-ruby (1.3.1)
|
97
|
+
state_machine (0.9.4)
|
98
|
+
test-unit (1.2.3)
|
99
|
+
hoe (>= 1.5.1)
|
100
|
+
thor (0.14.0)
|
101
|
+
treetop (1.4.8)
|
102
|
+
polyglot (>= 0.3.1)
|
103
|
+
tzinfo (0.3.23)
|
104
|
+
webrat (0.7.2.beta.1)
|
105
|
+
nokogiri (>= 1.2.0)
|
106
|
+
rack (>= 1.0)
|
107
|
+
rack-test (>= 0.5.3)
|
108
|
+
yard (0.5.8)
|
109
|
+
|
110
|
+
PLATFORMS
|
111
|
+
ruby
|
112
|
+
|
113
|
+
DEPENDENCIES
|
114
|
+
fakeweb
|
115
|
+
json_pure
|
116
|
+
libxml-ruby
|
117
|
+
nokogiri
|
118
|
+
rack-conneg
|
119
|
+
rails (>= 3.0.0)
|
120
|
+
rcov
|
121
|
+
responders_backport
|
122
|
+
rspec-rails (>= 2.0.0.beta.19)
|
123
|
+
ruby-debug
|
124
|
+
sinatra
|
125
|
+
sqlite3-ruby
|
126
|
+
state_machine
|
127
|
+
test-unit (= 1.2.3)
|
128
|
+
yard
|
data/README.textile
CHANGED
@@ -83,14 +83,7 @@ Appart from the simple server and client examples provided here, you can find th
|
|
83
83
|
|
84
84
|
h2. Installing
|
85
85
|
|
86
|
-
|
87
|
-
|
88
|
-
<pre>
|
89
|
-
gem install activesupport
|
90
|
-
gem install restfulie
|
91
|
-
</pre>
|
92
|
-
|
93
|
-
For server side usage, execute:
|
86
|
+
Execute:
|
94
87
|
|
95
88
|
<pre>
|
96
89
|
gem install restfulie
|
@@ -103,6 +96,7 @@ If you want to build the project and run its tests, remember to install all (cli
|
|
103
96
|
|
104
97
|
<pre>
|
105
98
|
bundle install
|
99
|
+
rake test:spec test:integration
|
106
100
|
</pre>
|
107
101
|
|
108
102
|
<script type="text/javascript">
|
@@ -117,10 +111,10 @@ pageTracker._trackPageview();
|
|
117
111
|
|
118
112
|
h2. Contributions
|
119
113
|
|
120
|
-
Restfulie was created and is maintained by "http://caelumobjects.com
|
114
|
+
Restfulie was created and is maintained by "Caelum":http://caelumobjects.com, and has received enormous contributions from all those developers:
|
121
115
|
|
122
116
|
Project Leader
|
123
|
-
Guilherme Silveira, "http://caelum.com.br
|
117
|
+
Guilherme Silveira, "Caelum":http://www.caelum.com.br
|
124
118
|
|
125
119
|
Caue Guerra, caelum
|
126
120
|
George Guimaraes, abril and plataforma
|
@@ -134,5 +128,9 @@ Everton Ribeiro, abril
|
|
134
128
|
Paulo Ahagon, abril
|
135
129
|
Elomar França
|
136
130
|
Thomas Stefano
|
137
|
-
"http://www.caelum.com.br"
|
138
|
-
"http://www.caikesouza.com/blog"
|
131
|
+
"David Paniz":"http://www.caelum.com.br"
|
132
|
+
"Caike Souza":"http://www.caikesouza.com/blog"
|
133
|
+
|
134
|
+
h2. Rails 2
|
135
|
+
|
136
|
+
If you want to use Restfulie with Rails2, please use any release up to 0.9.2 and its minor releases.
|
data/Rakefile
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
1
|
require 'rubygems'
|
4
2
|
require 'rubygems/specification'
|
5
3
|
require 'rake'
|
6
4
|
require 'rake/gempackagetask'
|
7
|
-
require 'spec/rake/spectask'
|
8
5
|
require 'rake/rdoctask'
|
6
|
+
require 'rspec'
|
7
|
+
require 'rspec/core'
|
8
|
+
require 'rspec/core/rake_task'
|
9
9
|
require File.expand_path('lib/restfulie')
|
10
10
|
|
11
11
|
GEM = "restfulie"
|
12
12
|
GEM_VERSION = Restfulie::VERSION
|
13
13
|
SUMMARY = "Hypermedia aware resource based library in ruby (client side) and ruby on rails (server side)."
|
14
|
-
AUTHOR = "Guilherme Silveira, Caue Guerra, Luis Cipriani, Everton Ribeiro, George Guimaraes, Paulo Ahagon"
|
14
|
+
AUTHOR = "Guilherme Silveira, Caue Guerra, Luis Cipriani, Everton Ribeiro, George Guimaraes, Paulo Ahagon, Several contributors"
|
15
15
|
EMAIL = "guilherme.silveira@caelum.com.br"
|
16
16
|
HOMEPAGE = "http://restfulie.caelumobjects.com"
|
17
17
|
|
@@ -25,7 +25,6 @@ spec = Gem::Specification.new do |s|
|
|
25
25
|
s.add_dependency("nokogiri", [">= 1.4.2"])
|
26
26
|
s.add_dependency("actionpack", [">= 2.3.2"])
|
27
27
|
s.add_dependency("activesupport", [">= 2.3.2"])
|
28
|
-
s.add_dependency("responders_backport", ["~> 0.1.0"])
|
29
28
|
s.add_dependency("json_pure", [">= 1.2.4"])
|
30
29
|
|
31
30
|
s.author = AUTHOR
|
@@ -33,120 +32,84 @@ spec = Gem::Specification.new do |s|
|
|
33
32
|
s.homepage = HOMEPAGE
|
34
33
|
end
|
35
34
|
|
36
|
-
|
37
|
-
def
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
wait_server(4567)
|
46
|
-
Rake::Task[task_name].invoke
|
47
|
-
Process.kill 'INT', pipe.pid
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def wait_server(port=3000)
|
52
|
-
(1..15).each do
|
53
|
-
begin
|
54
|
-
Net::HTTP.get(URI.parse("http://localhost:#{port}/"))
|
55
|
-
return
|
56
|
-
rescue
|
57
|
-
sleep 1
|
35
|
+
module FakeServer
|
36
|
+
def self.wait_server(port=3000)
|
37
|
+
(1..15).each do
|
38
|
+
begin
|
39
|
+
Net::HTTP.get(URI.parse("http://localhost:#{port}/"))
|
40
|
+
return
|
41
|
+
rescue
|
42
|
+
sleep 1
|
43
|
+
end
|
58
44
|
end
|
45
|
+
raise "Waited for the server but it did not finish"
|
59
46
|
end
|
60
|
-
raise "Waited for the server but it did not finish"
|
61
|
-
end
|
62
|
-
|
63
|
-
desc 'Start server'
|
64
|
-
task :server do
|
65
|
-
process 'fake_server'
|
66
|
-
end
|
67
|
-
|
68
|
-
namespace :test do
|
69
47
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
system('rake db:drop db:create db:migrate')
|
76
|
-
system('rake')
|
48
|
+
def self.start_sinatra
|
49
|
+
IO.popen("cd tests && ruby ./spec/requests/fake_server.rb") do |pipe|
|
50
|
+
wait_server 4567
|
51
|
+
yield
|
52
|
+
Process.kill 'INT', pipe.pid
|
77
53
|
end
|
78
54
|
end
|
79
55
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
Spec::Rake::SpecTask.new(:common) do |t|
|
87
|
-
t.spec_files = FileList['spec/common/**/*_spec.rb']
|
88
|
-
t.spec_opts = spec_opts
|
89
|
-
end
|
90
|
-
Spec::Rake::SpecTask.new(:client) do |t|
|
91
|
-
t.spec_files = FileList['spec/units/client/**/*_spec.rb']
|
92
|
-
t.spec_opts = spec_opts
|
56
|
+
def self.run(setup, process)
|
57
|
+
success = IO.popen(setup) do |pipe|
|
58
|
+
wait_server
|
59
|
+
success = system "rake spec"
|
60
|
+
Process.kill 'INT', pipe.pid
|
61
|
+
success
|
93
62
|
end
|
94
|
-
|
95
|
-
|
96
|
-
t.spec_opts = spec_opts
|
63
|
+
if !success
|
64
|
+
raise "Some of the specs failed"
|
97
65
|
end
|
98
66
|
end
|
99
67
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
t.spec_files = FileList['spec/units/**/*_spec.rb']
|
105
|
-
t.rcov = true
|
106
|
-
t.rcov_opts = ["-e", "/Library*", "-e", "~/.rvm", "-e", "spec", "-i", "bin"]
|
107
|
-
end
|
108
|
-
desc 'Run coverage test with fake server'
|
109
|
-
task :run do
|
110
|
-
start_server_and_invoke_test('test:rcov:rcov')
|
68
|
+
def self.start_server_and_run_spec(target_dir)
|
69
|
+
success = Dir.chdir(File.join(File.dirname(__FILE__), target_dir)) do
|
70
|
+
system('rake db:drop db:create db:migrate')
|
71
|
+
self.run "rails server", "rake spec"
|
111
72
|
end
|
112
73
|
end
|
113
74
|
|
114
|
-
|
115
|
-
task :all do
|
116
|
-
start_server_and_invoke_test('test:spec:all')
|
117
|
-
puts "Execution integration tests... (task test:integration)"
|
118
|
-
Rake::Task["test:integration"].invoke()
|
119
|
-
Rake::Task["test:examples"].invoke()
|
120
|
-
end
|
121
|
-
task :common do
|
122
|
-
start_server_and_invoke_test('test:spec:common')
|
123
|
-
end
|
124
|
-
task :client do
|
125
|
-
start_server_and_invoke_test('test:spec:client')
|
126
|
-
end
|
127
|
-
task :server do
|
128
|
-
start_server_and_invoke_test('test:spec:server')
|
129
|
-
end
|
130
|
-
task :rcov do
|
131
|
-
start_server_and_invoke_test('test:rcov:rcov')
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
desc "runs all example tests"
|
136
|
-
task :examples do
|
137
|
-
Rake::Task["install"].invoke()
|
75
|
+
end
|
138
76
|
|
139
|
-
|
140
|
-
|
77
|
+
# optionally loads a task if the required gems exist
|
78
|
+
def optionally
|
79
|
+
begin
|
80
|
+
yield
|
81
|
+
rescue LoadError; end
|
82
|
+
end
|
141
83
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
84
|
+
namespace :test do
|
85
|
+
|
86
|
+
task :spec do
|
87
|
+
FakeServer.start_sinatra do
|
88
|
+
FakeServer.start_server_and_run_spec "tests"
|
146
89
|
end
|
147
|
-
|
148
90
|
end
|
149
|
-
|
91
|
+
|
92
|
+
task :integration do
|
93
|
+
FakeServer.start_server_and_run_spec "full-examples/rest_from_scratch/part_1"
|
94
|
+
FakeServer.start_server_and_run_spec "full-examples/rest_from_scratch/part_2"
|
95
|
+
FakeServer.start_server_and_run_spec "full-examples/rest_from_scratch/part_3"
|
96
|
+
end
|
97
|
+
|
98
|
+
task :all => ["spec","integration"]
|
99
|
+
|
100
|
+
# namespace :rcov do
|
101
|
+
# Spec::Rake::SpecTask.new('rcov') do |t|
|
102
|
+
# t.spec_opts = %w(-fs --color)
|
103
|
+
# t.spec_files = FileList['spec/units/**/*_spec.rb']
|
104
|
+
# t.rcov = true
|
105
|
+
# t.rcov_opts = ["-e", "/Library*", "-e", "~/.rvm", "-e", "spec", "-i", "bin"]
|
106
|
+
# end
|
107
|
+
# desc 'Run coverage test with fake server'
|
108
|
+
# task :run do
|
109
|
+
# start_server_and_invoke_test('test:rcov:rcov')
|
110
|
+
# end
|
111
|
+
# end
|
112
|
+
|
150
113
|
end
|
151
114
|
|
152
115
|
Rake::GemPackageTask.new(spec) do |pkg|
|
@@ -177,8 +140,8 @@ task :make_spec do
|
|
177
140
|
end
|
178
141
|
|
179
142
|
desc "Builds the project"
|
180
|
-
task :build => :spec
|
143
|
+
task :build => ["install", "test:spec"]
|
181
144
|
|
182
145
|
desc "Default build will run specs"
|
183
|
-
task :default =>
|
146
|
+
task :default => :build
|
184
147
|
|
@@ -28,15 +28,16 @@ module Restfulie
|
|
28
28
|
defined?(Restfulie::Server::ActionController::Base) && self.include?(Restfulie::Server::ActionController::Base)
|
29
29
|
end
|
30
30
|
end
|
31
|
-
|
32
|
-
protected
|
33
31
|
|
34
32
|
# If your controller inherits from Restfulie::Server::Controller::Base,
|
35
33
|
# it will have an :atom option, very similar to render :xml
|
36
34
|
def render(options = nil, extra_options = {}, &block)
|
37
35
|
if options && atom = options[:atom]
|
38
36
|
response.content_type ||= Mime::ATOM
|
39
|
-
|
37
|
+
representation = atom.respond_to?(:to_atom) ? atom.to_atom.to_xml : atom.to_xml
|
38
|
+
options[:text] = representation
|
39
|
+
options[:atom] = nil
|
40
|
+
super options
|
40
41
|
else
|
41
42
|
super
|
42
43
|
end
|
@@ -56,14 +56,20 @@ module Restfulie
|
|
56
56
|
super
|
57
57
|
end
|
58
58
|
end
|
59
|
+
|
60
|
+
private
|
59
61
|
|
60
62
|
def set_public_cache_control!
|
61
|
-
cache_control =
|
63
|
+
cache_control = cache_control_headers.split(",").map {|k| k.strip }
|
62
64
|
cache_control.delete("private")
|
63
65
|
cache_control.delete("no-cache")
|
64
66
|
cache_control << "public"
|
65
67
|
controller.response.headers["Cache-Control"] = cache_control.join(', ')
|
66
68
|
end
|
69
|
+
|
70
|
+
def cache_control_headers
|
71
|
+
controller.response.headers["Cache-Control"] || ""
|
72
|
+
end
|
67
73
|
|
68
74
|
end
|
69
75
|
end
|
@@ -1,10 +1,73 @@
|
|
1
1
|
module Restfulie
|
2
2
|
module Server
|
3
3
|
module ActionController
|
4
|
+
|
5
|
+
# This class is just a proxy for the extension point offered by ActionDispatch::ParamsParser
|
6
|
+
class ParamsParser3
|
7
|
+
|
8
|
+
def register(content_type, representation)
|
9
|
+
ActionDispatch::ParamsParser::DEFAULT_PARSERS[Mime::Type.lookup(content_type)] = representation.method(:to_hash).to_proc
|
10
|
+
end
|
11
|
+
|
12
|
+
def unregister(content_type)
|
13
|
+
ActionDispatch::ParamsParser::DEFAULT_PARSERS.delete(Mime::Type.lookup(content_type))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# This class is just a proxy for the extension point offered by ActionController::Base
|
18
|
+
class ParamsParser2
|
19
|
+
|
20
|
+
def param_parsers
|
21
|
+
::ActionController::Base.param_parsers
|
22
|
+
end
|
23
|
+
|
24
|
+
def register(content_type, representation)
|
25
|
+
param_parsers[Mime::Type.lookup(content_type)] = representation.method(:to_hash).to_proc
|
26
|
+
end
|
27
|
+
|
28
|
+
def unregister(content_type)
|
29
|
+
param_parsers.delete(Mime::Type.lookup(content_type))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
4
34
|
class ParamsParser
|
5
|
-
|
6
|
-
|
35
|
+
|
36
|
+
def self.rails3?
|
37
|
+
defined?(::ActionDispatch) && defined?(::ActionDispatch::ParamsParser)
|
38
|
+
end
|
39
|
+
|
40
|
+
if rails3?
|
41
|
+
@parser = ParamsParser3.new
|
42
|
+
else
|
43
|
+
@parser = ParamsParser2.new
|
44
|
+
# This monkey patch is needed because Rails 2.3.5 doesn't support
|
45
|
+
# a way of use rescue_from ActionController handling to return
|
46
|
+
# bad request status when trying to parse an invalid body request
|
47
|
+
#
|
48
|
+
# In Rails 3 this won't be necessary, because all exception handling
|
49
|
+
# extensions are handled by the Rack stack
|
50
|
+
#
|
51
|
+
# TODO Change this when porting this code to Rails 3
|
52
|
+
::ActionController::ParamsParser.class_eval do
|
53
|
+
def call(env)
|
54
|
+
begin
|
55
|
+
if params = parse_formatted_parameters(env)
|
56
|
+
env["action_controller.request.request_parameters"] = params
|
57
|
+
elsif !(env["CONTENT_TYPE"] == "application/x-www-form-urlencoded") #do not override rails default behaviour for this media type, it's dangerous... (o.O)
|
58
|
+
if env["CONTENT_LENGTH"] && (env["CONTENT_LENGTH"] != "0")
|
59
|
+
env["action_controller.restfulie.response"] = [415, {'Content-Type' => 'text/html'}, ["<html><body><h1>415 Unsupported Media Type</h1></body></html>"]]
|
60
|
+
end
|
61
|
+
end
|
62
|
+
rescue
|
63
|
+
env["action_controller.restfulie.response"] = [400, {'Content-Type' => 'text/html'}, ["<html><body><h1>400 Bad Request</h1></body></html>"]]
|
64
|
+
end
|
7
65
|
|
66
|
+
@app.call(env)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
8
71
|
##
|
9
72
|
# :singleton-method:
|
10
73
|
# Use it to register param parsers on the server side.
|
@@ -15,9 +78,9 @@ module Restfulie
|
|
15
78
|
# Restfulie::Server::ActionController::ParamsParser.register('application/atom+xml', Atom)
|
16
79
|
#
|
17
80
|
def self.register(content_type, representation)
|
18
|
-
|
81
|
+
@parser.register(content_type, representation)
|
19
82
|
end
|
20
|
-
|
83
|
+
|
21
84
|
##
|
22
85
|
# :singleton-method:
|
23
86
|
# Use it to unregister param parsers on the server side.
|
@@ -27,36 +90,11 @@ module Restfulie
|
|
27
90
|
# Restfulie::Server::ActionController::ParamsParser.unregister('application/atom+xml')
|
28
91
|
#
|
29
92
|
def self.unregister(content_type)
|
30
|
-
|
93
|
+
@parser.unregister(content_type)
|
31
94
|
end
|
32
95
|
end
|
96
|
+
|
33
97
|
end
|
34
98
|
end
|
35
99
|
end
|
36
100
|
|
37
|
-
# This monkey patch is needed because Rails 2.3.5 doesn't support
|
38
|
-
# a way of use rescue_from ActionController handling to return
|
39
|
-
# bad request status when trying to parse an invalid body request
|
40
|
-
#
|
41
|
-
# In Rails 3 this won't be necessary, because all exception handling
|
42
|
-
# extensions are handled by the Rack stack
|
43
|
-
#
|
44
|
-
# TODO Change this when porting this code to Rails 3
|
45
|
-
::ActionController::ParamsParser.class_eval do
|
46
|
-
def call(env)
|
47
|
-
begin
|
48
|
-
if params = parse_formatted_parameters(env)
|
49
|
-
env["action_controller.request.request_parameters"] = params
|
50
|
-
elsif !(env["CONTENT_TYPE"] == "application/x-www-form-urlencoded") #do not override rails default behaviour for this media type, it's dangerous... (o.O)
|
51
|
-
if env["CONTENT_LENGTH"] && (env["CONTENT_LENGTH"] != "0")
|
52
|
-
env["action_controller.restfulie.response"] = [415, {'Content-Type' => 'text/html'}, ["<html><body><h1>415 Unsupported Media Type</h1></body></html>"]]
|
53
|
-
end
|
54
|
-
end
|
55
|
-
rescue
|
56
|
-
env["action_controller.restfulie.response"] = [400, {'Content-Type' => 'text/html'}, ["<html><body><h1>400 Bad Request</h1></body></html>"]]
|
57
|
-
end
|
58
|
-
|
59
|
-
@app.call(env)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
@@ -25,8 +25,6 @@ module Restfulie
|
|
25
25
|
# end
|
26
26
|
#
|
27
27
|
def partial(partial_path, caller_binding = nil)
|
28
|
-
template = _pick_partial_template(partial_path)
|
29
|
-
|
30
28
|
# Create a context to assing variables
|
31
29
|
if caller_binding.kind_of?(Hash)
|
32
30
|
Proc.new do
|
@@ -42,6 +40,7 @@ module Restfulie
|
|
42
40
|
partial(partial_path, binding)
|
43
41
|
end.call
|
44
42
|
else
|
43
|
+
template = _pick_partial_template(partial_path)
|
45
44
|
eval(template.source, caller_binding, template.path)
|
46
45
|
end
|
47
46
|
end
|
@@ -4,20 +4,25 @@ module Restfulie
|
|
4
4
|
module TemplateHandlers #:nodoc:
|
5
5
|
autoload :Tokamak, 'restfulie/server/action_view/template_handlers/tokamak'
|
6
6
|
|
7
|
-
|
8
|
-
# template handler
|
9
|
-
def self.activate!
|
7
|
+
def self.template_registry
|
10
8
|
if defined? ::ActionView::Template and
|
11
9
|
::ActionView::Template.respond_to?(:register_template_handler)
|
12
10
|
::ActionView::Template
|
13
11
|
else
|
14
12
|
::ActionView::Base
|
15
|
-
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# It is needed to explicitly call 'activate!' to install the Tokamak
|
17
|
+
# template handler
|
18
|
+
def self.activate!
|
19
|
+
template_registry.register_template_handler(:tokamak,
|
16
20
|
Restfulie::Server::ActionView::TemplateHandlers::Tokamak)
|
17
21
|
|
18
|
-
if
|
19
|
-
|
20
|
-
|
22
|
+
# TODO unsure if it can be removed. check feedback prior to 1.0.0
|
23
|
+
# if defined?(::ActionController::Base) && ::ActionController::Base.respond_to?(:exempt_from_layout)
|
24
|
+
# ::ActionController::Base.exempt_from_layout :tokamak
|
25
|
+
# end
|
21
26
|
end
|
22
27
|
end
|
23
28
|
end
|
@@ -42,10 +42,20 @@ class Array
|
|
42
42
|
# albums.updated_at(:created_at)
|
43
43
|
#
|
44
44
|
def updated_at(field = :updated_at)
|
45
|
-
|
45
|
+
max = max_by{|o| o.send(field)}
|
46
|
+
if max
|
47
|
+
max.send(field)
|
48
|
+
else
|
49
|
+
Time.now
|
50
|
+
end
|
46
51
|
end
|
47
52
|
|
48
53
|
def published_at(field = :published_at)
|
49
|
-
|
54
|
+
min = min_by{|o| o.send(field)}
|
55
|
+
if min
|
56
|
+
min.send(field)
|
57
|
+
else
|
58
|
+
Time.now
|
59
|
+
end
|
50
60
|
end
|
51
61
|
end
|
data/lib/restfulie/server.rb
CHANGED
data/lib/restfulie/version.rb
CHANGED
data/lib/restfulie.rb
CHANGED
metadata
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restfulie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 61
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
version: 0.9.
|
9
|
+
- 3
|
10
|
+
version: 0.9.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
|
-
- Guilherme Silveira, Caue Guerra, Luis Cipriani, Everton Ribeiro, George Guimaraes, Paulo Ahagon
|
13
|
+
- Guilherme Silveira, Caue Guerra, Luis Cipriani, Everton Ribeiro, George Guimaraes, Paulo Ahagon, Several contributors
|
14
14
|
autorequire:
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-31 00:00:00 -03:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -66,26 +66,10 @@ dependencies:
|
|
66
66
|
version: 2.3.2
|
67
67
|
type: :runtime
|
68
68
|
version_requirements: *id003
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: responders_backport
|
71
|
-
prerelease: false
|
72
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
|
-
requirements:
|
75
|
-
- - ~>
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
hash: 27
|
78
|
-
segments:
|
79
|
-
- 0
|
80
|
-
- 1
|
81
|
-
- 0
|
82
|
-
version: 0.1.0
|
83
|
-
type: :runtime
|
84
|
-
version_requirements: *id004
|
85
69
|
- !ruby/object:Gem::Dependency
|
86
70
|
name: json_pure
|
87
71
|
prerelease: false
|
88
|
-
requirement: &
|
72
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
89
73
|
none: false
|
90
74
|
requirements:
|
91
75
|
- - ">="
|
@@ -97,7 +81,7 @@ dependencies:
|
|
97
81
|
- 4
|
98
82
|
version: 1.2.4
|
99
83
|
type: :runtime
|
100
|
-
version_requirements: *
|
84
|
+
version_requirements: *id004
|
101
85
|
description:
|
102
86
|
email: guilherme.silveira@caelum.com.br
|
103
87
|
executables: []
|
@@ -206,6 +190,7 @@ files:
|
|
206
190
|
- lib/restfulie/version.rb
|
207
191
|
- lib/restfulie.rb
|
208
192
|
- Gemfile
|
193
|
+
- Gemfile.lock
|
209
194
|
- LICENSE
|
210
195
|
- Rakefile
|
211
196
|
- README.textile
|