TFWY 1.0.0 Released

Posted 2006-11-21…

I’m proud to announce (along with my co-author, Martin Owen) the v1.0.0 release of the Ruby bindings to the TheyWorkForYou API. TheyWorkForYou is a “non-partisan, volunteer-run website which aims to make it easy for people to keep tabs on their elected and unelected representatives in Parliament.”

The Ruby bindings currently support all of the services offered by v1.0.0 of the API, and makes accessing the data very, very easy to do.

Simple Examples

Get a client…

  require 'twfy'
  client = Twfy::Client.new

Then call services on it directly…

  puts client.constituency(:postcode=>'IP6 9PN').name
  # => Central Suffolk & North Ipswich

  mp = client.mp(:postcode=>'IP6 9PN')
  puts mp.full_name
  # => Michael Lord

  # Get a *lot* of info about this MP
  info = client.mp_info(:id=>mp.person_id)

  # Get a sorted list of all the parties in the House of Lords
  client.lords.map{|l| l.party}.uniq.sort
	#=> ["Bishop", "Conservative", "Crossbench", "DUP", "Green", "Labour", "Liberal Democrat", "Other"]

  # Get number of debates in the House of Commons mentioning 'Iraq'
  number = client.debates(:type=>'commons',:search=>'Iraq').info['total_results']

Or, make use of the “daisy chaining” available for services— the correct arguments are passed around for you (plus you get the benefit of some in-memory caching).

  # Get the MP for the last constituency (if you sort them alphabetically) 
  mp = client.constituencies.sort_by{|c| c.name }.last.mp
  # get the geometry information for that constituency (coming from the MP)
  geometry = mp.constituency.geometry

  # An overkill example showing caching (no services are called here, since
  # the results have already been cached from above)
  mp = mp.constituency.mp.constituency.geometry.constituency.mp

  # These return equivalent results (Note how much easier the first is)
  info1 = mp.info # this is cached for subsequent calls
  info2 = client.mp_info(:id=>mp.person_id)

  # Get pages of debates mentioning 'medicine'
  debates1 = mp.debates(:search=>'medicine')
  debates2 = mp.debates(:search=>'medicine', :page=>2)

See http://www.theyworkforyou.com/api/docs for the original TheyWorkForYou API documentation. The Ruby bindings has RDoc up at http://twfy.rubyforge.org. The project is still in its beginning stages, and feedback is [and always will be] welcome.

Get it

As with any gem…

sudo gem install twfy

Why I did this

It might be worth mentioning that I live in Colorado— a fair ways distant from London, or from anywhere else in the UK, for that matter. So why did I do this?

Sometimes I get bored, and that boredom eventually drives me to search for crazy, off the wall things to do. TheyWorkForYou is just one of the rare useful projects I’ve run across, and I couldn’t resist tossing some Ruby goodness at it.