Module: JSONAPI::Response

Defined in:
lib/easy/jsonapi/response.rb

Overview

Used to validate the serialized response before returned to a client

Class Method Summary collapse

Class Method Details

.validate(headers, body) ⇒ Nilclass

Returns if no errors are found.

Parameters:

  • headers (Hash)

    The hash of response headers.

  • body (Hash | String)

    The ruby hash mimicking jsonapi or a JSON document to check for compliance

Returns:

  • (Nilclass)

    if no errors are found

Raises:

  • (InvalidDocument | InvalidHeader)

    depending on what errors were found


15
16
17
18
19
20
# File 'lib/easy/jsonapi/response.rb', line 15

def self.validate(headers, body)
  # TODO: Spec checks based on collections which can be refered from the location header
  #   returned by the server
  JSONAPI::Exceptions::HeadersExceptions.check_compliance(headers.transform_keys(&:to_s).transform_keys(&:upcase))
  JSONAPI::Exceptions::DocumentExceptions.check_compliance(body)
end