Class: Contacts::Gmail

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

Constant Summary collapse

CONTACTS_SCOPE =
'http://www.google.com/m8/feeds/'
CONTACTS_FEED =
CONTACTS_SCOPE + 'contacts/default/full/'

Instance Method Summary collapse

Instance Method Details

#contactsObject



7
8
9
# File 'lib/contacts/gmail.rb', line 7

def contacts
  return @contacts if @contacts
end

#real_connectObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/contacts/gmail.rb', line 11

def real_connect
  @client = GData::Client::Contacts.new
  @client.clientlogin(@login, @password)
  
  feed = @client.get(CONTACTS_FEED).to_xml
  
  @contacts = feed.elements.to_a('entry').collect do |entry|
    title, email = entry.elements['title'].text, nil
    entry.elements.each('gd:email') do |e|
      email = e.attribute('address').value if e.attribute('primary')
    end
    [title, email] unless email.nil?
  end
  @contacts.compact!
rescue GData::Client::AuthorizationError => e
  raise AuthenticationError, "Username or password are incorrect"
end