Wed
Mar 11th

Hack the Tube

Yesterday we featured a roundup of iPhone London Underground apps.  Today I’m going to show you how to hack the Tube yourself.

Tube Updates API

Tube Updates is an API by Ben Dodson that provides access to TFL data on Tube updates.  You can get data in either XML or JSON.  Here’s the full documentation: API Documentation - Tube Updates.

Accessing the API is simple, just request the format and lines:

http://api.tubeupdates.com/?method=get.status&lines=central,hammersmithcity,victoria&format=xml

Ruby Example

Here’s a Ruby example to get you started:

This provides a simple way of accessing the API.  Just create a TubeUpdates object and pass an array of station names.  The station names are in the API documentation:

  • all - Wildcard for all lines
  • bakerloo - Bakerloo Line
  • central - Central Line
  • circle - Circle Line
  • district - District Line
  • docklands - Docklands (note: DLR will always return a status of ‘unknown’ as TFL doesn’t give it a status)
  • hammersmithcity - Hammersmith & City Line
  • jubilee - Jubilee Line
  • metropolitan - Metropolitan Line
  • northern - Northern Line
  • piccadilly - Piccadilly Line
  • tube - Wildcard for all tube lines (excludes DLR)
  • victoria - Victoria Line
  • waterloocity - Waterloo & City Line

There’s no error handling in my example, so you might like to add this.  It could form a create Rails plugin for a web site or service.

JavaScript Widget Example

If you’re writing a Mac OS Dashboard widget or Google Homepage Gadget you’ll need to use their API to request data.  For example, Mac OS Widgets require network access to be enabled in Widget Attributes:

Mac OS Widget Attributes

This basic example shows how to use Prototype.js to fetch data and show it in a Dashboard list UI element:

You can download the full example here: TubeStatus.zip

Comments (View)
Related Posts Widget for Blogs by LinkWithin