Class: Halibut::Adapter::JSON::ResourceExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/halibut/adapter/json.rb

Overview

ResourceExtractor is responsible for deserializing an HAL resource from the JSON representation.

extractor = ResourceExtractor.new({})
# => #<Halibut::Adapter::JSON::ResourceExtractor:0x007f8adb92f2a8
extractor.resource
# => #<Halibut::HAL::Resource:0x007f8add058fb0

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ ResourceExtractor

Straight-forward, just pass in the JSON string you want to extract the resource from.

json = '{"_links":{"self":{"href":"http://example.com"}}}'
ResourceExtractor.new('{}')


65
66
67
68
69
70
71
72
# File 'lib/halibut/adapter/json.rb', line 65

def initialize(json)
  @halibut = Halibut::Core::Resource.new
  @json    = MultiJson.load(json)

  extract_properties
  extract_links
  extract_embedded_resources
end

Instance Method Details

#resourceObject

This method should be called when the the resource extracted is needed



75
76
77
# File 'lib/halibut/adapter/json.rb', line 75

def resource
  @halibut
end