@@ -21,91 +21,18 @@ First, require the gem:
2121``` ruby
2222require ' jsonapi/parser'
2323```
24-
25- Then, parse a JSON API document:
24+ Then simply parse a document:
2625``` ruby
27- document = JSONAPI .parse(json_hash)
26+ # This will raise JSONAPI::Validator::InvalidDocument if an error is found.
27+ JSONAPI .parse_response!(document_hash)
2828```
29-
30- ## Examples
31-
29+ or a resource create/update payload:
3230``` ruby
33- document = JSONAPI .parse(json_hash)
34- # Should the document be invalid, the parse method would fail with a
35- # JSONAPI::Validator::InvalidDocument error.
36-
37- document.data.links.defined? (:self )
38- # => true
39- document.data.links.self .value
40- # => 'http://example.com/articles/1'
41- document.data.attributes.keys
42- # => ['title']
43- document.data.attributes.defined? (:title )
44- # => true
45- document.data.attributes.title
46- # => 'JSON API paints my bikeshed!'
47- document.data.relationships.keys
48- # => ['author', 'comments']
49- document.data.relationships.defined? (:author )
50- # => true
51- document.data.relationships.author.collection?
52- # => false
53- document.data.relationships.author.data.id
54- # => 9
55- document.data.relationships.author.data.type
56- # => 'people'
57- document.data.relationships.author.links.defined? (:self )
58- # => true
59- document.data.relationships.author.links.self .value
60- # => 'http://example.com/articles/1/relationships/author'
61- document.data.relationships.defined? (:comments )
62- # => true
63- document.data.relationships.comments.collection?
64- # => true
65- document.data.relationships.comments.data.size
66- # => 2
67- document.data.relationships.comments.data[0 ].id
68- # => 5
69- document.data.relationships.comments.data[0 ].type
70- # => 'comments'
71- document.data.relationships.comments.links.defined? (:self )
72- # => true
73- document.data.relationships.comments.links.self .value
74- # => 'http://example.com/articles/1/relationships/comments'
75-
76- # for the following document_hash
77- document_hash = {
78- ' data' =>
79- {
80- ' type' => ' articles' ,
81- ' id' => ' 1' ,
82- ' attributes' => {
83- ' title' => ' JSON API paints my bikeshed!'
84- },
85- ' links' => {
86- ' self' => ' http://example.com/articles/1'
87- },
88- ' relationships' => {
89- ' author' => {
90- ' links' => {
91- ' self' => ' http://example.com/articles/1/relationships/author' ,
92- ' related' => ' http://example.com/articles/1/author'
93- },
94- ' data' => { ' type' => ' people' , ' id' => ' 9' }
95- },
96- ' comments' => {
97- ' links' => {
98- ' self' => ' http://example.com/articles/1/relationships/comments' ,
99- ' related' => ' http://example.com/articles/1/comments'
100- },
101- ' data' => [
102- { ' type' => ' comments' , ' id' => ' 5' },
103- { ' type' => ' comments' , ' id' => ' 12' }
104- ]
105- }
106- }
107- }
108- }
31+ JSONAPI .parse_resource!(document_hash)
32+ ```
33+ or a relationship update payload:
34+ ``` ruby
35+ JSONAPI .parse_relationship!(document_hash)
10936```
11037
11138## License
0 commit comments