Class: AddressFetcher::Aol
- Inherits:
-
Base
- Object
- Base
- AddressFetcher::Aol
show all
- Defined in:
- lib/address_fetcher/aol.rb
Instance Attribute Summary
Attributes inherited from Base
#agent, #options
Instance Method Summary
collapse
Methods inherited from Base
#create_agent, #fetch, #type
Instance Method Details
#=~(options) ⇒ Object
3
4
5
|
# File 'lib/address_fetcher/aol.rb', line 3
def =~(options)
options && options[:username] =~ /@aol.com$/i ? true : false
end
|
#do_fetch ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/address_fetcher/aol.rb', line 23
def do_fetch
raise BadCredentialsError, "Login at first" unless auth_cookie = agent.cookies.find{|c| c.name =~ /^Auth/}
user = auth_cookie.value.scan(/&uid:([^&]+)&/).first.first
page = agent.get "http://webmail.aol.com/aim/en-us/Lite/addresslist-print.aspx?command=all&sort=LastFirstNick&sortDir=Ascending&nameFormat=LastFirstNick&user=#{user}"
names = page.body.scan(/<span class="fullName">([^<]+)<\/span>/).flatten
emails = page.body.scan(/<span>Email 1:<\/span> <span>([^<]+)<\/span>/).flatten
(0...[names.size,emails.size].max).collect do |i|
{ :name => names[i], :email => emails[i] }
end
end
|
#login ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/address_fetcher/aol.rb', line 7
def login
page = @agent.get("http://webmail.aol.com")
login_form = page.form('AOLLoginForm')
login_form.loginId = options[:username].split("@").first
login_form.password = options[:password]
page = @agent.submit(login_form)
raise BadCredentialsError, "Wrong username and password pair" if page.body =~ /Invalid Screen Name or Password. Please try again./
redirect_url = page.body.scan(/http:\/\/[^']*/).first
page = @agent.get redirect_url
success_url = page.body.scan(/gSuccessPath[^"]*\"([^"]*)".*/).flatten.first
page = @agent.get success_url
end
|