module Halibut::Adapter::JSON

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

Public Class Methods

dump(resource) click to toggle source

Returns a JSON string representation of an Halibut::HAL::Resource

# File lib/halibut/adapter/json.rb, line 30
def self.dump(resource)
  MultiJson.dump resource.to_hash
end
parse(json) click to toggle source

Returns an Halibut::HAL::Resource from a JSON string

# File lib/halibut/adapter/json.rb, line 25
def self.parse(json)
  ResourceExtractor.new(json).resource
end

Private Class Methods

extended(base) click to toggle source

@deprecated Please use Halibut::Adapter::JSON.dump instead.

# File lib/halibut/adapter/json.rb, line 37
def self.extended(base)
  base.extend InstanceMethods
end