Class: HyperResource::Adapter::HAL_JSON

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

Class Method Summary collapse

Class Method Details

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



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/hyper_resource/adapter/hal_json.rb', line 17

def apply(response, resource, opts={})
  if !response.kind_of?(Hash)
    raise ArgumentError, "'response' argument must be a Hash"
  end
  if !resource.kind_of?(HyperResource)
    raise ArgumentError, "'resource' argument must be a HyperResource"
  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



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

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

.serialize(object) ⇒ Object



9
10
11
# File 'lib/hyper_resource/adapter/hal_json.rb', line 9

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