grape 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grape might be problematic. Click here for more details.

@@ -0,0 +1,7 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - jruby
5
+ - rbx
6
+ - ree
7
+
data/Gemfile CHANGED
@@ -1,22 +1,3 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
- gem 'rack'
4
- gem 'rack-mount', '~> 0.6.13'
5
- gem 'rack-jsonp'
6
-
7
- gem 'json'
8
- gem 'multi_json'
9
- gem 'multi_xml'
10
-
11
- group :development do
12
- gem 'rake'
13
- gem 'jeweler'
14
- gem 'maruku'
15
- gem 'yard'
16
- end
17
-
18
- group :test do
19
- gem 'rack-test'
20
- gem 'rspec', '>= 2.1.0'
21
- gem 'cucumber', '>= 0.8.5'
22
- end
3
+ gemspec
@@ -1,64 +1,51 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ grape (0.1.4)
5
+ multi_json
6
+ multi_xml
7
+ rack
8
+ rack-jsonp
9
+ rack-mount
10
+
1
11
  GEM
2
12
  remote: http://rubygems.org/
3
13
  specs:
4
- builder (2.1.2)
5
- cucumber (0.8.5)
6
- builder (~> 2.1.2)
7
- diff-lcs (~> 1.1.2)
8
- gherkin (~> 2.1.4)
9
- json_pure (~> 1.4.3)
10
- term-ansicolor (~> 1.0.4)
11
14
  diff-lcs (1.1.2)
12
- gemcutter (0.6.1)
13
- gherkin (2.1.5)
14
- trollop (~> 1.16.2)
15
- git (1.2.5)
16
- jeweler (1.4.0)
17
- gemcutter (>= 0.1.0)
18
- git (>= 1.2.5)
19
- rubyforge (>= 2.0.0)
20
- json (1.4.6)
21
15
  json_pure (1.4.3)
22
16
  maruku (0.6.0)
23
17
  syntax (>= 1.0.0)
24
- multi_json (0.0.4)
25
- multi_xml (0.0.1)
18
+ mg (0.0.8)
19
+ rake
20
+ multi_json (0.0.5)
21
+ multi_xml (0.2.2)
26
22
  rack (1.2.1)
27
- rack-jsonp (1.0.0)
28
- rack-mount (0.6.13)
23
+ rack-jsonp (1.1.0)
24
+ rack
25
+ rack-mount (0.7.1)
29
26
  rack (>= 1.0.0)
30
27
  rack-test (0.5.4)
31
28
  rack (>= 1.0)
32
29
  rake (0.8.7)
33
- rspec (2.1.0)
34
- rspec-core (~> 2.1.0)
35
- rspec-expectations (~> 2.1.0)
36
- rspec-mocks (~> 2.1.0)
37
- rspec-core (2.1.0)
38
- rspec-expectations (2.1.0)
30
+ rspec (2.5.0)
31
+ rspec-core (~> 2.5.0)
32
+ rspec-expectations (~> 2.5.0)
33
+ rspec-mocks (~> 2.5.0)
34
+ rspec-core (2.5.1)
35
+ rspec-expectations (2.5.0)
39
36
  diff-lcs (~> 1.1.2)
40
- rspec-mocks (2.1.0)
41
- rubyforge (2.0.4)
42
- json_pure (>= 1.1.7)
37
+ rspec-mocks (2.5.0)
43
38
  syntax (1.0.0)
44
- term-ansicolor (1.0.5)
45
- trollop (1.16.2)
46
39
  yard (0.6.1)
47
40
 
48
41
  PLATFORMS
49
42
  ruby
50
43
 
51
44
  DEPENDENCIES
52
- cucumber (>= 0.8.5)
53
- jeweler
54
- json
45
+ grape!
46
+ json_pure
55
47
  maruku
56
- multi_json
57
- multi_xml
58
- rack
59
- rack-jsonp
60
- rack-mount (~> 0.6.13)
48
+ mg
61
49
  rack-test
62
- rake
63
- rspec (>= 2.1.0)
50
+ rspec (~> 2.5.0)
64
51
  yard
data/Rakefile CHANGED
@@ -1,28 +1,9 @@
1
1
  require 'rubygems'
2
2
  require 'bundler'
3
-
4
3
  Bundler.setup :default, :test, :development
5
4
 
6
- def version
7
- @version ||= open('VERSION').read.trim
8
- end
9
-
10
- begin
11
- require 'jeweler'
12
- Jeweler::Tasks.new do |gem|
13
- gem.name = "grape"
14
- gem.summary = %Q{A Ruby framework for rapid API development.}
15
- gem.description = %Q{A Ruby framework for rapid API development with great conventions.}
16
- gem.email = "michael@intridea.com"
17
- gem.homepage = "http://github.com/intridea/grape"
18
- gem.authors = ["Michael Bleigh"]
19
- gem.add_bundler_dependencies
20
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
21
- end
22
- Jeweler::GemcutterTasks.new
23
- rescue LoadError
24
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
25
- end
5
+ require 'mg'
6
+ MG.new('grape.gemspec')
26
7
 
27
8
  require 'rspec/core/rake_task'
28
9
  RSpec::Core::RakeTask.new(:spec) do |spec|
@@ -34,7 +15,7 @@ RSpec::Core::RakeTask.new(:rcov) do |spec|
34
15
  spec.rcov = true
35
16
  end
36
17
 
37
- task :spec => :check_dependencies
18
+ task :spec
38
19
  task :default => :spec
39
20
 
40
21
  begin
@@ -67,4 +48,4 @@ begin
67
48
  end
68
49
  rescue LoadError
69
50
  puts "You need to install YARD."
70
- end
51
+ end
@@ -1,212 +1,33 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+ require "grape/version"
5
3
 
