versioncake 2.2.0 → 2.3.0
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.
- checksums.yaml +8 -8
- data/CHANGELOG.md +27 -13
- data/Gemfile.lock +1 -1
- data/README.md +8 -8
- data/gemfiles/rails3.2.gemfile.lock +1 -1
- data/gemfiles/rails4.0.gemfile.lock +1 -1
- data/gemfiles/rails4.1.gemfile.lock +1 -1
- data/lib/versioncake/strategies/extraction_strategy.rb +24 -15
- data/lib/versioncake/version.rb +1 -1
- data/test/unit/strategies/extraction_strategy_test.rb +9 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YTY4ZDYxNWY2ZDdjMjEwMjQyZDYwZDQ1ZTM2MmYyMzZkZTQzYjE1NA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MjcxYTE4N2NjMmQxMjU3NTIwNDA2ZDQzNTcyMWQ2YzU0ZTA5ODBhZg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YjA2ZDU2MDEzMjk3NzBhODNmZDhlNTY1ZDI1Y2I5OWQ2OWE4OTM1ODBhNjg0
|
10
|
+
ZDUzYTI5MmNhYTNiODg1M2IxNTY3MzFmNDNjNjFhZWQyZTM1MjI5NzUyZGUx
|
11
|
+
NGNmZWExN2QzOTgzMGM2MzZkMzA5NDBiN2M0ZTI2MjUzOTkyYTU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NDljNjI2NDk3ZjY2YTI3NGZlMTFiY2IxNmYxNTU0YjdkMTVlOTFhZjY5ZmM1
|
14
|
+
N2M5ODM4MmM3YjAzMDM3OGY0YWNmMDk4YzdiNTk2MDExZmEwMDk1MDgxMjgy
|
15
|
+
NzI2OTFiYzA3YTc0NTZmZjVhNTExN2NmN2U4YmYwZWJjYzA4ZDM=
|
data/CHANGELOG.md
CHANGED
@@ -1,13 +1,39 @@
|
|
1
1
|
## Unreleased Changes
|
2
2
|
|
3
|
-
[Full Changelog](https://github.com/bwillis/versioncake/compare/v2.
|
3
|
+
[Full Changelog](https://github.com/bwillis/versioncake/compare/v2.3...master)
|
4
4
|
|
5
5
|
Bug Fixes:
|
6
6
|
|
7
|
+
* None
|
8
|
+
|
9
|
+
Enhancements:
|
10
|
+
|
11
|
+
* None
|
12
|
+
|
13
|
+
Deprecations:
|
14
|
+
|
15
|
+
* None
|
16
|
+
|
17
|
+
## 2.3.0 (Mar 6, 2014)
|
18
|
+
|
19
|
+
[Full Changelog](https://github.com/bwillis/versioncake/compare/v2.2...v2.3)
|
20
|
+
|
7
21
|
Enhancements:
|
8
22
|
|
23
|
+
* Allow an object instance to be used as a custom strategy
|
24
|
+
|
25
|
+
## 2.2.0 (Mar 5, 2014)
|
26
|
+
|
27
|
+
[Full Changelog](https://github.com/bwillis/versioncake/compare/v2.1...v2.2)
|
28
|
+
|
29
|
+
Bug Fixes:
|
30
|
+
|
31
|
+
* Be defensive with the return value of a custom strategy (#27)
|
32
|
+
|
9
33
|
## 2.1.0 (Mar 3, 2014)
|
10
34
|
|
35
|
+
[Full Changelog](https://github.com/bwillis/versioncake/compare/v2.0...v2.1)
|
36
|
+
|
11
37
|
Enhancements:
|
12
38
|
|
13
39
|
* Allow simpler handling of an unsupported versioned request by raising a custom error (issues #24 and #25) thanks [Richard Nuno](https://github.com/richardnuno) and [Andres Camacho](https://github.com/andresfcamacho)
|
@@ -40,20 +66,12 @@ Bug Fixes:
|
|
40
66
|
|
41
67
|
[Full Changelog](https://github.com/bwillis/versioncake/compare/v1.1...v1.2)
|
42
68
|
|
43
|
-
Bug Fixes:
|
44
|
-
|
45
|
-
* None
|
46
|
-
|
47
69
|
Enhancements:
|
48
70
|
|
49
71
|
* Support Rails 4
|
50
72
|
* Adding Rails version testing with [Appraisals](https://github.com/thoughtbot/appraisal)
|
51
73
|
* Added contribution guide
|
52
74
|
|
53
|
-
Deprecations:
|
54
|
-
|
55
|
-
* None
|
56
|
-
|
57
75
|
## 1.1.0 (May 18, 2013)
|
58
76
|
|
59
77
|
[Full Changelog](https://github.com/bwillis/versioncake/compare/v1.0...v1.1)
|
@@ -69,10 +87,6 @@ Enhancements:
|
|
69
87
|
* Internal refactoring of strategies for better testability.
|
70
88
|
* Isolated Rails hooks.
|
71
89
|
|
72
|
-
Deprecations:
|
73
|
-
|
74
|
-
* None
|
75
|
-
|
76
90
|
## 1.0.0 (March 14, 2013)
|
77
91
|
|
78
92
|
[Full Changelog](https://github.com/bwillis/versioncake/compare/v0.5...v1.0)
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
|
9
9
|
Co-authored by Ben Willis ([bwillis](https://github.com/bwillis/)) and Jim Jones ([aantix](https://github.com/aantix)).
|
10
10
|
|
11
|
-
Version Cake is an unobtrusive way to version APIs in your Rails app.
|
11
|
+
Version Cake is an unobtrusive way to version APIs in your Rails app.
|
12
12
|
|
13
13
|
- Easily version any view with their API version:
|
14
14
|
|
@@ -39,7 +39,7 @@ gem install versioncake
|
|
39
39
|
| [1.1](CHANGELOG.md#110-may-18-2013) | Yes | No | No |
|
40
40
|
| [1.2](CHANGELOG.md#120-may-26-2013) | Yes | Yes | No |
|
41
41
|
| [1.3](CHANGELOG.md#130-sept-26-2013) | Yes | Yes | No |
|
42
|
-
| [2.0](CHANGELOG.md#200-feb-6-2014)
|
42
|
+
| [>2.0](CHANGELOG.md#200-feb-6-2014) | Yes | Yes | Yes |
|
43
43
|
|
44
44
|
## Upgrade v1.* -> v2.0
|
45
45
|
|
@@ -74,7 +74,7 @@ config.versioncake.extraction_strategy = :query_parameter # for simplicity
|
|
74
74
|
```
|
75
75
|
|
76
76
|
Often times with APIs, depending upon the version, different logic needs to be applied. With the following controller code, the initial value of @posts includes all Post entries.
|
77
|
-
But if the requested API version is three or greater, we're going to eagerly load the associated comments as well.
|
77
|
+
But if the requested API version is three or greater, we're going to eagerly load the associated comments as well.
|
78
78
|
|
79
79
|
Being able to control the logic based on the api version allow you to ensure forwards and backwards compatibility for future changes.
|
80
80
|
|
@@ -119,7 +119,7 @@ end
|
|
119
119
|
|
120
120
|
When a version is specified for which a view doesn't exist, the request degrades and renders the next lowest version number to ensure the API's backwards compatibility. In the following case, since views/posts/index.json.v3.jbuilder doesn't exist, views/posts/index.json.v1.jbuilder is rendered instead.
|
121
121
|
|
122
|
-
#### http://localhost:3000/posts.json?api_version=3
|
122
|
+
#### http://localhost:3000/posts.json?api_version=3
|
123
123
|
```javascript
|
124
124
|
[
|
125
125
|
{
|
@@ -140,7 +140,7 @@ When a version is specified for which a view doesn't exist, the request degrades
|
|
140
140
|
|
141
141
|
For a given request, if we specify the version number, and that version of the view exists, that version specific view version will be rendered. In the below case, views/posts/index.json.v1.jbuilder is rendered.
|
142
142
|
|
143
|
-
#### http://localhost:3000/posts.json?api_version=2 or http://localhost:3000/posts.json?api_version=1
|
143
|
+
#### http://localhost:3000/posts.json?api_version=2 or http://localhost:3000/posts.json?api_version=1
|
144
144
|
```javascript
|
145
145
|
[
|
146
146
|
{
|
@@ -214,11 +214,11 @@ These are the available strategies:
|
|
214
214
|
Strategy | Description | Example
|
215
215
|
--- | --- | ---
|
216
216
|
:query_parameter | version in the url query parameter, for testing or to override for special case | `http://localhost:3000/posts.json?api_version=1` (This is the default.)
|
217
|
-
:path_parameter | version in the url path parameter | `api/v:api_version/`
|
217
|
+
:path_parameter | version in the url path parameter | `api/v:api_version/`
|
218
218
|
request_parameter | version that is sent in the body of the request | Good for testing.
|
219
219
|
:http_header | Api version HTTP header | `X-API-Version: 1`
|
220
220
|
:http_accept_parameter | HTTP Accept header | `Accept: application/xml; version=1` [why do this?](http://blog.steveklabnik.com/posts/2011-07-03-nobody-understands-rest-or-http#i_want_my_api_to_be_versioned)
|
221
|
-
custom | takes the request object and must return an integer | lambda {|request| request.headers["HTTP_X_MY_VERSION"].to_i }
|
221
|
+
custom | takes the request object and must return an integer | lambda {|request| request.headers["HTTP_X_MY_VERSION"].to_i } or class ExtractorStrategy; def execute(request);end;end
|
222
222
|
|
223
223
|
If you use the path_parameter strategy with resources routes, you will want to setup your routes.rb config file to capture the api version. You can do that in a few ways. If you have just a few api routes you might specify the path directly like this:
|
224
224
|
```
|
@@ -346,7 +346,7 @@ AppName::Application.config.versioncake.supported_version_numbers.each do |suppo
|
|
346
346
|
before do
|
347
347
|
@controller.stubs(:requested_version).returns(supported_version)
|
348
348
|
end
|
349
|
-
|
349
|
+
|
350
350
|
test "all versions render the correct template" do
|
351
351
|
get :index
|
352
352
|
assert_equal @response.body, "index.html.v1.erb"
|
@@ -23,22 +23,31 @@ module VersionCake
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def self.lookup(strategy)
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
case strategy
|
27
|
+
when String, Symbol
|
28
|
+
strategy_name = "#{strategy}_strategy".camelize
|
29
|
+
begin
|
30
|
+
VersionCake.const_get(strategy_name).new
|
31
|
+
rescue
|
32
|
+
raise Exception, "Unknown VersionCake extraction strategy #{strategy_name}"
|
33
|
+
end
|
34
|
+
when Proc
|
35
|
+
if strategy.arity == 1
|
36
|
+
VersionCake::CustomStrategy.new(strategy)
|
37
|
+
else
|
38
|
+
raise Exception, "Custom proc extraction strategy requires a single parameter"
|
39
|
+
end
|
40
|
+
when Object
|
41
|
+
if !strategy.methods.include?(:execute)
|
42
|
+
raise Exception, "Custom extraction strategy requires an execute method"
|
43
|
+
elsif strategy.method(:execute).arity != 1
|
44
|
+
raise Exception, "Custom extraction strategy requires an execute method with a single parameter"
|
45
|
+
else
|
46
|
+
strategy
|
47
|
+
end
|
29
48
|
else
|
30
|
-
raise Exception, "
|
31
|
-
end
|
32
|
-
else
|
33
|
-
strategy_name = "#{strategy}_strategy".camelize
|
34
|
-
begin
|
35
|
-
VersionCake.const_get(strategy_name).new
|
36
|
-
rescue
|
37
|
-
raise Exception, "Unknown VersionCake extraction strategy #{strategy_name}"
|
38
|
-
end
|
49
|
+
raise Exception, "Invalid extration strategy"
|
39
50
|
end
|
40
|
-
|
41
51
|
end
|
42
|
-
|
43
52
|
end
|
44
|
-
end
|
53
|
+
end
|
data/lib/versioncake/version.rb
CHANGED
@@ -38,6 +38,15 @@ class ExtractionStrategyTest < ActiveSupport::TestCase
|
|
38
38
|
assert_equal VersionCake::CustomStrategy, strategy.class
|
39
39
|
end
|
40
40
|
|
41
|
+
test "it allows a custom class" do
|
42
|
+
class FakeStrategy
|
43
|
+
def execute(request); end
|
44
|
+
end
|
45
|
+
instance = FakeStrategy.new
|
46
|
+
strategy = VersionCake::ExtractionStrategy.lookup(instance)
|
47
|
+
assert_equal instance, strategy
|
48
|
+
end
|
49
|
+
|
41
50
|
test "it fails to create a custom strategy for a proc with no parameters" do
|
42
51
|
assert_raise(Exception) do
|
43
52
|
VersionCake::ExtractionStrategy.lookup(lambda{})
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: versioncake
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jim Jones
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-03-
|
12
|
+
date: 2014-03-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|