One of any social application’s key aspects is often importing contacts. There are a couple of ways to do this. Many wrong ones, and one right one. Our friend Frank Oxener has pointed us to the best one yet.
The importing of contacts is nothing more than parsing a response from a webmail provider. Usually when you want to import contacts, people will build a parser themselves. I have always refused to do this. I don’t suffer from Not Invented Here and I always want to re-use existing code. Besides, I am not keen on parsing text. I have better things to do.
A step up from building everything yourself is using one of the many PHP libraries, or refactoring those. This works, but is brittle as well and introduces a dependency you are trying to avoid. For Bemba this solution was out, too.
A next step is to use one one of the free importer tools that companies are offering. Plaxo is one. Actually I kind of appreciate this route, and I use it for other projects. But for Bemba, we want to keep the user inside our own application. Also, privacy is a concern. Bemba does not exist to feed sensitive data into other businesses.
The step almost close to code nirvana is to use a professional library to do the scraping for you. We have gone this route with Bemba. There are a few tools out there that do all the parsing, scraping and error handling for you. This sort of works. Actually, it didn’t for us. The results from those scrapes were never completely to our liking.
Thanks to the weblog Holland on Rails, Frank discovered the perfect tool to import contacts. It is simply a Ruby gem that does all the hard work for you. Require it in your code, done! There is no step two. I have tested this library and it works wonders.
If you are building software in Ruby (on Rails) and need to import contacts from Yahoo, GMail or Hotmail, I can really recommend this library. It works!

Subscribe to our RSS feed


Were you able to successfully implement all services with the gem? I’ve tried using it in the past and was only able to use it with Yahoo’s service.
Funny enough Yahoo is the only one that doesn’t work for me at the moment. GMail and Hotmail worked great out of the box. I’ve contacted the author about the Yahoo problem and hope to receive a response soon.
Great gem indeed!
When trying to use the gem out of the box, Hotmail did sometimes fail with a CSV::IllegalFormatError error.
This fix worked for me -> http://rubyforge.org/tracker/index.php?func=detail&aid=13753&group_id=2693&atid=10371
hi,
when i tried to install contacts gem ,it gives following error:
ERROR: While executing gem … (RuntimeError)
Error instaling contacts-1.0.9.gem:
contacts requires json >= 0.4.1
For everyone trying the rubygem … as of early March it seems to lack updates. I have switched to using the (non-free) importer from Octazen which works great for all providers.
http://bembamedia.com/2008/03/09/import-contacts-fixed-it/