Halibut is a tiny gem that makes it easier to deal with the HAL format.
In providing tools to build, (de)serialize, and manipulate HAL resources, Halibut has the following goals:
- Provide Ruby abstractions
- Clean, small API
- Easily composable, for use in other libraries
Add this line to your application's Gemfile:
gem 'halibut'
And then execute:
$ bundle
Or install it yourself as:
$ gem install halibut
There are three ways to get a resource with halibut: manual, Builder, and JSON.
require 'halibut'
# manually creating a resource
order = Halibut::Core::Resource.new "/orders/123"
order.set_property "total", 30.00
order.set_property "currency", "USD"
order.set_property "status", "shipped"
payment = Halibut::Core::Resource.new "/orders/123/payment"
payment.set_property "method", "credit"
payment.set_property "amount", "30.00"
payment.set_property "auth_code", "ABZ127"
resource = Halibut::Core::Resource.new "/orders"
resource.add_link "find", "/orders{?id}", templated: true
resource.add_link "next", "/orders/1", "name" => 'hotdog'
resource.add_link "next", "/orders/9"
resource.set_property "currentlyProcessing", 14
resource.set_property "shippedToday", 20
resource.embed_resource "payment", payment
resource.add_embed_resource "orders", order
require 'halibut/builder'
builder = Halibut::Builder.new '/orders' do
property 'currentlyProcessing', 14
property 'shippedToday', 20
namespace 'th', 'http://things-db.com/{rel}'
link 'find', '/orders{?id}', templated: true
link 'next', '/orders/1', name: 'hotdog'
link 'next', '/orders/9'
link 'th:manufacturer', '/manufacturer/1'
link 'th:manufacturer', '/manufacturer/2'
link 'th:manufacturer', '/manufacturer/3'
end
# alternatively
builder = Halibut::Builder.new '/orders' do
property 'currentlyProcessing', 14
property 'shippedToday', 20
namespace 'th', 'http://things-db.com/{rel}'
link 'find', '/orderes{?id}', templated: true
relation 'next' do
link '/orders/1', name: 'hotdog'
link '/orders/9'
end
relation 'th:manufacturer' do
link '/manufacturers/1'
link '/manufacturers/2'
link '/manufacturers/3'
end
end
resource = builder.resource
require 'halibut/adapter/json'
# converting to JSON
Halibut::Adapter::JSON.dump resource
# creating a resource from JSON
resource = Halibut::Adapter::JSON.load 'resource.json'
- Fork it
git submodule update --init
bundle install
, optionally pass--without-development
and use your own tools
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request