June 23, 2006

New Ruby API Library (Now With YAML!)

Always one to be fashionably late (in my usual stylish t-shirt and pair of jeans), I'm pleased to announce the release of a new version of our Ruby API library. Here's the part you'll really like: XML and REXML have been replaced with YAML and Syck.

That's right, EVDB API methods now return data in three different formats, depending on the way they are called. Get your XML, JSON, or YAML like so:

http://api.evdb.com/rest/events/get?app_key=applicationkey&id=E0-001-001056650-4
http://api.evdb.com/json/events/get?app_key=applicationkey&id=E0-001-001056650-4
http://api.evdb.com/yaml/events/get?app_key=applicationkey&id=E0-001-001056650-4

(The YAML output is a little experimental, and we've been spending the last few days tweaking the output. Let us know if something breaks.)

Since Syck powers the parsing, the API#call method gives you back a normal Ruby hash instead of a REXML object. venue.root.elements['//name'] becomes venue['name']. You know you like it.

But since Nothing is Ever That Easy, we're going to pretend that the old library never existed and ignore the incompatibilities introduced by these changes. Hey, what's that behind you?

Oh, sorry. I thought I saw something. Where were we? Oh, right, Ruby. Well, what are you waiting for? Go grab an application key and start coding! Get the code here and read the docs here. Here's a little something to get you started:

#!/usr/bin/env ruby
# A quick script that finds events I've created and displays how many people 
# have said "I'm Going"

# Require the EVDB API Ruby library
require 'evdb/api'

# These are the tokens needed to use the API
user = 'XXXXXX'
password = 'XXXXXX'
app_key = 'XXXXXX'

# Login as me
evdb = EVDB::API.new app_key,
                     'user' => user,
                     'password' => password

# Search for events that I've created
my_events = evdb.call 'events/search',
                      'q' => "user:#{user}"

# Check each event to see if people are going
my_events['events']['event'].each do |event|
  next unless event['going']

  # How many people are going?
  print people_going = event['going']['user'].size
  print (people_going == 1 ? " person is " : " people are ")
  print "going to your event #{event['title']} "
  print "on #{event['start_time']}\n"
end

Posted by paul at June 23, 2006 02:54 PM

Comments