Class: EmailSpy::Gmail

Inherits:
Object
  • Object
show all
Defined in:
lib/email-spy/gmail.rb

Constant Summary collapse

Contacts_API_URL =
"http://www.google.com/m8/feeds/contacts/default/full"

Class Method Summary collapse

Class Method Details

.fetch(invitor_email_address, invitor_email_password) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/email-spy/gmail.rb', line 6

def self.fetch invitor_email_address,invitor_email_password
  client = GData::Client::Contacts.new
  client.clientlogin(invitor_email_address, invitor_email_password)
  response = client.get(Contacts_API_URL).to_xml
  
  response.elements.to_a('entry').map 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
    Contact.new(title,email) unless email.nil?
  end.compact
rescue GData::Client::AuthorizationError => e
  raise AuthenticationError
end