api-versions 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changes.md +6 -1
- data/README.md +29 -1
- data/lib/api-versions.rb +1 -1
- data/lib/api-versions/middleware.rb +2 -0
- data/lib/api-versions/version.rb +6 -1
- data/spec/dummy/config/routes.rb +8 -2
- data/spec/middleware_spec.rb +19 -4
- data/spec/routing_spec.rb +6 -0
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76c06f9b24fbbbce7345e61b4cce9a66f955f32a
|
4
|
+
data.tar.gz: d596f61158abb67ba28f5b7200a8f774416bb33d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9243f84c3b74cae3311a3cfd01a6cd63f8d28cf5f2df870aa6c9afd915858cef2bc91d26f1fe79ef1d914cee6a2ddbdfa464a36d4e095f60faa83aecc65e0eac
|
7
|
+
data.tar.gz: 293cb32aaaa8b3b2953c38235778307a88e452ff512fe845ecc05a9270db3e18a9deabd794520bb2bff48f6c47229347ee788f759058a306d4167032a664d3ad
|
data/Changes.md
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
-
# api-versions
|
1
|
+
# api-versions
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/erichmenge/api-versions.png?branch=master)](https://travis-ci.org/erichmenge/api-versions)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/api-versions.png)](http://badge.fury.io/rb/api-versions)
|
2
5
|
|
3
6
|
|
4
7
|
### Requirements
|
@@ -178,3 +181,28 @@ end
|
|
178
181
|
|
179
182
|
So instead of copying your prior version controllers over to the new ones and duplicating all the code in them, you can redefine specific methods,
|
180
183
|
or start from scratch by removing the inheritance.
|
184
|
+
|
185
|
+
## Passing Rails Routing options
|
186
|
+
The api-versions routing DSL will pass any options that are regularly accepted by Rails' own routing DSL. For example, if you are using an api subdomain and don't need your paths prefixed with `/api`, you can override it as you normally would:
|
187
|
+
|
188
|
+
```ruby
|
189
|
+
api vendor_string: 'myvendor', default_version: 1, path: '' do
|
190
|
+
version 1 do
|
191
|
+
cache as: 'v1' do
|
192
|
+
resources :foo
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
```
|
197
|
+
|
198
|
+
Then a `rake routes` would show your desires fulfilled:
|
199
|
+
|
200
|
+
```
|
201
|
+
GET /foo(.:format) api/v1/foo#index
|
202
|
+
POST /foo(.:format) api/v1/foo#create
|
203
|
+
GET /foo/new(.:format) api/v1/foo#new
|
204
|
+
GET /foo/:id/edit(.:format) api/v1/foo#edit
|
205
|
+
GET /foo/:id(.:format) api/v1/foo#show
|
206
|
+
PUT /foo/:id(.:format) api/v2/foo#update
|
207
|
+
DELETE /foo/:id(.:format) api/v2/foo#destroy
|
208
|
+
```
|
data/lib/api-versions.rb
CHANGED
data/lib/api-versions/version.rb
CHANGED
data/spec/dummy/config/routes.rb
CHANGED
@@ -18,7 +18,13 @@ Dummy::Application.routes.draw do
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
|
21
|
+
api vendor_string: 'myvendor', path: '' do
|
22
|
+
version 1 do
|
23
|
+
cache as: 'v1' do
|
24
|
+
resources :baz
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
22
28
|
|
23
|
-
get '
|
29
|
+
get '*a' => 'errors#not_found'
|
24
30
|
end
|
data/spec/middleware_spec.rb
CHANGED
@@ -2,23 +2,38 @@ require 'spec_helper'
|
|
2
2
|
require 'rack/test'
|
3
3
|
|
4
4
|
describe ApiVersions::Middleware do
|
5
|
-
let(:app) { ->(env) { [200, { "Content-Type" => "text/plain"}, [env["HTTP_ACCEPT"]]] } }
|
5
|
+
let(:app) { ->(env) { [200, { "Content-Type" => "text/plain" }, [env["HTTP_ACCEPT"]]] } }
|
6
6
|
|
7
|
-
|
7
|
+
around do |example|
|
8
|
+
original = ApiVersions::VersionCheck.vendor_string
|
8
9
|
ApiVersions::VersionCheck.vendor_string = "myvendor"
|
10
|
+
example.run
|
11
|
+
ApiVersions::VersionCheck.vendor_string = original
|
9
12
|
end
|
10
13
|
|
11
14
|
describe "the accept header" do
|
12
15
|
it "should not adjust the header" do
|
13
16
|
request = Rack::MockRequest.env_for("/", "HTTP_ACCEPT" => "application/vnd.foobar+json;version=1", lint: true, fatal: true)
|
14
|
-
|
17
|
+
response = described_class.new(app).call(request).last
|
15
18
|
response.first.should == "application/vnd.foobar+json;version=1"
|
16
19
|
end
|
17
20
|
|
18
21
|
it "should adjust the header" do
|
19
22
|
request = Rack::MockRequest.env_for("/", "HTTP_ACCEPT" => "text/plain,application/vnd.myvendor+json;version=1,text/html,application/vnd.myvendor+xml", lint: true, fatal: true)
|
20
|
-
|
23
|
+
response = described_class.new(app).call(request).last
|
21
24
|
response.last.should == "text/plain,application/json,application/vnd.myvendor+json;version=1,text/html,application/xml,application/vnd.myvendor+xml"
|
22
25
|
end
|
26
|
+
|
27
|
+
it "should tolerate a nil Accept header" do
|
28
|
+
request = Rack::MockRequest.env_for("/", lint: true, fatal: true)
|
29
|
+
response = described_class.new(app).call(request).last
|
30
|
+
response.last.should_not be
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should tolerate an empty Accept header" do
|
34
|
+
request = Rack::MockRequest.env_for("/", "HTTP_ACCEPT" => '', lint: true, fatal: true)
|
35
|
+
response = described_class.new(app).call(request).last
|
36
|
+
response.last.should == ""
|
37
|
+
end
|
23
38
|
end
|
24
39
|
end
|
data/spec/routing_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api-versions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erich Menge
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
11
|
+
date: 2013-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -129,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
129
|
version: '0'
|
130
130
|
requirements: []
|
131
131
|
rubyforge_project: api-versions
|
132
|
-
rubygems_version: 2.0.
|
132
|
+
rubygems_version: 2.0.2
|
133
133
|
signing_key:
|
134
134
|
specification_version: 4
|
135
135
|
summary: api-versions helps manage your Rails app API endpoints.
|
@@ -154,4 +154,3 @@ test_files:
|
|
154
154
|
- spec/middleware_spec.rb
|
155
155
|
- spec/routing_spec.rb
|
156
156
|
- spec/spec_helper.rb
|
157
|
-
has_rdoc:
|