Discussing the nuts and bolts of software development

Wednesday, November 12, 2008

 

The Anti-social web - Twitter for the socially inept

Twitter was mentioned during Macadamian's corporate blogging presentation. "Useless! Bah! Humbug!" were the first thoughts to enter my head. Then the speaker pointed out that corporate bloggers should strive to see the positive side of any situation, and I figured making Twitter useful to a neo-Luddite was a good challenge; there must be an itch to scratch here, right?

All I knew about Twitter was that people think it's slow, and it's written in Ruby (on Rails.) After exploring a little more, I found out that it can provide private Atom feeds of your messages, and exposes a REST API (ooh, new, shiny!) That was enough to get me coding.

To keep things simple I decided to be boring and test out Twitter using Ruby (normally, I plan epic posts with 5 different languages, communicating through at least 2 protocols... and a database for no good reason.) The process I followed was:
require 'date'
require 'rest_client'
require 'rexml/document'

username = "your_twitter_id_here"
password = "your_twitter_password_here"

twitter = RestClient::Resource.new 'http://%s:%s@twitter.com' % [ username, password ]

# Send a message to twitter
result = twitter['statuses/update.xml'].post(
:status => "This is your computer. You have no life as of %s" % DateTime.now()
)
# print result

timelineXML = twitter['statuses/user_timeline.xml'].get({ :count => 5 });

# Make the XML usable
# (Use XmlSimple for even easier handling)
timeline = REXML::Document.new(timelineXML)

# Display the text element of every status returned by the service
# (print timelineXML to learn more about the structure of the result.)
puts "%s's timeline:" % username
timeline.elements.each('statuses/status/text') { |message|
puts message.text
}

As Twitter restricts you to 70 calls per hour, it's a good job Ruby (on REST) made this so easy. REST is a nice change from the usual URL gobbledygook that frameworks throw up - I can't wait to try it out in Struts2.

So, what can people with no interest in socializing do with Twitter?
One final note, until the authentication framework is more robust, don’t rely on anything you twit staying private.

Labels: , ,


This page is powered by Blogger. Isn't yours?