6
4
  Gem::Specification.new do |s|
7
- s.name = %q{grape}
8
- s.version = "0.1.3"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Michael Bleigh"]
12
- s.date = %q{2011-01-10}
5
+ s.name = "grape"
6
+ s.version = Grape::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Michael Bleigh"]
9
+ s.email = ["michael@intridea.com"]
10
+ s.homepage = "https://github.com/intridea/grape"
11
+ s.summary = %q{A simple Ruby framework for building REST-like APIs.}
13
12
  s.description = %q{A Ruby framework for rapid API development with great conventions.}
14
- s.email = %q{michael@intridea.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.markdown"
18
- ]
19
- s.files = [
20
- ".document",
21
- ".gitignore",
22
- ".rspec",
23
- ".yardoc/checksums",
24
- ".yardoc/objects/Grape.dat",
25
- ".yardoc/objects/Grape/API.dat",
26
- ".yardoc/objects/Grape/API/auth_c.dat",
27
- ".yardoc/objects/Grape/API/build_endpoint_c.dat",
28
- ".yardoc/objects/Grape/API/call_c.dat",
29
- ".yardoc/objects/Grape/API/compile_path_c.dat",
30
- ".yardoc/objects/Grape/API/default_format_c.dat",
31
- ".yardoc/objects/Grape/API/delete_c.dat",
32
- ".yardoc/objects/Grape/API/get_c.dat",
33
- ".yardoc/objects/Grape/API/group_c.dat",
34
- ".yardoc/objects/Grape/API/head_c.dat",
35
- ".yardoc/objects/Grape/API/helpers_c.dat",
36
- ".yardoc/objects/Grape/API/http_basic_c.dat",
37
- ".yardoc/objects/Grape/API/inherited_c.dat",
38
- ".yardoc/objects/Grape/API/logger_c.dat",
39
- ".yardoc/objects/Grape/API/namespace_c.dat",
40
- ".yardoc/objects/Grape/API/nest_c.dat",
41
- ".yardoc/objects/Grape/API/post_c.dat",
42
- ".yardoc/objects/Grape/API/prefix_c.dat",
43
- ".yardoc/objects/Grape/API/put_c.dat",
44
- ".yardoc/objects/Grape/API/reset_21_c.dat",
45
- ".yardoc/objects/Grape/API/resource_c.dat",
46
- ".yardoc/objects/Grape/API/resources_c.dat",
47
- ".yardoc/objects/Grape/API/route_c.dat",
48
- ".yardoc/objects/Grape/API/route_set_c.dat",
49
- ".yardoc/objects/Grape/API/scope_c.dat",
50
- ".yardoc/objects/Grape/API/set_c.dat",
51
- ".yardoc/objects/Grape/API/settings_c.dat",
52
- ".yardoc/objects/Grape/API/settings_stack_c.dat",
53
- ".yardoc/objects/Grape/API/version_c.dat",
54
- ".yardoc/objects/Grape/Endpoint.dat",
55
- ".yardoc/objects/Grape/Endpoint/block_3D_c.dat",
56
- ".yardoc/objects/Grape/Endpoint/block_c.dat",
57
- ".yardoc/objects/Grape/Endpoint/call_c.dat",
58
- ".yardoc/objects/Grape/Endpoint/call_i.dat",
59
- ".yardoc/objects/Grape/Endpoint/env_i.dat",
60
- ".yardoc/objects/Grape/Endpoint/error_21_i.dat",
61
- ".yardoc/objects/Grape/Endpoint/generate_c.dat",
62
- ".yardoc/objects/Grape/Endpoint/header_i.dat",
63
- ".yardoc/objects/Grape/Endpoint/params_i.dat",
64
- ".yardoc/objects/Grape/Endpoint/request_i.dat",
65
- ".yardoc/objects/Grape/Endpoint/status_i.dat",
66
- ".yardoc/objects/Grape/Endpoint/version_i.dat",
67
- ".yardoc/objects/Grape/Middleware.dat",
68
- ".yardoc/objects/Grape/Middleware/Auth.dat",
69
- ".yardoc/objects/Grape/Middleware/Auth/Basic.dat",
70
- ".yardoc/objects/Grape/Middleware/Auth/Basic/authenticator_i.dat",
71
- ".yardoc/objects/Grape/Middleware/Auth/Basic/basic_request_i.dat",
72
- ".yardoc/objects/Grape/Middleware/Auth/Basic/before_i.dat",
73
- ".yardoc/objects/Grape/Middleware/Auth/Basic/credentials_i.dat",
74
- ".yardoc/objects/Grape/Middleware/Auth/Basic/initialize_i.dat",
75
- ".yardoc/objects/Grape/Middleware/Auth/OAuth2.dat",
76
- ".yardoc/objects/Grape/Middleware/Auth/OAuth2/before_i.dat",
77
- ".yardoc/objects/Grape/Middleware/Auth/OAuth2/default_options_i.dat",
78
- ".yardoc/objects/Grape/Middleware/Auth/OAuth2/error_out_i.dat",
79
- ".yardoc/objects/Grape/Middleware/Auth/OAuth2/parse_authorization_header_i.dat",
80
- ".yardoc/objects/Grape/Middleware/Auth/OAuth2/token_class_i.dat",
81
- ".yardoc/objects/Grape/Middleware/Auth/OAuth2/verify_token_i.dat",
82
- ".yardoc/objects/Grape/Middleware/Base.dat",
83
- ".yardoc/objects/Grape/Middleware/Base/after_i.dat",
84
- ".yardoc/objects/Grape/Middleware/Base/app_i.dat",
85
- ".yardoc/objects/Grape/Middleware/Base/before_i.dat",
86
- ".yardoc/objects/Grape/Middleware/Base/call_21_i.dat",
87
- ".yardoc/objects/Grape/Middleware/Base/call_i.dat",
88
- ".yardoc/objects/Grape/Middleware/Base/default_options_i.dat",
89
- ".yardoc/objects/Grape/Middleware/Base/env_i.dat",
90
- ".yardoc/objects/Grape/Middleware/Base/initialize_i.dat",
91
- ".yardoc/objects/Grape/Middleware/Base/options_i.dat",
92
- ".yardoc/objects/Grape/Middleware/Base/request_i.dat",
93
- ".yardoc/objects/Grape/Middleware/Base/response_i.dat",
94
- ".yardoc/objects/Grape/Middleware/Error.dat",
95
- ".yardoc/objects/Grape/Middleware/Error/call_21_i.dat",
96
- ".yardoc/objects/Grape/Middleware/Error/error_response_i.dat",
97
- ".yardoc/objects/Grape/Middleware/Formatter.dat",
98
- ".yardoc/objects/Grape/Middleware/Formatter/CONTENT_TYPES.dat",
99
- ".yardoc/objects/Grape/Middleware/Formatter/after_i.dat",
100
- ".yardoc/objects/Grape/Middleware/Formatter/before_i.dat",
101
- ".yardoc/objects/Grape/Middleware/Formatter/content_types_i.dat",
102
- ".yardoc/objects/Grape/Middleware/Formatter/default_options_i.dat",
103
- ".yardoc/objects/Grape/Middleware/Formatter/encode_json_i.dat",
104
- ".yardoc/objects/Grape/Middleware/Formatter/encode_txt_i.dat",
105
- ".yardoc/objects/Grape/Middleware/Formatter/format_from_extension_i.dat",
106
- ".yardoc/objects/Grape/Middleware/Formatter/format_from_header_i.dat",
107
- ".yardoc/objects/Grape/Middleware/Formatter/headers_i.dat",
108
- ".yardoc/objects/Grape/Middleware/Formatter/mime_array_i.dat",
109
- ".yardoc/objects/Grape/Middleware/Formatter/mime_types_i.dat",
110
- ".yardoc/objects/Grape/Middleware/Prefixer.dat",
111
- ".yardoc/objects/Grape/Middleware/Prefixer/before_i.dat",
112
- ".yardoc/objects/Grape/Middleware/Prefixer/prefix_i.dat",
113
- ".yardoc/objects/Grape/Middleware/Versioner.dat",
114
- ".yardoc/objects/Grape/Middleware/Versioner/before_i.dat",
115
- ".yardoc/objects/Grape/Middleware/Versioner/default_options_i.dat",
116
- ".yardoc/objects/Grape/MiddlewareStack.dat",
117
- ".yardoc/objects/Grape/MiddlewareStack/initialize_i.dat",
118
- ".yardoc/objects/Grape/MiddlewareStack/stack_i.dat",
119
- ".yardoc/objects/Grape/MiddlewareStack/to_app_i.dat",
120
- ".yardoc/objects/Grape/MiddlewareStack/use_i.dat",
121
- ".yardoc/objects/root.dat",
122
- ".yardoc/proxy_types",
123
- "Gemfile",
124
- "Gemfile.lock",
125
- "LICENSE",
126
- "README.markdown",
127
- "Rakefile",
128
- "VERSION",
129
- "autotest/discover.rb",
130
- "grape.gemspec",
131
- "lib/grape.rb",
132
- "lib/grape/api.rb",
133
- "lib/grape/endpoint.rb",
134
- "lib/grape/middleware/auth/basic.rb",
135
- "lib/grape/middleware/auth/oauth2.rb",
136
- "lib/grape/middleware/base.rb",
137
- "lib/grape/middleware/error.rb",
138
- "lib/grape/middleware/formatter.rb",
139
- "lib/grape/middleware/prefixer.rb",
140
- "lib/grape/middleware/versioner.rb",
141
- "spec/grape/api_spec.rb",
142
- "spec/grape/endpoint_spec.rb",
143
- "spec/grape/middleware/auth/basic_spec.rb",
144
- "spec/grape/middleware/auth/oauth2_spec.rb",
145
- "spec/grape/middleware/base_spec.rb",
146
- "spec/grape/middleware/error_spec.rb",
147
- "spec/grape/middleware/formatter_spec.rb",
148
- "spec/grape/middleware/prefixer_spec.rb",
149
- "spec/grape/middleware/versioner_spec.rb",
150
- "spec/grape_spec.rb",
151
- "spec/spec_helper.rb"
152
- ]
153
- s.homepage = %q{http://github.com/intridea/grape}
154
- s.rdoc_options = ["--charset=UTF-8"]
155
- s.require_paths = ["lib"]
156
- s.rubygems_version = %q{1.3.7}
157
- s.summary = %q{A Ruby framework for rapid API development.}
158
- s.test_files = [
159
- "spec/grape/api_spec.rb",
160
- "spec/grape/endpoint_spec.rb",
161
- "spec/grape/middleware/auth/basic_spec.rb",
162
- "spec/grape/middleware/auth/oauth2_spec.rb",
163
- "spec/grape/middleware/base_spec.rb",
164
- "spec/grape/middleware/error_spec.rb",
165
- "spec/grape/middleware/formatter_spec.rb",
166
- "spec/grape/middleware/prefixer_spec.rb",
167
- "spec/grape/middleware/versioner_spec.rb",
168
- "spec/grape_spec.rb",
169
- "spec/spec_helper.rb"
170
- ]
171
13
 
172
- if s.respond_to? :specification_version then
173
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
174
- s.specification_version = 3
14
+ s.rubyforge_project = "grape"
175
15
 
176
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
177
- s.add_runtime_dependency(%q<rack>, [">= 0"])
178
- s.add_runtime_dependency(%q<rack-mount>, ["~> 0.6.13"])
179
- s.add_runtime_dependency(%q<rack-jsonp>, [">= 0"])
180
- s.add_runtime_dependency(%q<json>, [">= 0"])
181
- s.add_runtime_dependency(%q<multi_json>, [">= 0"])
182
- s.add_runtime_dependency(%q<multi_xml>, [">= 0"])
183
- s.add_development_dependency(%q<rake>, [">= 0"])
184
- s.add_development_dependency(%q<jeweler>, [">= 0"])
185
- s.add_development_dependency(%q<maruku>, [">= 0"])
186
- s.add_development_dependency(%q<yard>, [">= 0"])
187
- else
188
- s.add_dependency(%q<rack>, [">= 0"])
189
- s.add_dependency(%q<rack-mount>, ["~> 0.6.13"])
190
- s.add_dependency(%q<rack-jsonp>, [">= 0"])
191
- s.add_dependency(%q<json>, [">= 0"])
192
- s.add_dependency(%q<multi_json>, [">= 0"])
193
- s.add_dependency(%q<multi_xml>, [">= 0"])
194
- s.add_dependency(%q<rake>, [">= 0"])
195
- s.add_dependency(%q<jeweler>, [">= 0"])
196
- s.add_dependency(%q<maruku>, [">= 0"])
197
- s.add_dependency(%q<yard>, [">= 0"])
198
- end
199
- else
200
- s.add_dependency(%q<rack>, [">= 0"])
201
- s.add_dependency(%q<rack-mount>, ["~> 0.6.13"])
202
- s.add_dependency(%q<rack-jsonp>, [">= 0"])
203
- s.add_dependency(%q<json>, [">= 0"])
204
- s.add_dependency(%q<multi_json>, [">= 0"])
205
- s.add_dependency(%q<multi_xml>, [">= 0"])
206
- s.add_dependency(%q<rake>, [">= 0"])
207
- s.add_dependency(%q<jeweler>, [">= 0"])
208
- s.add_dependency(%q<maruku>, [">= 0"])
209
- s.add_dependency(%q<yard>, [">= 0"])
210
- end
211
- end
16
+ s.add_runtime_dependency 'rack'
17
+ s.add_runtime_dependency 'rack-mount'
18
+ s.add_runtime_dependency 'rack-jsonp'
19
+ s.add_runtime_dependency 'multi_json'
20
+ s.add_runtime_dependency 'multi_xml'
212
21
 
22
+ s.add_development_dependency 'mg'
23
+ s.add_development_dependency 'maruku'
24
+ s.add_development_dependency 'yard'
25
+ s.add_development_dependency 'rack-test'
26
+ s.add_development_dependency 'rspec', '~> 2.5.0'
27
+ s.add_development_dependency 'json_pure'
28
+
29
+ s.files = `git ls-files`.split("\n")
30
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
31
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
32
+ s.require_paths = ["lib"]
33
+ end
@@ -19,4 +19,6 @@ module Grape
19
19
  autoload :Basic, 'grape/middleware/auth/basic'
20
20
  end
21
21
  end
22
- end
22
+ end
23
+
24
+ require 'grape/version'
@@ -62,11 +62,12 @@ module Grape
62
62
  # end
63
63
  #
64
64
  # version 'v1' do
65
- # get '/legacy' do
65
+ # get '/main' do
66
66
  # {:legacy => 'data'}
67
67
  # end
68
68
  # end
69
69
  # end
70
+ #
70
71
  def version(*new_versions, &block)
71
72
  new_versions.any? ? nest(block){ set(:version, new_versions) } : settings[:version]
72
73
  end
@@ -139,10 +140,12 @@ module Grape
139
140
  paths = ['/'] if paths == []
140
141
  paths = Array(paths)
141
142
  endpoint = build_endpoint(&block)
143
+ options = {}
144
+ options[:version] = /#{version.join('|')}/ if version
142
145
 
143
146
  methods.each do |method|
144
147
  paths.each do |path|
145
- path = Rack::Mount::Strexp.compile(compile_path(path))
148
+ path = Rack::Mount::Strexp.compile(compile_path(path), options, ['/'], true)
146
149
  route_set.add_route(endpoint,
147
150
  :path_info => path,
148
151
  :request_method => (method.to_s.upcase unless method == :any)
@@ -11,10 +11,15 @@ module Grape
11
11
  :rss => 'application/rss+xml',
12
12
  :txt => 'text/plain'
13
13
  }
14
+ FORMATTERS = {
15
+ :json => :encode_json,
16
+ :txt => :encode_txt,
17
+ }
14
18
 
15
19
  def default_options
16
20
  {
17
21
  :default_format => :txt,
22
+ :formatters => {},
18
23
  :content_types => {}
19
24
  }
20
25
  end
@@ -22,6 +27,10 @@ module Grape
22
27
  def content_types
23
28
  CONTENT_TYPES.merge(options[:content_types])
24
29
  end
30
+
31
+ def formatters
32
+ FORMATTERS.merge(options[:formatters])
33
+ end
25
34
 
26
35
  def mime_types
27
36
  content_types.invert
@@ -75,18 +84,25 @@ module Grape
75
84
 
76
85
  def after
77
86
  status, headers, bodies = *@app_response
78
- bodymap = []
79
- bodies.each do |body|
80
- bodymap << case env['api.format']
81
- when :json
82
- encode_json(body)
83
- when :txt
84
- encode_txt(body)
85
- end
87
+ formatter = formatter_for env['api.format']
88
+ bodymap = bodies.collect do |body|
89
+ formatter.call(body)
86
90
  end
87
- headers['Content-Type'] = 'application/json'
91
+ headers['Content-Type'] = content_types[env['api.format']]
88
92
  Rack::Response.new(bodymap, status, headers).to_a
89
93
  end
94
+
95
+ def formatter_for(api_format)
96
+ spec = formatters[api_format]
97
+ case spec
98
+ when nil
99
+ lambda { |obj| obj }
100
+ when Symbol
101
+ method(spec)
102
+ else
103
+ spec
104
+ end
105
+ end
90
106
 
91
107
  def encode_json(object)
92
108
  if object.respond_to? :serializable_hash
@@ -103,4 +119,4 @@ module Grape
103
119
  end
104
120
  end
105
121
  end
106
- end
122
+ end
@@ -0,0 +1,3 @@
1
+ module Grape
2
+ VERSION = '0.1.4'
3
+ end
@@ -14,10 +14,10 @@ describe Grape::API do
14
14
  end
15
15
 
16
16
  get 'awesome/sauce/hello'
17
- last_response.body.should == "Hello there."
17
+ last_response.body.should eql "Hello there."
18
18
 
19
19
  get '/hello'
20
- last_response.status.should == 404
20
+ last_response.status.should eql 404
21
21
  end
22
22
  end
23
23
 
@@ -29,7 +29,7 @@ describe Grape::API do
29
29
  end
30
30
 
31
31
  get '/v1/hello'
32
- last_response.body.should == "Version: v1"
32
+ last_response.body.should eql "Version: v1"
33
33
  end
34
34
 
35
35
  it 'should add the prefix before the API version' do
@@ -40,7 +40,7 @@ describe Grape::API do
40
40
  end
41
41
 
42
42
  get '/api/v1/hello'
43
- last_response.body.should == "Version: v1"
43
+ last_response.body.should eql "Version: v1"
44
44
  end
45
45
 
46
46
  it 'should be able to specify version as a nesting' do
@@ -56,13 +56,13 @@ describe Grape::API do
56
56
  end
57
57
 
58
58
  get '/v1/awesome'
59
- last_response.status.should == 404
59
+ last_response.status.should eql 404
60
60
  get '/v2/awesome'
61
- last_response.status.should == 200
61
+ last_response.status.should eql 200
62
62
  get '/v1/legacy'
63
- last_response.status.should == 200
63
+ last_response.status.should eql 200
64
64
  get '/v2/legacy'
65
- last_response.status.should == 404
65
+ last_response.status.should eql 404
66
66
  end
67
67
 
68
68
  it 'should be able to specify multiple versions' do
@@ -72,12 +72,33 @@ describe Grape::API do
72
72
  end
73
73
 
74
74
  get '/v1/awesome'
75
- last_response.status.should == 200
75
+ last_response.status.should eql 200
76
76
  get '/v2/awesome'
77
- last_response.status.should == 200
77
+ last_response.status.should eql 200
78
78
  get '/v3/awesome'
79
- last_response.status.should == 404
79
+ last_response.status.should eql 404
80
80
  end
81
+
82
+ it 'should allow the same endpoint to be implemented for different versions' do
83
+ subject.version 'v2'
84
+ subject.get 'version' do
85
+ request.env['api.version']
86
+ end
87
+
88
+ subject.version 'v1' do
89
+ get 'version' do
90
+ "version " + request.env['api.version']
91
+ end
92
+ end
93
+
94
+ get '/v2/version'
95
+ last_response.status.should == 200
96
+ last_response.body.should == 'v2'
97
+ get '/v1/version'
98
+ last_response.status.should == 200
99
+ last_response.body.should == 'version v1'
100
+ end
101
+
81
102
  end
82
103
 
83
104
  describe '.namespace' do
@@ -125,7 +146,7 @@ describe Grape::API do
125
146
  %w(group resource resources).each do |als|
126
147
  it "`.#{als}` should be an alias" do
127
148
  subject.send(als, :awesome) do
128
- namespace.should == "/awesome"
149
+ namespace.should == "/awesome"
129
150
  end
130
151
  end
131
152
  end
@@ -144,9 +165,9 @@ describe Grape::API do
144
165
  end
145
166
 
146
167
  get '/votes'
147
- last_response.body.should == 'Votes'
168
+ last_response.body.should eql 'Votes'
148
169
  post '/votes'
149
- last_response.body.should == 'Created a Vote'
170
+ last_response.body.should eql 'Created a Vote'
150
171
  end
151
172
 
152
173
  it 'should allow for multiple paths' do
@@ -155,9 +176,9 @@ describe Grape::API do
155
176
  end
156
177
 
157
178
  get '/abc'
158
- last_response.body.should == 'foo'
179
+ last_response.body.should eql 'foo'
159
180
  get '/def'
160
- last_response.body.should == 'foo'
181
+ last_response.body.should eql 'foo'
161
182
  end
162
183
 
163
184
  it 'should allow for format' do
@@ -166,7 +187,7 @@ describe Grape::API do
166
187
  end
167
188
 
168
189
  get '/abc.json'
169
- last_response.body.should == '"json"'
190
+ last_response.body.should eql '"json"'
170
191
  end
171
192
 
172
193
  it 'should allow for format in namespace with no path' do
@@ -177,7 +198,7 @@ describe Grape::API do
177
198
  end
178
199
 
179
200
  get '/abc.json'
180
- last_response.body.should == '"json"'
201
+ last_response.body.should eql '"json"'
181
202
  end
182
203
 
183
204
  it 'should allow for multiple verbs' do
@@ -186,9 +207,38 @@ describe Grape::API do
186
207
  end
187
208
 
188
209
  get '/abc'
189
- last_response.body.should == 'hiya'
210
+ last_response.body.should eql 'hiya'
190
211
  post '/abc'
191
- last_response.body.should == 'hiya'
212
+ last_response.body.should eql 'hiya'
213
+ end
214
+
215
+ it 'should allow for multipart paths' do
216
+
217
+
218
+ subject.route([:get, :post], '/:id/first') do
219
+ "first"
220
+ end
221
+
222
+
223
+ subject.route([:get, :post], '/:id') do
224
+ "ola"
225
+ end
226
+ subject.route([:get, :post], '/:id/first/second') do
227
+ "second"
228
+ end
229
+
230
+
231
+ get '/1'
232
+ last_response.body.should eql 'ola'
233
+ post '/1'
234
+ last_response.body.should eql 'ola'
235
+ get '/1/first'
236
+ last_response.body.should eql 'first'
237
+ post '/1/first'
238
+ last_response.body.should eql 'first'
239
+ get '/1/first/second'
240
+ last_response.body.should eql 'second'
241
+
192
242
  end
193
243
 
194
244
  it 'should allow for :any as a verb' do
@@ -198,7 +248,7 @@ describe Grape::API do
198
248
 
199
249
  %w(get post put delete).each do |m|
200
250
  send(m, '/abc')
201
- last_response.body.should == 'lol'
251
+ last_response.body.should eql 'lol'
202
252
  end
203
253
  end
204
254
 
@@ -209,10 +259,10 @@ describe Grape::API do
209
259
  verb
210
260
  end
211
261
  send(verb, '/example')
212
- last_response.body.should == verb
262
+ last_response.body.should eql verb
213
263
  # Call it with a method other than the properly constrained one.
214
264
  send(verbs[(verbs.index(verb) + 1) % verbs.size], '/example')
215
- last_response.status.should == 404
265
+ last_response.status.should eql 404
216
266
  end
217
267
  end
218
268
 
@@ -222,8 +272,8 @@ describe Grape::API do
222
272
  end
223
273
 
224
274
  post '/example'
225
- last_response.status.should == 201
226
- last_response.body.should == 'Created'
275
+ last_response.status.should eql 201
276
+ last_response.body.should eql 'Created'
227
277
  end
228
278
  end
229
279
 
@@ -244,7 +294,7 @@ describe Grape::API do
244
294
  describe '.middleware' do
245
295
  it 'should include middleware arguments from settings' do
246
296
  subject.stub!(:settings_stack).and_return [{:middleware => [[PhonyMiddleware, 'abc', 123]]}]
247
- subject.middleware.should == [[PhonyMiddleware, 'abc', 123]]
297
+ subject.middleware.should eql [[PhonyMiddleware, 'abc', 123]]
248
298
  end
249
299
 
250
300
  it 'should include all middleware from stacked settings' do
@@ -253,7 +303,7 @@ describe Grape::API do
253
303
  {:middleware => [[PhonyMiddleware, 'foo']]}
254
304
  ]
