roda-rest_api 1.3 → 1.3.1
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 +4 -4
- data/lib/roda/plugins/rest_api.rb +22 -13
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 994564104a483693d384aa356c2d5992162b9da8
|
4
|
+
data.tar.gz: ec7b09f05da6ccfbec6a407a38d76ff659c483b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96f63bc502a54ceec8550f7816ccfafd78fef29eb26b3cd828af7538e74e4e2702670a91785302275a7ebc77ef5780086b08ad8d73ba2ef520c987f056978a2c
|
7
|
+
data.tar.gz: 17e0be87930991a02cb2790221a8d55e7fe19eca862ced3d0615777df445ff1b7e4cd0ed97a5c9e1e9696467e729356d817f3f4cc6f203ea4d29826d39b421bb
|
@@ -49,6 +49,7 @@ class Roda
|
|
49
49
|
|
50
50
|
def delete(&block)
|
51
51
|
@delete = block if block
|
52
|
+
@content_type = nil
|
52
53
|
@delete || ->(_){raise NotImplementedError, "delete"}
|
53
54
|
end
|
54
55
|
|
@@ -93,21 +94,28 @@ class Roda
|
|
93
94
|
protected
|
94
95
|
|
95
96
|
def arguments(method)
|
96
|
-
|
97
|
-
if @request.media_type == "application/x-www-form-urlencoded"
|
97
|
+
if method === :save
|
98
|
+
args = if @request.media_type == "application/x-www-form-urlencoded"
|
98
99
|
@request.POST
|
99
100
|
else
|
100
|
-
JSON.parse(@request.body.
|
101
|
+
JSON.parse(@request.body.string)
|
101
102
|
end
|
103
|
+
permitted_args args
|
102
104
|
else
|
103
|
-
@request.GET
|
105
|
+
symbolize_keys @request.GET
|
104
106
|
end
|
105
|
-
args = permitted_args(args)
|
106
107
|
end
|
107
108
|
|
108
|
-
|
109
109
|
private
|
110
110
|
|
111
|
+
def symbolize_keys(args)
|
112
|
+
_args = {}
|
113
|
+
args.each do |k,v|
|
114
|
+
v = symbolize_keys(v) if v.is_a?(Hash)
|
115
|
+
_args[k.to_sym] = v
|
116
|
+
end
|
117
|
+
_args
|
118
|
+
end
|
111
119
|
|
112
120
|
def permitted_args(args, keypath = [])
|
113
121
|
permitted = nil
|
@@ -156,7 +164,8 @@ class Roda
|
|
156
164
|
path = options.delete(:path) || 'api'
|
157
165
|
subdomain = options.delete(:subdomain)
|
158
166
|
options.merge!(host: /\A#{Regexp.escape(subdomain)}\./) if subdomain
|
159
|
-
|
167
|
+
path = true if path.nil? or path.empty?
|
168
|
+
on(path, options, &block)
|
160
169
|
end
|
161
170
|
|
162
171
|
def version(version, &block)
|
@@ -181,7 +190,7 @@ class Roda
|
|
181
190
|
|
182
191
|
def show(options={}, &block)
|
183
192
|
block ||= default_block(:one)
|
184
|
-
get(
|
193
|
+
get(_path, options, &block)
|
185
194
|
end
|
186
195
|
|
187
196
|
def create(options={}, &block)
|
@@ -195,12 +204,12 @@ class Roda
|
|
195
204
|
def update(options={}, &block)
|
196
205
|
block ||= default_block(:save)
|
197
206
|
options.merge!(method: [:put, :patch])
|
198
|
-
is(
|
207
|
+
is(_path, options, &block)
|
199
208
|
end
|
200
209
|
|
201
210
|
def destroy(options={}, &block)
|
202
211
|
block ||= default_block(:delete)
|
203
|
-
delete(
|
212
|
+
delete(_path, options) do
|
204
213
|
response.status = 204
|
205
214
|
block.call(*captures) if block
|
206
215
|
end
|
@@ -208,7 +217,7 @@ class Roda
|
|
208
217
|
|
209
218
|
def edit(options={}, &block)
|
210
219
|
block ||= default_block(:one)
|
211
|
-
get(
|
220
|
+
get(_path("edit"), options, &block)
|
212
221
|
end
|
213
222
|
|
214
223
|
def new(options={}, &block)
|
@@ -218,8 +227,8 @@ class Roda
|
|
218
227
|
|
219
228
|
private
|
220
229
|
|
221
|
-
def
|
222
|
-
if @resource.singleton
|
230
|
+
def _path(path=nil)
|
231
|
+
if @resource and @resource.singleton
|
223
232
|
path = ["", true] unless path
|
224
233
|
else
|
225
234
|
path = [":d", path].compact.join("/")
|