Module: Safire::Protocols::JSONResponseParsing Private

Defined in:
lib/safire/protocols/json_response_parsing.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Parses protocol response bodies into JSON-compatible, string-keyed Hashes.

Consumers remain responsible for translating a nil result into their protocol-specific error. This collaborator performs no HTTP or policy work.

Class Method Summary collapse

Class Method Details

.parse_object(body) ⇒ Hash?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns normalized JSON object, or nil when unusable.

Parameters:

  • body (Hash, String, Object)

    parsed or raw response body

Returns:

  • (Hash, nil)

    normalized JSON object, or nil when unusable



16
17
18
19
20
21
22
23
24
# File 'lib/safire/protocols/json_response_parsing.rb', line 16

def parse_object(body)
  parsed = body.is_a?(String) ? JSON.parse(body) : body
  return unless parsed.is_a?(Hash)

  normalized = normalize_value(parsed, {}, 0)
  normalized unless normalized.equal?(INVALID)
rescue JSON::ParserError, EncodingError
  nil
end