Method: Hyperclient::Resource#validate

Defined in:
lib/hyperclient/resource.rb

#validate(representation) ⇒ Object (private)

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.

Ensures the received representation is a valid Hash-lookalike.



84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/hyperclient/resource.rb', line 84

def validate(representation)
  return {} if representation.nil? || representation.empty?

  if representation.respond_to?(:to_hash)
    representation.to_hash.dup
  else
    raise InvalidRepresentationError.new(
      "Invalid representation for resource (got #{representation.class}, expected Hash). " \
      "Is your web server returning JSON HAL data with a 'Content-Type: application/hal+json' header?",
      representation
    )
  end
end