Class: AddressBook::Gmail

Inherits:
Base
  • Object
show all
Defined in:
lib/address_book/gmail.rb

Constant Summary collapse

ADDRESS_BOOK_URL =
"http://www.google.com/m8/feeds/contacts/default/full/?max-results=1000"

Instance Attribute Summary

Attributes inherited from Base

#contacts

Instance Method Summary collapse

Methods inherited from Base

#session

Constructor Details

#initialize(login, password) ⇒ Gmail

Returns a new instance of Gmail.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/address_book/gmail.rb', line 9

def initialize(, password)
  client = GData::Client::Contacts.new
  client.clientlogin , password

  self.contacts = Nokogiri::XML.parse(client.get(ADDRESS_BOOK_URL).body).css("entry").map do |e|
    name = (e > "title").first.content
    email = e.at_xpath("gd:email")[:address]
    [name, email]
  end
rescue GData::Client::AuthorizationError
  raise AuthenticationError, "Username or password are incorrect"
end