Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions parser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ require 'jsonapi/parser'

Then, parse a JSON API document:
```ruby
json_hash = JSON.parse(json_string)
document = JSONAPI.parse(json_hash)
```

Expand Down
2 changes: 0 additions & 2 deletions parser/jsonapi-parser.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@ Gem::Specification.new do |spec|

spec.files = Dir['LICENSE', 'README.md', 'lib/**/*']
spec.require_path = 'lib'

spec.add_dependency 'json', '~>1.8'
end
10 changes: 3 additions & 7 deletions parser/lib/jsonapi/parser.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'json'

require 'jsonapi/parser/attributes'
require 'jsonapi/parser/document'
require 'jsonapi/parser/error'
Expand All @@ -17,14 +15,12 @@ module JSONAPI

# Parse a JSON API document.
#
# @param document [Hash, String] the JSON API document.
# @param options [Hash] options
# @param [Hash] document The JSON API document.
# @param [Hash] options options
# @option options [Boolean] :id_optional (false) Whether the resource
# objects in the primary data must have an id.
# @return [JSONAPI::Parser::Document]
def parse(document, options = {})
hash = document.is_a?(Hash) ? document : JSON.parse(document)

Parser::Document.new(hash, options)
Parser::Document.new(document, options)
end
end
1 change: 1 addition & 0 deletions parser/lib/jsonapi/parser/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Document
attr_reader :data, :meta, :errors, :json_api, :links, :included

def initialize(document_hash, options = {})
fail InvalidDocument if document_hash.nil?
@hash = document_hash
@options = options
@data_defined = document_hash.key?('data')
Expand Down