|
1 | 1 | require 'jsonapi'
|
| 2 | +require 'jsonapi/deserializable' |
2 | 3 |
|
3 | 4 | module ActiveModelSerializers
|
4 | 5 | module Adapter
|
@@ -83,24 +84,26 @@ def parse!(document, options = {})
|
83 | 84 | def parse(document, options = {})
|
84 | 85 | JSONAPI.parse_response!(document)
|
85 | 86 | document = document.to_h
|
86 |
| - primary_data = document['data'] |
87 |
| - |
88 |
| - # null data is allowed, as per the JSON API Schema |
89 |
| - return {} unless primary_data |
90 |
| - |
91 |
| - attributes = primary_data['attributes'] || {} |
92 |
| - attributes['id'] = primary_data['id'] if primary_data['id'] |
93 |
| - relationships = primary_data['relationships'] || {} |
94 |
| - |
95 |
| - filter_fields(attributes, options) |
96 |
| - filter_fields(relationships, options) |
97 |
| - |
98 |
| - hash = {} |
99 |
| - hash.merge!(parse_attributes(attributes, options)) |
100 |
| - hash.merge!(parse_relationships(relationships, options)) |
101 |
| - |
102 |
| - hash |
103 |
| - |
| 87 | + puts document |
| 88 | + return JSONAPI::Deserializable::Resource.new(document, options) |
| 89 | + # |
| 90 | + # primary_data = document['data'] |
| 91 | + # |
| 92 | + # # null data is allowed, as per the JSON API Schema |
| 93 | + # return {} unless primary_data |
| 94 | + # |
| 95 | + # attributes = primary_data['attributes'] || {} |
| 96 | + # attributes['id'] = primary_data['id'] if primary_data['id'] |
| 97 | + # relationships = primary_data['relationships'] || {} |
| 98 | + # |
| 99 | + # filter_fields(attributes, options) |
| 100 | + # filter_fields(relationships, options) |
| 101 | + # |
| 102 | + # hash = {} |
| 103 | + # hash.merge!(parse_attributes(attributes, options)) |
| 104 | + # hash.merge!(parse_relationships(relationships, options)) |
| 105 | + # |
| 106 | + # hash |
104 | 107 | rescue JSONAPI::Parser::InvalidDocument => e
|
105 | 108 | puts e.message
|
106 | 109 | return {} unless block_given?
|
|
0 commit comments