=Almodovar {}[http://travis-ci.org/bebanjo/almodovar]
Almodovar is a client for BeBanjo's Sequence & Movida API written in Ruby (it's actually a generic client which plays nice with any RESTful API following some conventions).
==Getting started
Install the gem (make sure you have http://rubygems.org in your gem source list):
$ [sudo] gem install almodovar
Now, let's play with irb:
>> require 'almodovar'
=> true
First you need an authentication token:
>> auth = Almodovar::DigestAuth.new("realm", "user", "password")
=> #
Now you have to instantiate a resource given its URL. Let's try with the root of the Movida API:
>> movida = Almodovar::Resource("http://movida.example.com/api", auth)
=>
Ok. Let's see what we have under _platforms_
>> movida.platforms
=> [YouTube, Vimeo]
Now, show me the _schedule_ of a _title_ given its external id:
>> movida.titles(:external_id => "C5134350003").first.schedule(:expand => :schedulings)
=> 11222010-04-17T00:00:00Z2010-06-17T00:00:00Zarchive
Of course, once you've got the URL of a resource, the next time you don't need to navigate from the root of the API. You can (should!) start from the resource URL:
>> schedulings = Almodovar::Resource("http://staging.schedule.bebanjo.net/api/titles/498/schedule/schedulings", auth)
=> [11222010-04-17T00:00:00Z2010-06-17T00:00:00Zarchive]
What if I want to access a specific node? Just do it:
>> schedulings.first.id
=> 112
>> schedulings.first.scheduling_type
=> "archive"
Note that fields with a hyphen are accessed with an underscore instead, otherwise ruby will think you are trying to substract ('-')
Next, explore the {API docs}[http://wiki.github.com/bebanjo/almodovar/] to learn about other resources.
==Creating resources
Resource collections have the _create_ method. Just call it with the attributes you want your new resource to have!
>> jobs = Almodovar::Resource("http://sequence.example.com/api/work_areas/52/jobs", auth)
=> [ ... , ... ]
>> job = jobs.create(:job => {:name => "Wadus"})
=> ...
>> job.name
=> "Wadus"
==Modifying resources
You can use the _update_ method:
>> job = Almodovar::Resource("http://sequence.example.com/api/work_areas/52/jobs", auth).first
=> ...
>> job.update(:job => {:name => "Wadus wadus"})
=> ...
>> job.name
=> "Wadus wadus"
== Deleting resources
And exactly the same with the _delete_ method:
>> job = Almodovar::Resource("http://sequence.example.com/api/work_areas/52/jobs", auth).first
=> ...
>> job.delete
==To-do
* Better error management
* Write the conventions Almodovar expects in an API
* Other authentication methods than digest
Copyright (c) 2010 BeBanjo S.L., released under the MIT license