Saturday, July 17, 2010

my recent techie prowess, plus HTTP hacking with curl, and the joy that is fortune

being between gigs at the moment, i have to keep my days busy lest grow used to inactivity, or worse, i slowly lose my mind (any more than i already am). that means working on my own projects, which include a couple of code-related things i'm working on, and a few non-code related things (more on the latter in the future).

on the coding front, i'm still putting in a little bit of work into Corner Flower Shoppe. today i helped to finally get Google Analytics sorted and working (woot!).

then there's my personal baby, FortuneBOT. for the uninitiated, fortune is a classic UNIX program that greets you with a random quote; sometimes like a fortune cookie, sometimes nerdy, sometimes offensive, but more often than not grin-inducing. FortuneBOT is literally fortune brought to you over twitter.

the problem with the way FortuneBOT is set up at the moment is that whatever quotes he serves up is dependent on what server he resides on. this was fine when he lived on a tiny little server at home (an NSLU2, or slug, running SlugOS). reliability concerns forced me to move him onto a Dreamhost server. don't get me wrong, he's quite happy living there, and since hasn't missed a scheduled tweet due to untimely power outages. since moving to Dreamhost, however, FortuneBOT has since cleaned up his potty-mouth: no more offensive quotes! and those were some of my favorites!

so long ago i decided FortuneBOT needed to be rewritten, from the ground up, and forgo it's humble 20-line python script roots. well, now i have the free time to do just that, and use it as an excuse for a crash-course in ruby-on-rails and HTTP / REST services (in a desperate attempt to stay relevant).

the REST part of the equation means i have to be able to GET responses from the web service in various formats, not just as HTML. it turns out cURL, along with a little header hacking thanks to the -H switch, makes for an easy way to do just that, all from a command prompt. to make the whole testing process easier i whipped up a quick sh script to do the dirty work for me.

Listing: curl.xml
#!/bin/sh
curl -H 'Accept: application/xml' $@

i've also made curl.json and curl.text scripts for JSON and plain text responses, respectively. you're welcome, internets =]

on that note, i'd like to leave you now with a quote from fortune itself, one of the things it does best (and something followers of FortuneBOT are currently missing) - a dirty limerick:

There once was a man named McSweeny
Who spilled some raw gin on his weeny.
 Just to be couth,
 He added vermouth,
And slipped his girlfriend a martini.

No comments: