Posts tagged with “ActiveResource”

ObjectiveResource

Pretty cool:

ObjectiveResource is an Objective-C port of Ruby on Rails’ ActiveResource. It provides a way to serialize objects to and from Rails’ standard RESTful web-services (via XML or JSON) and handles much of the complexity involved with invoking web-services of any language from the iPhone.

I’ve been considering trying out some iPhone development (even though I don’t yet own one), and this seems like a really slick way to interface with an existing Rails application.

Posted on June 21, 2009 Leave a Comment
Tagged with: , , , , , ,

Posting to Brightkite using ActiveResource and REST

The other day, I came across Brightkite’s REST API. After taking a look at it, I decided it was the perfect opportunity to try out ActiveResource, the dead simple way to consume RESTful resources. In 20 lines, I was able to put together a simple script to find your most recent check-in on Brightkite and then post to that place.

A Quick Intro To Active Resource

First off, here’s an idea of just how easy it is to connect to a REST API using ActiveResource. Take, for instance, the “places” resource in Brightkite; these URLs all have the base http://brightkite.com/places. To interface with places, all it takes is this:

class Place < ActiveResource::Base
  self.site = 'http://brightkite.com'
end

That’s it. To get all the places, just do Place.find(:all). To create a new place, all it takes is Place.new. Amazing, to say the least. There’s a lot more that’s possible, so I recommend you check out the ActiveResource page on the Rails wiki.

The code

Below are the 20 lines necessary to post a note to Brightkite through the API. Just change USERNAME and PASSWORD to your username and password and change the note text at the bottom, and you’re ready to go. While this is a pretty simple example, it shows just how powerful a well constructed REST API can be.

Posted on August 11, 2008 20 Comments
Tagged with: , , , , ,