api_versioning 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
data/README.md
CHANGED
@@ -94,6 +94,31 @@ class PostsController < ApplicationController
|
|
94
94
|
end
|
95
95
|
```
|
96
96
|
|
97
|
+
Additionally, you can also pass in multiple parameters to the presenter.
|
98
|
+
|
99
|
+
```
|
100
|
+
render_json posts: { posts: @posts, signed_in: user_signed_in? }
|
101
|
+
```
|
102
|
+
|
103
|
+
Then, in the presenter, you can access your parameters like ...
|
104
|
+
|
105
|
+
```
|
106
|
+
class Api::PostsApi < Api::BaseApi
|
107
|
+
|
108
|
+
def v1(options)
|
109
|
+
|
110
|
+
posts = options[:posts]
|
111
|
+
signed_in = options[:signed_in]
|
112
|
+
|
113
|
+
Jbuilder.encode do |json|
|
114
|
+
json.awesome_response 'Hello World'
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
```
|
121
|
+
|
97
122
|
Requesting an API Version
|
98
123
|
=========================
|
99
124
|
|
@@ -32,20 +32,21 @@ module ApiVersioning
|
|
32
32
|
def render_json(presenters)
|
33
33
|
|
34
34
|
results = []
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
35
|
+
|
36
|
+
begin
|
37
|
+
|
38
|
+
presenters.each do |key, value|
|
39
|
+
presenter = Api.const_get("#{key.to_s.camelize}Api").new(api_version)
|
40
|
+
results << presenter.render(value)
|
41
|
+
end
|
42
|
+
|
43
|
+
render :json => results.join(','), :callback => params[:callback]
|
44
|
+
|
45
|
+
rescue NameError => e
|
46
|
+
render_api_error "Unknown Presenter"
|
47
|
+
rescue Exception => e
|
48
|
+
render_api_error "Bad API Request"
|
49
|
+
end
|
49
50
|
|
50
51
|
end
|
51
52
|
|