restful-jsonapi 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/lib/restful/jsonapi/restify_param.rb +50 -37
- data/lib/restful/jsonapi/version.rb +1 -1
- metadata +1 -2
- data/restful-jsonapi-0.0.8.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f35fb3c43cd68b559563b31892b4a3929b5b7326
|
4
|
+
data.tar.gz: 1db27c7d5d17955a03c3eece8f779a2788d63e73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8cc05db93720be70a6e664cf6318de16dd62feb71812cfee5366206ac7ad24a529860be1f3a63c8d181b7f606cd42ad1cb51a8ade0d1c792bdc0e86043685a11
|
7
|
+
data.tar.gz: 1a3f64688c9b18cfb3ef8a109b36a8eb14a45ced91c9666fc4cbb1c1cfd8c5e39b6c8cb1486503f0adf5836c8ad1196166b00575cff47306181922499e0bd618
|
data/README.md
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
A temporary monkeypatch for JSONAPI support, both in request payload, and serializing the type without a namespace.
|
4
4
|
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/restful-jsonapi.svg)](http://badge.fury.io/rb/restful-jsonapi)
|
6
|
+
|
7
|
+
|
5
8
|
## Installation
|
6
9
|
|
7
10
|
Add this line to your application's Gemfile:
|
@@ -4,51 +4,64 @@ module Restful
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
def restify_param(param_key)
|
7
|
-
ActionController::Parameters.new(param_key =>
|
7
|
+
ActionController::Parameters.new(param_key => restify_data(param_key))
|
8
8
|
end
|
9
9
|
|
10
10
|
private
|
11
11
|
|
12
|
-
def
|
12
|
+
def restify_data(param_key, value = params)
|
13
13
|
if value == params
|
14
|
-
value = params.clone[:data]
|
14
|
+
value = params.clone[:data] # leave params alone
|
15
15
|
end
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
16
|
+
value.delete(:type)
|
17
|
+
new_params = ActionController::Parameters.new
|
18
|
+
# relationships
|
19
|
+
if value.has_key? :relationships
|
20
|
+
value.delete(:relationships).each do |relationship_name, relationship_data|
|
21
|
+
new_data = restify_relationship(relationship_name, relationship_data)
|
22
|
+
new_params.merge! new_data if new_data.present?
|
23
|
+
end
|
24
|
+
end
|
25
|
+
# attributes
|
26
|
+
attributes = value.has_key?(:attributes) ? value[:attributes] : value
|
27
|
+
attributes.merge!(id: value[:id]) if value[:id]
|
28
|
+
attributes.transform_keys!(&:underscore)
|
29
|
+
new_params.merge!(attributes)
|
30
|
+
new_params
|
31
|
+
end
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
new_params[relationship_key].push restify_value(k,vv)
|
40
|
-
end unless v[:data].nil?
|
41
|
-
else
|
42
|
-
relationship_key = k.to_s.singularize.underscore+"_ids"
|
43
|
-
new_params[relationship_key] ||= []
|
44
|
-
v[:data].each do |vv|
|
45
|
-
new_params[relationship_key].push vv[:id]
|
46
|
-
end unless v[:data].nil?
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
33
|
+
def restify_relationship(relationship_name, relationship_data)
|
34
|
+
if relationship_data[:data].present?
|
35
|
+
if relationship_data[:data].is_a? Hash
|
36
|
+
restify_belongs_to(relationship_name, relationship_data)
|
37
|
+
else
|
38
|
+
restify_has_many(relationship_name, relationship_data)
|
50
39
|
end
|
51
|
-
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def restify_belongs_to(relationship_name, relationship_data)
|
44
|
+
if relationship_data[:data].has_key? :attributes
|
45
|
+
relationship_key = relationship_name.to_s.underscore+"_attributes"
|
46
|
+
{relationship_key => restify_data(relationship_name,relationship_data[:data])}
|
47
|
+
else
|
48
|
+
{"#{relationship_name}_id" => relationship_data[:data][:id]}
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def restify_has_many(relationship_name, relationship_data)
|
53
|
+
if relationship_data[:data].select(&:attributes).blank?
|
54
|
+
relationship_key = relationship_name.to_s.singularize.underscore+"_ids"
|
55
|
+
new_params[relationship_key] ||= []
|
56
|
+
relationship_data[:data].each do |vv|
|
57
|
+
new_params[relationship_key].push vv[:id]
|
58
|
+
end unless relationship_data[:data].nil?
|
59
|
+
else
|
60
|
+
relationship_key = relationship_name.to_s.underscore+"_attributes"
|
61
|
+
new_params[relationship_key] ||= []
|
62
|
+
relationship_data[:data].each do |vv|
|
63
|
+
new_params[relationship_key].push restify_data(relationship_name,vv[:data])
|
64
|
+
end unless relationship_data[:data].nil?
|
52
65
|
end
|
53
66
|
end
|
54
67
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restful-jsonapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zach Wentz
|
@@ -56,7 +56,6 @@ files:
|
|
56
56
|
- lib/restful/jsonapi/restify_param.rb
|
57
57
|
- lib/restful/jsonapi/serializable_errors.rb
|
58
58
|
- lib/restful/jsonapi/version.rb
|
59
|
-
- restful-jsonapi-0.0.8.gem
|
60
59
|
- restful-jsonapi.gemspec
|
61
60
|
homepage: https://github.com/Netflix/restful-jsonapi
|
62
61
|
licenses:
|
data/restful-jsonapi-0.0.8.gem
DELETED
Binary file
|