lib/blackbook/importer/gmail.rb in rakutenusa-blackbook-1.0.15 vs lib/blackbook/importer/gmail.rb in rakutenusa-blackbook-1.0.16
- old
+ new
@@ -11,14 +11,23 @@
def =~(options = {})
options && options[:username] =~ /@(gmail|googlemail).com$/i ? true : false
end
+ def import(*args)
+ # GMail depends on Hpricot for some reason...
+ parser = WWW::Mechanize.html_parser
+ WWW::Mechanize.html_parser = Hpricot
+ returning super do
+ WWW::Mechanize.html_parser = parser
+ end
+ end
+
##
# login to gmail
- def login
+ def login
page = agent.get('http://mail.google.com/mail/')
form = page.forms.first
form.Email = options[:username]
form.Passwd = options[:password]
page = agent.submit(form,form.buttons.first)
@@ -38,13 +47,14 @@
end
##
# scrape gmail contacts for this importer
- def scrape_contacts
- unless agent.cookies.find{|c| c.name == 'GAUSR' &&
- (c.value.include? "mail:#{options[:username]}")}
+ def scrape_contacts
+ unless agent.cookies.find { |c|
+ c.name == 'GAUSR' && c.value.match(/mail(.*?):#{options[:username]}/)
+ }
raise( Blackbook::BadCredentialsError, "Must be authenticated to access contacts." )
end
page = agent.get('http://mail.google.com/mail/h/?v=cl&pnl=a')
title = page.search("//title").inner_text
@@ -61,10 +71,10 @@
clean_email = email[/[a-zA-Z0-9._%+-]+@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,4}/]
unless clean_email.empty?
columns = row/"td"
{
- :name => ( columns[1] / "b" ).inner_text, # name
+ :name => ( columns[1] / "b" / "a" ).inner_html, # name
:email => clean_email
}
end
end.compact
end