Class: HyperResource::Adapter::HAL_JSON

Inherits:
HyperResource::Adapter show all
Defined in:
lib/hyper_resource/adapter/hal_json.rb

Overview

HyperResource::Adapter::HAL_JSON provides support for the HAL+JSON hypermedia format by implementing the interface defined in HyperResource::Adapter.

Class Method Summary collapse

Class Method Details

.apply(response, resource, opts = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/hyper_resource/adapter/hal_json.rb', line 22

def apply(response, resource, opts={})
  if !response.kind_of?(Hash)
    raise ArgumentError, "'response' argument must be a Hash (got #{response.inspect})"
  end
  if !resource.kind_of?(HyperResource)
    raise ArgumentError, "'resource' argument must be a HyperResource (got #{resource.inspect})"
  end

  apply_objects(response, resource)
  apply_links(response, resource)
  apply_attributes(response, resource)
  resource.loaded = true
  resource.href = response['_links']['self']['href'] rescue nil
  resource
end

.deserialize(string) ⇒ Object



18
19
20
# File 'lib/hyper_resource/adapter/hal_json.rb', line 18

def deserialize(string)
  JSON.parse(string)
end

.serialize(object) ⇒ Object



14
15
16
# File 'lib/hyper_resource/adapter/hal_json.rb', line 14

def serialize(object)
  JSON.dump(object)
end