cuba-api 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,11 +12,13 @@ module CubaApi
12
12
  def new_instance( clazz, context = nil )
13
13
  clazz.new( params( clazz, context ) )
14
14
  end
15
-
15
+ alias :new_instance_from_request :new_instance
16
+
16
17
  def params( clazz = nil, context = nil )
17
18
  filter_params_and_keeps( clazz, context )
18
19
  @_data[ 0 ] || {}
19
20
  end
21
+ alias :filtered_params :params
20
22
 
21
23
  def keeps( clazz = nil, context = nil )
22
24
  filter_params_and_keeps( clazz, context )
@@ -36,7 +38,7 @@ module CubaApi
36
38
  private :filter_params_and_keeps
37
39
 
38
40
  def parse_request_body
39
- if env[ 'CONTENT_TYPE' ] == 'application/json'
41
+ if env[ 'CONTENT_TYPE' ] =~ /^application\/json/
40
42
  MultiJson.load( req.body.read )
41
43
  else
42
44
  {}
@@ -8,7 +8,7 @@ module CubaApi
8
8
  elsif req.post?
9
9
  res.status = 201 # Created
10
10
  if obj.respond_to?( :id ) && ! res[ 'Location' ]
11
- res[ 'Location' ] = env[ 'SCRIPT_NAME' ].to_s+ "/#{obj.id}"
11
+ res[ 'Location' ] = env[ 'SCRIPT_NAME' ].to_s + "/#{obj.id}"
12
12
  end
13
13
  elsif req.delete?
14
14
  res.status = 204 # No Content
@@ -19,6 +19,15 @@ module CubaApi
19
19
  end
20
20
  end
21
21
 
22
+ def to_boolean( name, default = nil )
23
+ v = req[ name ]
24
+ if v
25
+ v == 'true'
26
+ else
27
+ default
28
+ end
29
+ end
30
+
22
31
  def offset_n_limit( method, set )
23
32
  count = set.count
24
33
  offset = to_int( 'offset' ).to_i
@@ -27,7 +36,7 @@ module CubaApi
27
36
  end
28
37
 
29
38
  def last_modified( last )
30
- res[ 'Last-Modified' ] = rfc2616( last )
39
+ res[ 'Last-Modified' ] = rfc2616( last ) if last
31
40
  end
32
41
 
33
42
  def modified_since
@@ -39,7 +39,7 @@ describe CubaApi::InputFilter do
39
39
 
40
40
  it 'no json input' do
41
41
  _, _, resp = Cuba.call({})
42
- resp.join.must_be :empty?
42
+ resp.join.must.be :empty?
43
43
  end
44
44
 
45
45
  it 'json input with attr and without keep' do
@@ -57,7 +57,7 @@ describe CubaApi::InputFilter do
57
57
  it 'json input without attr and without keep' do
58
58
  _, _, resp = Cuba.call( 'CONTENT_TYPE' => 'application/json',
59
59
  'rack.input' => StringIO.new( '{"something":"else"}' ) )
60
- resp.join.must_be :empty?
60
+ resp.join.must.be :empty?
61
61
  end
62
62
 
63
63
  it 'json input without attr and with keep' do
@@ -70,7 +70,7 @@ describe CubaApi::ResponseStatus do
70
70
  it 'status 204' do
71
71
  status, _, resp = Cuba.call({'REQUEST_METHOD' => 'DELETE'})
72
72
  status.must.eq 204
73
- resp.join.must_be :empty?
73
+ resp.join.must.be :empty?
74
74
  end
75
75
 
76
76
  it 'status 412' do
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: cuba-api
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.3.2
5
+ version: 0.3.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Christian Meier
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-06 00:00:00.000000000 Z
12
+ date: 2013-06-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cuba
@@ -111,15 +111,15 @@ dependencies:
111
111
  name: copyright-header
112
112
  version_requirements: !ruby/object:Gem::Requirement
113
113
  requirements:
114
- - - "~>"
114
+ - - '='
115
115
  - !ruby/object:Gem::Version
116
- version: 1.0.7
116
+ version: 1.0.8
117
117
  none: false
118
118
  requirement: !ruby/object:Gem::Requirement
119
119
  requirements:
120
- - - "~>"
120
+ - - '='
121
121
  - !ruby/object:Gem::Version
122
- version: 1.0.7
122
+ version: 1.0.8
123
123
  none: false
124
124
  prerelease: false
125
125
  type: :development
@@ -180,48 +180,48 @@ extra_rdoc_files: []
180
180
  files:
181
181
  - MIT-LICENSE
182
182
  - README.md
183
- - lib/cuba_api.rb
184
183
  - lib/cuba_api.rb~
184
+ - lib/cuba_api.rb
185
+ - lib/cuba_api/accept_content.rb
186
+ - lib/cuba_api/reponse_status.rb~
187
+ - lib/cuba_api/response_status.rb
188
+ - lib/cuba_api/config.rb
189
+ - lib/cuba_api/current_user.rb
190
+ - lib/cuba_api/ext2mime_rack.rb
191
+ - lib/cuba_api/reloader_rack.rb
185
192
  - lib/cuba_api/reloader_rack.rb~
186
- - lib/cuba_api/input_filter.rb~
187
- - lib/cuba_api/write_aspects.rb~
188
193
  - lib/cuba_api/ext2mime_rack.rb~
189
- - lib/cuba_api/utils.rb
190
- - lib/cuba_api/guard.rb
191
- - lib/cuba_api/serializer.rb~
192
- - lib/cuba_api/accept_content.rb~
193
- - lib/cuba_api/current_user.rb
194
- - lib/cuba_api/write_aspect.rb
195
- - lib/cuba_api/input_filter.rb
196
- - lib/cuba_api/reponse_status.rb~
197
- - lib/cuba_api/write_aspect.rb~
198
194
  - lib/cuba_api/current_user.rb~
199
- - lib/cuba_api/config.rb
200
195
  - lib/cuba_api/response_status.rb~
201
- - lib/cuba_api/guard.rb~
202
- - lib/cuba_api/accept_content.rb
203
- - lib/cuba_api/config.rb~
204
196
  - lib/cuba_api/utils.rb~
205
- - lib/cuba_api/reloader_rack.rb
197
+ - lib/cuba_api/config.rb~
198
+ - lib/cuba_api/guard.rb~
199
+ - lib/cuba_api/write_aspect.rb~
206
200
  - lib/cuba_api/serializer.rb
207
- - lib/cuba_api/response_status.rb
208
- - lib/cuba_api/ext2mime_rack.rb
209
- - spec/serializer_spec.rb
210
- - spec/input_filter_spec.rb~
201
+ - lib/cuba_api/guard.rb
202
+ - lib/cuba_api/input_filter.rb~
203
+ - lib/cuba_api/accept_content.rb~
204
+ - lib/cuba_api/utils.rb
205
+ - lib/cuba_api/input_filter.rb
206
+ - lib/cuba_api/serializer.rb~
207
+ - lib/cuba_api/write_aspects.rb~
208
+ - lib/cuba_api/write_aspect.rb
211
209
  - spec/config_spec.rb~
212
- - spec/spec_helper.rb~
213
- - spec/aspects_spec.rb
214
- - spec/accept_spec.rb~
215
210
  - spec/spec_helper.rb
216
- - spec/response_status_spec.rb~
217
- - spec/config_spec.rb
211
+ - spec/input_filter_spec.rb~
212
+ - spec/spec_helper.rb~
218
213
  - spec/accept_spec.rb
219
- - spec/serializer_spec.rb~
220
214
  - spec/current_user_spec.rb
221
- - spec/aspects_spec.rb~
222
215
  - spec/current_user_spec.rb~
216
+ - spec/serializer_spec.rb~
217
+ - spec/aspects_spec.rb~
218
+ - spec/response_status_spec.rb~
223
219
  - spec/input_filter_spec.rb
220
+ - spec/aspects_spec.rb
221
+ - spec/serializer_spec.rb
222
+ - spec/config_spec.rb
224
223
  - spec/response_status_spec.rb
224
+ - spec/accept_spec.rb~
225
225
  - Gemfile
226
226
  homepage: http://github.com/mkristian/cuba-api
227
227
  licenses:
@@ -251,10 +251,10 @@ signing_key:
251
251
  specification_version: 3
252
252
  summary: set of plugins for using cuba as API server
253
253
  test_files:
254
- - spec/serializer_spec.rb
255
- - spec/aspects_spec.rb
256
- - spec/config_spec.rb
257
254
  - spec/accept_spec.rb
258
255
  - spec/current_user_spec.rb
259
256
  - spec/input_filter_spec.rb
257
+ - spec/aspects_spec.rb
258
+ - spec/serializer_spec.rb
259
+ - spec/config_spec.rb
260
260
  - spec/response_status_spec.rb