File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -19,3 +19,37 @@ def encode_basic(username, password)
1919RSpec . configure do |config |
2020 config . include Rack ::Test ::Methods
2121end
22+
23+ # Versioning
24+
25+ # Returns the path with options[:version] prefixed if options[:using] is :path.
26+ # Returns normal path otherwise.
27+ def versioned_path ( options = { } )
28+ case options [ :using ]
29+ when :path
30+ File . join ( '/' , options [ :prefix ] || '' , options [ :version ] , options [ :path ] )
31+ when :header
32+ File . join ( '/' , options [ :prefix ] || '' , options [ :path ] )
33+ else
34+ raise ArgumentError . new ( "unknown versioning strategy: #{ options [ :using ] } " )
35+ end
36+ end
37+
38+ def versioned_headers ( options )
39+ case options [ :using ]
40+ when :path
41+ { } # no-op
42+ when :header
43+ {
44+ 'HTTP_ACCEPT' => "application/vnd.#{ options [ :vendor ] } -#{ options [ :version ] } +#{ options [ :format ] } "
45+ }
46+ else
47+ raise ArgumentError . new ( "unknown versioning strategy: #{ options [ :using ] } " )
48+ end
49+ end
50+
51+ def versioned_get ( path , version_name , version_options = { } )
52+ path = versioned_path ( version_options . merge ( :version => version_name , :path => path ) )
53+ headers = versioned_headers ( version_options . merge ( :version => version_name ) )
54+ get path , { } , headers
55+ end
You can’t perform that action at this time.
0 commit comments