An unofficial Google Contacts API for ruby. Might not be stable (but probably is).
Right now upgrading should just work, barring any bugs in my implementation. In the next major version I will probably drop (or at least stop maintaining) support for OAuth::AccessToken objects and depend directly on the oauth2 gem.
You need to pass to the GoogleContactsApi::User
constructor one of the following two objects:
See their respective documentation for details on how to get this object. (I'm guessing there would be a few changes in implementation details of the GoogleContactsApi::Api class if you use another OAuth library, mostly to change how the base get/post/put/delete methods work.)
Then you can instantiate a GoogleContactsApi::Api object for direct posting and parsing, or a GoogleContactsApi::User object for easier stuff.
oauth_access_token_for_user
# => <OAuth2::AccessToken:0x000000029a69d36>
google_contacts_user = GoogleContactsApi::User.new(oauth_access_token_for_user)
contacts = google_contacts_user.contacts
# => <GoogleContactsApi::ContactSet: @start_index=1, @items_per_page=100000, @total_results=638>
groups = google_contacts_user.groups
# => <GoogleContactsApi::GroupSet: @start_index=1, @items_per_page=100000, @total_results=8>
# group methods
group = groups.first
# => <GoogleContactsApi::Group: System Group: My Contacts>
group.contacts
# => <GoogleContactsApi::ContactSet: @start_index=1, @items_per_page=100000, @total_results=20>
# creating or deleting a group
new_group = google_contacts_user.create_group('New group')
api.delete_group(new_group)
# contact methods
contact = contacts.first
# => <GoogleContactsApi::Contact: Alvin>
contact.photo
contact.title
contact.id
contact.primary_email
contact.emails
ContactSet
and GroupSet
both implement Enumberable
.
In addition, Contact
and Group
are subclasses of Hashie::Mash, so you can access any of the underlying data directly (for example, if Google returns new data in their API). Note that data is retrieved using Google's JSON API so the equivalent content of an XML element from the XML API is stored under the key "$t".
The easiest way to see the convenience methods I've provided is to look at the RSpec tests.
I welcome patches and pull requests, see the guidelines below (handily auto-generated by jeweler).
Copyright (c) 2011-15 Alvin Liang (aliang). See LICENSE.txt for further details.