JSON Microformat Converter

One of the goals in writing Michromeformats (a Chrome extension for displaying hCards, hCalendars, and hReviews) was to allow a user to download a specific hCard or hCalendar event and add it to Address Book or iCal.

The extension uses Sumo to parse the page, which picks out the various hcards and hcalendars, and stores them as objects which then get passed around within the extension.

Now, there’s plenty of conversion services out there already, but most of them seem to assume you want them to do the parsing by passing in the url of the page. Sumo has already done half the dirty work, so using one of these services didn’t feel right.

Using Sinatra, the vpim and ri_cal gems, and hosting it on Heroku, I had a working web service in no time that parsed a single microformat into a downloadable file.

The web service is pretty straightforward; it takes URI encoded JSON and turns it into either a .vcf or .ics file. So this:

{
  "n": {"givenName":"Brian","familyName":"Ryckbost"},
  "fn": "Brian Ryckbost",
  "url": ["http://www.ryckbost.com/"],
  "email": ["[email protected]"],
  "adr":[
    {
      "locality":"Holland",
      "region":"Michigan",
      "postal-code":"49423",
      "country-name":"USA"
    }
  ]
}

gets turned into this in michromeformats:

http://growing-flower-18.heroku.com/vcard?query=%7B%22n%22%3A%7B%22givenName%22%3A%22Brian%22%2C%22familyName%22%3A%22Ryckbost%22%7D%2C%22fn%22%3A%22Brian%20Ryckbost%22%2C%22url%22%3A%5B%22http%3A%2F%2Fwww.ryckbost.com%2F%22%5D%2C%22email%22%3A%5B%22brian%40collectiveidea.com%22%5D%2C%22adr%22%3A%5B%7B%22locality%22%3A%22Holland%22%2C%22region%22%3A%22Michigan%22%2C%22postal-code%22%3A%2249423%22%2C%22country-name%22%3A%22USA%22%7D%5D%7D

which if you follow the link ends up looking like this:

BEGIN:VCARD
VERSION:3.0
N:Ryckbost;Brian;;;
FN:Brian Ryckbost
ADR:;;170 W. 35th Street;Holland;Michigan;49423;USA
EMAIL:[email protected]
END:VCARD

It’s not the prettiest URI I’ve ever seen, but it seems to gets the job done when it comes to downloading a specific vcard.

The code is on Github if you want to peak at the internals. Who uses microformats anymore anyways?

bryckbost@gmail.com

Comments

  1. January 09, 2011 at 2:45 AM

    Love your site design!!!