Module: Halibut::Adapter::JSON
- Defined in:
- lib/halibut/adapter/json.rb
Overview
This adapter converts Halibut::HAL::Resources to JSON encoded strings and back.
resource = Halibut::Builder.new('http://example.com') do
link "posts", '/posts'
link "author", 'http://locks.io'
property "title", 'Entry point'
end.resource
dumped = Halibut::Adapter::JSON.dump resource
# => "{\"title\":\"Entry point\",\"_links\":{\"self\":{\"href\":\"http://example.com\"},\"posts\":{\"href\":\"/posts\"},\"author\":{\"href\":\"http://locks.io\"}}}"
loaded = Halibut::Adapter::JSON.load dumped
resource == loaded
# => true
Defined Under Namespace
Modules: ConvenienceMethods, InstanceMethods Classes: ResourceExtractor
Class Method Summary collapse
-
.dump(resource) ⇒ Object
Returns a JSON string representation of an Halibut::HAL::Resource.
-
.parse(json) ⇒ Object
Returns an Halibut::HAL::Resource from a JSON string.
Class Method Details
.dump(resource) ⇒ Object
Returns a JSON string representation of an Halibut::HAL::Resource
30 31 32 |
# File 'lib/halibut/adapter/json.rb', line 30 def self.dump(resource) MultiJson.dump resource.to_hash end |
.parse(json) ⇒ Object
Returns an Halibut::HAL::Resource from a JSON string
25 26 27 |
# File 'lib/halibut/adapter/json.rb', line 25 def self.parse(json) ResourceExtractor.new(json).resource end |