January 11, 2007
Follow me on Twitter

UPS Tracking in Tinderbox

Let's look at another nifty thing you can do in Tinderbox 3.6. This time, we're going to use AutoFetchCommand to plug into a Web service.

Lots of companies use UPS to ship packages. If you got to their Web site, you can sign up for a free "developer key" that gives you access to their tracking system. You send them a little hunk of XML that contains:

The UPS server sends back a hunk of XML that tells you what it knows about the package. So, in Tinderbox, we have a user attribute for the UPS tracking number and we write a little script (I used ruby) to talk to UPS. Here's the business end, after I've assembled the little XML package to send to UPS:

# assemble the input xml
command="curl -s -d \'"+input+"\' https://www.ups.com/ups.app/xml/Track";
status= XPath.first(doc,"//Status/StatusType/Description")
if (!status)
puts status.to_a

This is lousy ruby style. I don't really know ruby. You can do loads better. It's just an example.

Anyway, now we can add TrackingNumber and DeliveryStatus attributes to our notes about UPS parcels, and give them an AutoFetchCommand like this:

DeliveryStatus=`ruby ~/Documents/Work/UPS/ups.rb $TrackingNumber

And now the DeliveryStatus will be automatically updated over the net. Agents can give you up-to-the-minute lists of all the packages that have not been delivered. All sorts of nice new things are possible: even easy.