3 # DialCentral - Front end for Google's Grand Central service.
4 # Copyright (C) 2008 Eric Warnke ericew AT gmail DOT com
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License, or (at your option) any later version.
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 GMail Contacts Support
24 @todo Look into the official API http://code.google.com/p/gdata-python-client/
37 class GMailAddressBook(object):
39 @note Combined the factory and the addressbook for "simplicity" and "cutting down" the number of allocations/deallocations
42 def __init__(self, username, password):
43 if not self.is_supported():
46 self._account = libgmail.GmailAccount(username, password)
47 self._gmailContacts = self._account.getContacts()
50 def is_supported(cls):
51 return libgmail is not None
53 def get_addressbooks(self):
55 @returns Iterable of (Address Book Factory, Book Id, Book Name)
57 if not self.is_supported():
62 def open_addressbook(self, bookId):
66 def contact_source_short_name(contactId):
73 def get_contacts(self):
75 @returns Iterable of (contact id, contact name)
77 if not self.is_supported():
81 def get_contact_details(self, contactId):
83 @returns Iterable of (Phone Type, Phone Number)
88 def print_gbooks(username, password):
90 Included here for debugging.
92 Either insert it into the code or launch python with the "-i" flag
94 if not GMailAddressBook.is_supported():
95 print "No GMail Support"
98 gab = GMailAddressBook(username, password)
99 for book in gab.get_addressbooks():
100 gab = gab.open_addressbook(book[1])
102 for contact in gab.get_contacts():
104 for details in gab.get_contact_details(contact[0]):
105 print "\t\t", details
106 print gab._gmailContacts