255
305
 
256
- subject.middleware.should == [
306
+ subject.middleware.should eql [
257
307
  [PhonyMiddleware, 123],
258
308
  [PhonyMiddleware, 'abc'],
259
309
  [PhonyMiddleware, 'foo']
@@ -264,7 +314,7 @@ describe Grape::API do
264
314
  describe '.use' do
265
315
  it 'should add middleware' do
266
316
  subject.use PhonyMiddleware, 123
267
- subject.middleware.should == [[PhonyMiddleware, 123]]
317
+ subject.middleware.should eql [[PhonyMiddleware, 123]]
268
318
  end
269
319
 
270
320
  it 'should not show up outside the namespace' do
@@ -274,7 +324,7 @@ describe Grape::API do
274
324
  middleware.should == [[PhonyMiddleware, 123],[PhonyMiddleware, 'abc']]
275
325
  end
276
326
 
277
- subject.middleware.should == [[PhonyMiddleware, 123]]
327
+ subject.middleware.should eql [[PhonyMiddleware, 123]]
278
328
  end
279
329
 
280
330
  it 'should actually call the middleware' do
@@ -284,7 +334,7 @@ describe Grape::API do
284
334
  end
285
335
 
286
336
  get '/'
287
- last_response.body.should == 'hello'
337
+ last_response.body.should eql 'hello'
288
338
  end
289
339
  end
290
340
  end
@@ -295,9 +345,9 @@ describe Grape::API do
295
345
  end
296
346
  subject.get(:hello){ "Hello, world."}
297
347
  get '/hello'
298
- last_response.status.should == 401
348
+ last_response.status.should eql 401
299
349
  get '/hello', {}, 'HTTP_AUTHORIZATION' => encode_basic('allow','whatever')
300
- last_response.status.should == 200
350
+ last_response.status.should eql 200
301
351
  end
302
352
 
303
353
  it 'should be scopable' do
@@ -311,9 +361,9 @@ describe Grape::API do
311
361
  end
312
362
 
313
363
  get '/hello'
314
- last_response.status.should == 200
364
+ last_response.status.should eql 200
315
365
  get '/admin/hello'
316
- last_response.status.should == 401
366
+ last_response.status.should eql 401
317
367
  end
318
368
 
319
369
  it 'should be callable via .auth as well' do
@@ -323,9 +373,9 @@ describe Grape::API do
323
373
 
324
374
  subject.get(:hello){ "Hello, world."}
325
375
  get '/hello'
326
- last_response.status.should == 401
376
+ last_response.status.should eql 401
327
377
  get '/hello', {}, 'HTTP_AUTHORIZATION' => encode_basic('allow','whatever')
328
- last_response.status.should == 200
378
+ last_response.status.should eql 200
329
379
  end
330
380
  end
331
381
 
@@ -342,7 +392,7 @@ describe Grape::API do
342
392
  end
343
393
 
344
394
  get '/howdy'
345
- last_response.body.should == 'Hello, world.'
395
+ last_response.body.should eql 'Hello, world.'
346
396
  end
347
397
 
348
398
  it 'should be scopable' do
@@ -369,9 +419,9 @@ describe Grape::API do
369
419
  end
370
420
 
371
421
  get '/generic'
372
- last_response.body.should == 'always there:false'
422
+ last_response.body.should eql 'always there:false'
373
423
  get '/admin/secret'
374
- last_response.body.should == 'always there:only in admin'
424
+ last_response.body.should eql 'always there:only in admin'
375
425
  end
376
426
 
377
427
  it 'should be reopenable' do
@@ -412,13 +462,13 @@ describe Grape::API do
412
462
  end
413
463
 
414
464
  get '/v2/abc'
415
- last_response.status.should == 404
465
+ last_response.status.should eql 404
416
466
  get '/v1/abc'
417
- last_response.status.should == 200
467
+ last_response.status.should eql 200
418
468
  get '/v1/def'
419
- last_response.status.should == 404
469
+ last_response.status.should eql 404
420
470
  get '/v2/def'
421
- last_response.status.should == 200
471
+ last_response.status.should eql 200
422
472
  end
423
473
  end
424
474
  end
@@ -84,4 +84,43 @@ describe Grape::Middleware::Formatter do
84
84
  subject.env['api.format'].should == :json
85
85
  end
86
86
  end
87
- end
87
+
88
+ context 'Content-type' do
89
+ it 'should be set for json' do
90
+ _, headers, _ = subject.call({'PATH_INFO' => '/info.json'})
91
+ headers['Content-type'].should == 'application/json'
92
+ end
93
+ it 'should be set for xml' do
94
+ _, headers, _ = subject.call({'PATH_INFO' => '/info.xml'})
95
+ headers['Content-type'].should == 'application/xml'
96
+ end
97
+ it 'should be set for txt' do
98
+ _, headers, _ = subject.call({'PATH_INFO' => '/info.txt'})
99
+ headers['Content-type'].should == 'text/plain'
100
+ end
101
+ it 'should be set for custom' do
102
+ subject.options[:content_types][:custom] = 'application/x-custom'
103
+ _, headers, _ = subject.call({'PATH_INFO' => '/info.custom'})
104
+ headers['Content-type'].should == 'application/x-custom'
105
+ end
106
+ end
107
+
108
+ context 'Format' do
109
+ it 'should use custom formatter' do
110
+ subject.options[:content_types][:custom] = "don't care"
111
+ subject.options[:formatters][:custom] = lambda { |obj| 'CUSTOM FORMAT' }
112
+ _, _, body = subject.call({'PATH_INFO' => '/info.custom'})
113
+ body.body.should == ['CUSTOM FORMAT']
114
+ end
115
+ it 'should use default json formatter' do
116
+ @body = 'blah'
117
+ _, _, body = subject.call({'PATH_INFO' => '/info.json'})
118
+ body.body.should == ['"blah"']
119
+ end
120
+ it 'should use custom json formatter' do
121
+ subject.options[:formatters][:json] = lambda { |obj| 'CUSTOM JSON FORMAT' }
122
+ _, _, body = subject.call({'PATH_INFO' => '/info.json'})
123
+ body.body.should == ['CUSTOM JSON FORMAT']
124
+ end
125
+ end
126
+ end
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- - 3
9
- version: 0.1.3
4
+ prerelease:
5
+ version: 0.1.4
10
6
  platform: ruby
11
7
  authors:
12
8
  - Michael Bleigh
@@ -14,7 +10,7 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2011-01-10 00:00:00 -06:00
13
+ date: 2011-04-08 00:00:00 -05:00
18
14
  default_executable:
19
15
  dependencies:
20
16
  - !ruby/object:Gem::Dependency
@@ -24,8 +20,6 @@ dependencies:
24
20
  requirements:
25
21
  - - ">="
26
22
  - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
23
  version: "0"
30
24
  type: :runtime
31
25
  prerelease: false
@@ -35,13 +29,9 @@ dependencies:
35
29
  requirement: &id002 !ruby/object:Gem::Requirement
36
30
  none: false
37
31
  requirements:
38
- - - ~>
32
+ - - ">="
39
33
  - !ruby/object:Gem::Version
40
- segments:
41
- - 0
42
- - 6
43
- - 13
44
- version: 0.6.13
34
+ version: "0"
45
35
  type: :runtime
46
36
  prerelease: false
47
37
  version_requirements: *id002
@@ -52,116 +42,112 @@ dependencies:
52
42
  requirements:
53
43
  - - ">="
54
44
  - !ruby/object:Gem::Version
55
- segments:
56
- - 0
57
45
  version: "0"
58
46
  type: :runtime
59
47
  prerelease: false
60
48
  version_requirements: *id003
61
49
  - !ruby/object:Gem::Dependency
62
- name: json
50
+ name: multi_json
63
51
  requirement: &id004 !ruby/object:Gem::Requirement
64
52
  none: false
65
53
  requirements:
66
54
  - - ">="
67
55
  - !ruby/object:Gem::Version
68
- segments:
69
- - 0
70
56
  version: "0"
71
57
  type: :runtime
72
58
  prerelease: false
73
59
  version_requirements: *id004
74
60
  - !ruby/object:Gem::Dependency
75
- name: multi_json
61
+ name: multi_xml
76
62
  requirement: &id005 !ruby/object:Gem::Requirement
77
63
  none: false
78
64
  requirements:
79
65
  - - ">="
80
66
  - !ruby/object:Gem::Version
81
- segments:
82
- - 0
83
67
  version: "0"
84
68
  type: :runtime
85
69
  prerelease: false
86
70
  version_requirements: *id005
87
71
  - !ruby/object:Gem::Dependency
88
- name: multi_xml
72
+ name: mg
89
73
  requirement: &id006 !ruby/object:Gem::Requirement
90
74
  none: false
91
75
  requirements:
92
76
  - - ">="
93
77
  - !ruby/object:Gem::Version
94
- segments:
95
- - 0
96
78
  version: "0"
97
- type: :runtime
79
+ type: :development
98
80
  prerelease: false
99
81
  version_requirements: *id006
100
82
  - !ruby/object:Gem::Dependency
101
- name: rake
83
+ name: maruku
102
84
  requirement: &id007 !ruby/object:Gem::Requirement
103
85
  none: false
104
86
  requirements:
105
87
  - - ">="
106
88
  - !ruby/object:Gem::Version
107
- segments:
108
- - 0
109
89
  version: "0"
110
90
  type: :development
111
91
  prerelease: false
112
92
  version_requirements: *id007
113
93
  - !ruby/object:Gem::Dependency
114
- name: jeweler
94
+ name: yard
115
95
  requirement: &id008 !ruby/object:Gem::Requirement
116
96
  none: false
117
97
  requirements:
118
98
  - - ">="
119
99
  - !ruby/object:Gem::Version
120
- segments:
121
- - 0
122
100
  version: "0"
123
101
  type: :development
124
102
  prerelease: false
125
103
  version_requirements: *id008
126
104
  - !ruby/object:Gem::Dependency
127
- name: maruku
105
+ name: rack-test
128
106
  requirement: &id009 !ruby/object:Gem::Requirement
129
107
  none: false
130
108
  requirements:
131
109
  - - ">="
132
110
  - !ruby/object:Gem::Version
133
- segments:
134
- - 0
135
111
  version: "0"
136
112
  type: :development
137
113
  prerelease: false
138
114
  version_requirements: *id009
139
115
  - !ruby/object:Gem::Dependency
140
- name: yard
116
+ name: rspec
141
117
  requirement: &id010 !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ~>
121
+ - !ruby/object:Gem::Version
122
+ version: 2.5.0
123
+ type: :development
124
+ prerelease: false
125
+ version_requirements: *id010
126
+ - !ruby/object:Gem::Dependency
127
+ name: json_pure
128
+ requirement: &id011 !ruby/object:Gem::Requirement
142
129
  none: false
143
130
  requirements:
144
131
  - - ">="
145
132
  - !ruby/object:Gem::Version
146
- segments:
147
- - 0
148
133
  version: "0"
149
134
  type: :development
150
135
  prerelease: false
151
- version_requirements: *id010
136
+ version_requirements: *id011
152
137
  description: A Ruby framework for rapid API development with great conventions.
153
- email: michael@intridea.com
138
+ email:
139
+ - michael@intridea.com
154
140
  executables: []
155
141
 
156
142
  extensions: []
157
143
 
158
- extra_rdoc_files:
159
- - LICENSE
160
- - README.markdown
144
+ extra_rdoc_files: []
145
+
161
146
  files:
162
147
  - .document
163
148
  - .gitignore
164
149
  - .rspec
150
+ - .travis.yml
165
151
  - .yardoc/checksums
166
152
  - .yardoc/objects/Grape.dat
167
153
  - .yardoc/objects/Grape/API.dat
@@ -267,7 +253,6 @@ files:
267
253
  - LICENSE
268
254
  - README.markdown
269
255
  - Rakefile
270
- - VERSION
271
256
  - autotest/discover.rb
272
257
  - grape.gemspec
273
258
  - lib/grape.rb
@@ -280,6 +265,7 @@ files:
280
265
  - lib/grape/middleware/formatter.rb
281
266
  - lib/grape/middleware/prefixer.rb
282
267
  - lib/grape/middleware/versioner.rb
268
+ - lib/grape/version.rb
283
269
  - spec/grape/api_spec.rb
284
270
  - spec/grape/endpoint_spec.rb
285
271
  - spec/grape/middleware/auth/basic_spec.rb
@@ -292,12 +278,12 @@ files:
292
278
  - spec/grape_spec.rb
293
279
  - spec/spec_helper.rb
294
280
  has_rdoc: true
295
- homepage: http://github.com/intridea/grape
281
+ homepage: https://github.com/intridea/grape
296
282
  licenses: []
297
283
 
298
284
  post_install_message:
299
- rdoc_options:
300
- - --charset=UTF-8
285
+ rdoc_options: []
286
+
301
287
  require_paths:
302
288
  - lib
303
289
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -305,7 +291,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
305
291
  requirements:
306
292
  - - ">="
307
293
  - !ruby/object:Gem::Version
308
- hash: 3948769819312145241
294
+ hash: -2709592695038958113
309
295
  segments:
310
296
  - 0
311
297
  version: "0"
@@ -314,16 +300,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
314
300
  requirements:
315
301
  - - ">="
316
302
  - !ruby/object:Gem::Version
303
+ hash: -2709592695038958113
317
304
  segments:
318
305
  - 0
319
306
  version: "0"
320
307
  requirements: []
321
308
 
322
- rubyforge_project:
323
- rubygems_version: 1.3.7
309
+ rubyforge_project: grape
310
+ rubygems_version: 1.6.2
324
311
  signing_key:
325
312
  specification_version: 3
326
- summary: A Ruby framework for rapid API development.
313
+ summary: A simple Ruby framework for building REST-like APIs.
327
314
  test_files:
328
315
  - spec/grape/api_spec.rb
329
316
  - spec/grape/endpoint_spec.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.3