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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: daa8e2061260c0cf2b7f4d58d95d9f321ba5796b
4
- data.tar.gz: 1de22bfc799fb807ee1e8af14d47ef8707c59a4a
3
+ metadata.gz: 76c06f9b24fbbbce7345e61b4cce9a66f955f32a
4
+ data.tar.gz: d596f61158abb67ba28f5b7200a8f774416bb33d
5
5
  SHA512:
6
- metadata.gz: 3e5a9e281b081b71b0caad6c1b71acac5a00ca01040337182e00a3ee68eedf39de6ccb1caecc3b69632772e69f916116c53894995270769de2471f1c5aacf817
7
- data.tar.gz: 562696e06899eadf515615ae257357cd3610125559236f9876c1de48824bb85ce026560f5565b4b5492e67c2d1e7ff0f54596197b7ffaa3daf1cd25e957194f5
6
+ metadata.gz: 9243f84c3b74cae3311a3cfd01a6cd63f8d28cf5f2df870aa6c9afd915858cef2bc91d26f1fe79ef1d914cee6a2ddbdfa464a36d4e095f60faa83aecc65e0eac
7
+ data.tar.gz: 293cb32aaaa8b3b2953c38235778307a88e452ff512fe845ecc05a9270db3e18a9deabd794520bb2bff48f6c47229347ee788f759058a306d4167032a664d3ad
data/Changes.md CHANGED
@@ -1,3 +1,8 @@
1
- ## 1.1
1
+ ## 1.2.0
2
+
3
+ * Pass `#api` options to Rails namespace [#1, David Celis]
4
+ * Fix issue with middleware and nil accept header [#2, rposborne]
5
+
6
+ ## 1.1.0
2
7
 
3
8
  * Use middleware to simplify the MIME type instead of doing it at the controller.
data/README.md CHANGED
@@ -1,4 +1,7 @@
1
- # api-versions [![Build Status](https://travis-ci.org/erichmenge/api-versions.png?branch=master)](https://travis-ci.org/erichmenge/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
+ ```
@@ -11,7 +11,7 @@ module ApiVersions
11
11
  VersionCheck.default_version = options[:default_version]
12
12
  VersionCheck.vendor_string = options[:vendor_string]
13
13
 
14
- namespace(:api) { DSL.new(self, &block) }
14
+ namespace(:api, options) { DSL.new(self, &block) }
15
15
  end
16
16
  end
17
17
 
@@ -5,6 +5,8 @@ module ApiVersions
5
5
  end
6
6
 
7
7
  def call(env)
8
+ return @app.call(env) unless env['HTTP_ACCEPT']
9
+
8
10
  accepts = env['HTTP_ACCEPT'].split(',')
9
11
  offset = 0
10
12
  accepts.dup.each_with_index do |accept, i|
@@ -1,3 +1,8 @@
1
1
  module ApiVersions
2
- VERSION = "1.1.0"
2
+ MAJOR = 1
3
+ MINOR = 2
4
+ PATCH = 0
5
+ PRE = nil
6
+
7
+ VERSION = [MAJOR, MINOR, PATCH, PRE].compact.join '.'
3
8
  end
@@ -18,7 +18,13 @@ Dummy::Application.routes.draw do
18
18
  end
19
19
  end
20
20
 
21
- get '*a' => 'errors#not_found'
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 'index' => 'simplified_format#index'
29
+ get '*a' => 'errors#not_found'
24
30
  end
@@ -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
- before do
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
- _, _, response = described_class.new(app).call(request)
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
- _, _, response = described_class.new(app).call(request)
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
@@ -119,4 +119,10 @@ describe 'API Routing' do
119
119
  response.status.should == 404
120
120
  end
121
121
  end
122
+
123
+ describe 'paths' do
124
+ it "should pass options, such as :path, to the regular routing DSL" do
125
+ new_api_baz_path.should == '/baz/new'
126
+ end
127
+ end
122
128
  end
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.1.0
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-13 00:00:00.000000000 Z
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.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: