collection-json 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'collection-json/attributes/template'
|
2
|
+
|
3
|
+
module CollectionJSON
|
4
|
+
module Goliath
|
5
|
+
COLLECTION_JSON_ENCODED = %r{^application/vnd\.collection\+json}
|
6
|
+
|
7
|
+
class Params
|
8
|
+
module Parser
|
9
|
+
def retrieve_params(env)
|
10
|
+
env['params'].tap do |params|
|
11
|
+
if env['rack.input']
|
12
|
+
body = env['rack.input'].read
|
13
|
+
env['rack.input'].rewind
|
14
|
+
unless body.empty?
|
15
|
+
if env['CONTENT_TYPE'].match COLLECTION_JSON_ENCODED
|
16
|
+
begin
|
17
|
+
hash = JSON.parse(body)
|
18
|
+
template = Template.from_hash(hash['template'])
|
19
|
+
template.data.each do |datum|
|
20
|
+
params.merge! datum.name => datum.value
|
21
|
+
end
|
22
|
+
rescue StandardError => e
|
23
|
+
raise ::Goliath::Validation::BadRequestError, "Invalid parameters: #{e.class.to_s}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
include ::Goliath::Rack::Validator
|
33
|
+
include Parser
|
34
|
+
|
35
|
+
def initialize(app)
|
36
|
+
@app = app
|
37
|
+
end
|
38
|
+
|
39
|
+
def call(env)
|
40
|
+
::Goliath::Rack::Validator.safely(env) do
|
41
|
+
env['params'] = retrieve_params(env)
|
42
|
+
@app.call(env)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: collection-json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70328357327560 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70328357327560
|
25
25
|
description: Lightweight gem for building Collection+JSON responses.
|
26
26
|
email:
|
27
27
|
- sebastian@uprise.co.nz
|
@@ -44,6 +44,7 @@ files:
|
|
44
44
|
- lib/collection-json/attributes/query.rb
|
45
45
|
- lib/collection-json/attributes/template.rb
|
46
46
|
- lib/collection-json/builder.rb
|
47
|
+
- lib/collection-json/goliath.rb
|
47
48
|
- lib/collection-json/transformers/uri.rb
|
48
49
|
- lib/collection-json/version.rb
|
49
50
|
- spec/collection-json/attributes/collection_spec.rb
|