Home

Awesome

Apipie Bindings

The Ruby bindings for Apipie documented APIs.

Features

Caching

The bindings cache the apidoc from the server. It has separated caches for each server it connects to. If the server sends the apipie checksum in the headers Apipie-Checksum: <md5> , the bindings can expire the cache and reload updated version before next request. If the server does not send the hashes, the cache does not expire and has to be deleted manually when necessary.

The ability to send checksums comes with Apipie 0.1.1, see the docs on how to set it up.

API introspection

It is possible to list available resources, actions, params, routes and its attributes

Getting started
$ rake install
$ irb
irb> require 'apipie-bindings'

irb> api = ApipieBindings::API.new({:uri => 'http://localhost:3000/', :username => 'admin', :password => :changeme})
Listing resources
irb> api.resources
=> [<Resource :roles>, <Resource :images>, <Resource :reports>, <Resource :hosts>, .... <Resource :architectures>]
Listing actions
irb> api.resource(:roles).actions
=> [<Action roles:index>, <Action roles:show>, <Action roles:create>, <Action roles:update>, <Action roles:destroy>]
Listing routes
irb> api.resource(:architectures).action(:show).routes
=> [<Route /api/architectures/:id>]
Listing params
irb> api.resource(:architectures).action(:show).params
=> [<Param *id (String)>]


irb> api.resource(:architectures).action(:show).params.first.required?
=> true
Calling methods (all the calls bellow are equivalent)
irb> api.resource(:architectures).call(:show, :id => 1)
=> {"name"=>"x86_64", "id"=>1, "created_at"=>"2013-12-03T15:00:08Z", "updated_at"=>"2013-12-03T15:00:08Z"}

irb> api.call(:architectures, :show, :id => 1)
=> {"name"=>"x86_64", "id"=>1, "created_at"=>"2013-12-03T15:00:08Z", "updated_at"=>"2013-12-03T15:00:08Z"}

irb> api.resource(:architectures).action(:show).call(:id => 1)
=> {"name"=>"x86_64", "id"=>1, "created_at"=>"2013-12-03T15:00:08Z", "updated_at"=>"2013-12-03T15:00:08Z"}

Logging

It is possible to set custom (Logger compatible) logger while creating API instance.

ApipieBindings::API.new({:uri => 'http://localhost:3000/', :logger => Logging.logger(STDOUT)})

Add gem awesome_print to your application Gemfile if you want to debug api calls with awesome inspect.

Documentation

there is not much of the library documented yet, but we started to document our API with Yard. The docs are installed with the gem and can be viewed from the docs dir directly or by running yard server --gems or online on rubydoc.info

TODO

License

This project is licensed under the MIT license.