lib/blackbook/importer/aol.rb in blackbook-1.0.2 vs lib/blackbook/importer/aol.rb in blackbook-1.0.3

- old
+ new

@@ -30,12 +30,14 @@ raise( Blackbook::BadCredentialsError, "That username and password was not accepted. Please check them and try again." ) if page.body =~ /Invalid Screen Name or Password. Please try again./ # aol bumps to a wait page while logging in. if we can't scrape out the js then its a bad login wait_url = page.body.scan(/onLoad="checkError[^\)]+/).first.scan(/'([^']+)'/).last.first page = agent.get wait_url - # aol generates the URL below from some JS magic in the wait_url page - agent.get 'http://webmail.aol.com/31361/aol/en-us/Suite.aspx' + + base_uri = page.body.scan(/^var gSuccessPath = \"(.+)\";/).first.first + raise( Blackbook::BadCredentialsError, "You do not appear to be signed in." ) unless base_uri + page = agent.get base_uri end ## # must login to prepare @@ -55,14 +57,16 @@ # Get user id from cookies user_id = auth_cookie.value.scan(/&uid:([^&]+)&/).first.first # Get contacts print page - page = agent.get "http://webmail.aol.com/aim/en-us/Lite/addresslist-print.aspx?command=all&sort=FirstLastNick&sortDir=Ascending&nameFormat=FirstLastNick&user=#{user_id}" - + contacts_uri = agent.current_page.body.scan(/document.forms.searchForm.action = \"(.+)\";/) + raise( Blackbook::BadCredentialsError, "Must be authenticated to access contacts." ) unless contacts_uri + page = agent.get contacts_uri.first.first + # Grab all the contacts - names = page.body.scan( /<span class="fullName">([^<]+)<\/span>/ ).flatten - emails = page.body.scan( /<span>Email 1:<\/span> <span>([^<]+)<\/span>/ ).flatten + names = page.search("//a[@class='contactNameLabel']").map{|a| a.innerText}.flatten + emails = page.body.scan( /<span class="contactOtherEmailLabel">([^<]+)<\/span>/ ).flatten (0...[names.size,emails.size].max).collect do |i| { :name => names[i], :email => emails[i] }