From 903862a4bd33966773680e6630c3c7534f81277d Mon Sep 17 00:00:00 2001 From: Lucas Hosseini Date: Tue, 27 Sep 2016 11:39:02 +0200 Subject: [PATCH] Remove json dependency. `JSONAPI.parse` now requires a hash. --- parser/README.md | 1 + parser/jsonapi-parser.gemspec | 2 -- parser/lib/jsonapi/parser.rb | 10 +++------- parser/lib/jsonapi/parser/document.rb | 1 + 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/parser/README.md b/parser/README.md index 26360ad..5ee0c85 100644 --- a/parser/README.md +++ b/parser/README.md @@ -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) ``` diff --git a/parser/jsonapi-parser.gemspec b/parser/jsonapi-parser.gemspec index 577fc8b..a9c7618 100644 --- a/parser/jsonapi-parser.gemspec +++ b/parser/jsonapi-parser.gemspec @@ -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 diff --git a/parser/lib/jsonapi/parser.rb b/parser/lib/jsonapi/parser.rb index b66801b..f20cb56 100644 --- a/parser/lib/jsonapi/parser.rb +++ b/parser/lib/jsonapi/parser.rb @@ -1,5 +1,3 @@ -require 'json' - require 'jsonapi/parser/attributes' require 'jsonapi/parser/document' require 'jsonapi/parser/error' @@ -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 diff --git a/parser/lib/jsonapi/parser/document.rb b/parser/lib/jsonapi/parser/document.rb index ddb07d4..83edd96 100644 --- a/parser/lib/jsonapi/parser/document.rb +++ b/parser/lib/jsonapi/parser/document.rb @@ -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')