roda-rest_api 1.3 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/roda/plugins/rest_api.rb +22 -13
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 21df76a3e9ee8bb54ae50ad5b35f6d1731f8a235
4
- data.tar.gz: a12ad2291415d7ef2e29f00d467dc5b16c3214d5
3
+ metadata.gz: 994564104a483693d384aa356c2d5992162b9da8
4
+ data.tar.gz: ec7b09f05da6ccfbec6a407a38d76ff659c483b8
5
5
  SHA512:
6
- metadata.gz: af5bac9086c6c6de7d0a94a78769615820624166dd1f2d3c82bfaa7a38f87354037e0598424253b932adacbca7a457cc2a192b334238c756f23650664c6c2ddb
7
- data.tar.gz: 949761e444322abd461c95cc21f7f7d28d19b41531dca6155699bc7adb31d061b14cb5974db0b190b5455f1347640dc3396e797789551ad79b8123d9f2bc4c88
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
- args = if method === :save
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.read)
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
- on([path, true], options, &block)
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(path, options, &block)
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(path, options, &block)
207
+ is(_path, options, &block)
199
208
  end
200
209
 
201
210
  def destroy(options={}, &block)
202
211
  block ||= default_block(:delete)
203
- delete(path, options) do
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(path("edit"), options, &block)
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 path(path=nil)
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("/")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roda-rest_api
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.3'
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michel Benevento