ActiveResource sample code?

I’d like to play around a bit with ActiveResource for consuming a web
service. Does anyone have sample code they would be willing to share?
I’ve googled all around and have come up empty except for simple (non-
working) examples given in the RailsConf keynote and some associated
blog entries.

Thanks!

cr

On 11/18/06, [email protected] [email protected] wrote:

I’d like to play around a bit with ActiveResource for consuming a web
service. Does anyone have sample code they would be willing to share?
I’ve googled all around and have come up empty except for simple (non-
working) examples given in the RailsConf keynote and some associated
blog entries.

$LOAD_PATH << “/path/to/activeresource/lib”
require ‘active_resource’

class Job < ActiveResource::Base
self.site = URI.parse(‘http://localhost:3000’)

def done!
connection.post “/jobs/#{id}.xml;done”
end
end

GET /jobs.xml calls JobsController#index

puts Job.find(:all).inspect

POST /jobs/1.xml;done calls JobsController#done with params[:id] == 1

job.done!

Check out the scaffold_resource generator for instantly available
resources:
./script/generate scaffold_resource Job worker:string command:text
description:text started_at:datetime finished_at:datetime

Best,
jeremy