Portable Contacts in Ruby
Published October 6th, 2009 edit replace rm!
One of the great new standards made possible by OAuth is PortableContacts. Joseph Smarr from Plaxo is the main force behind it together with Chris Messina and others.
Portable Contacts as the name suggests is a standard for allowing one application access to your contact data on another application. The standard is a nice example of a very clean API which supports both JSON and XML.
I was looking around and I couldn’t find a Ruby library for it, so I wrote this simple Portable Contacts Ruby Gem to allow me and others to use it.
It requires OAuth and the Ruby OAuth Gem. If you need to use it with a Rails application use the OAuth Plugin if using straight Ruby use the Ruby Gem. All you need is an AccessToken object and a Portable Contacts URL to get started.
@access_token = ... # instantiate access token
@client = PortableContacts::Client.new "http://www-opensocial.googleusercontent.com/api/people", @access_token
# Get users profile
@profile = @client.me
puts @profile.display_name
=> "Bob Sample"
# Get users contacts
@contacts = @client.all
If you are using the plugin it is very easy to get started accessing Google.
Just install it and configure it. Once you have a GoogleToken for your user:
@google_token=GoogleToken.find_by_user_id @user.id
@client = @google_token.portable_contacts
# Get users profile
@profile = @client.me
puts @profile.display_name
=> "Bob Sample"
# Get users contacts
@contacts = @client.all
As this is the very first version there are likely to be issues, please do submit patches. I would also love to include a PlaxoToken etc for the OAuth Plugin if someone wants to submit one.
Plans
Eventually there will be some sort of auto discovery so you don’t need to provide a Portable Contacts url.
I would also like to add a server component to the gem, making it easy for you to provide portable contacts for your own application.
Riccardo December 1st, 2010
It would be nice to see an example with PortableContacts and a real oauth login to Google. I am using Deivse and Omniauth (openid) to login but then I have only the uid not an access token.
Martin Lapietra August 9th, 2011
I was looking around and I couldn’t find a Ruby library for it