json_api_params 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +43 -1
- data/lib/json_api_params/version.rb +1 -1
- data/lib/json_api_params.rb +7 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52862200b62f7fba69587fbf5b0fc50465e03696
|
4
|
+
data.tar.gz: 79299c35029cc6c9e475d3d2ccf168b36ca57ce7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f873e5ba02d5653b50e8054a5fcc3beb037cc0af75a7a863853460ac68418de6f5508bb00c130f51a1f8fe9e5adb283ab4942952724d34c026c7defc18d3d1e
|
7
|
+
data.tar.gz: 99dc948684ceb0ed8c671a12d4112224761fe7ca9ad8137e51c1a3d7e9e617ba05c6aaf0974b614c88fe6edc6d821302c88d5ba5c6bcc4b421f2c8af7f709452
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# JsonApiParams
|
2
2
|
|
3
|
-
Extracts JSON API params to old-fashioned way.
|
3
|
+
Extracts JSON API (http://jsonapi.org/) params to old-fashioned way.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -20,6 +20,48 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
+
In a case with the following request payload:
|
24
|
+
|
25
|
+
``` json
|
26
|
+
{
|
27
|
+
"data": {
|
28
|
+
"attributes": {
|
29
|
+
"x-y": 1,
|
30
|
+
"z": 2
|
31
|
+
},
|
32
|
+
"relationships": {
|
33
|
+
"foo-bar": {
|
34
|
+
"data": {
|
35
|
+
"id": 42
|
36
|
+
}
|
37
|
+
},
|
38
|
+
"baz": {
|
39
|
+
"data": null
|
40
|
+
},
|
41
|
+
"qux": {
|
42
|
+
"data": [
|
43
|
+
{
|
44
|
+
"id": 3
|
45
|
+
},
|
46
|
+
{
|
47
|
+
"id": 4
|
48
|
+
}
|
49
|
+
]
|
50
|
+
}
|
51
|
+
}
|
52
|
+
}
|
53
|
+
}
|
54
|
+
```
|
55
|
+
|
56
|
+
`ActionController::Parameters#extract_json_api` returns the following structure.
|
57
|
+
|
58
|
+
``` ruby
|
59
|
+
params.extract_json_api
|
60
|
+
#=> {"x_y"=>1, "z"=>2, "foo_bar_id"=>42, "baz_id"=>nil, "qux_ids"=>[3, 4]}
|
61
|
+
```
|
62
|
+
|
63
|
+
You can use Strong Parameters as usual.
|
64
|
+
|
23
65
|
``` ruby
|
24
66
|
# app/controllers/users_controller.rb
|
25
67
|
|
data/lib/json_api_params.rb
CHANGED
@@ -9,7 +9,13 @@ require 'active_support/core_ext/string/inflections'
|
|
9
9
|
|
10
10
|
class ActionController::Parameters
|
11
11
|
def extract_json_api
|
12
|
-
data
|
12
|
+
case data = fetch(:data)
|
13
|
+
when Array
|
14
|
+
return data.map {|_data|
|
15
|
+
self.class.new(data: _data).extract_json_api
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
13
19
|
relationships = data.fetch(:relationships) { self.class.new }
|
14
20
|
|
15
21
|
attributes = self.class[*data.fetch(:attributes) { Hash.new }.flat_map {|key, value|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_api_params
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keita Urashima
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|