Class: AddressFetcher::Hotmail
- Inherits:
-
Base
- Object
- Base
- AddressFetcher::Hotmail
show all
- Defined in:
- lib/address_fetcher/hotmail.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
5
6
7
|
# File 'lib/address_fetcher/hotmail.rb', line 5
def =~(options)
options && options[:username] =~ /@hotmail.com$/i ? true : false
end
|
#do_fetch ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/address_fetcher/hotmail.rb', line 21
def do_fetch
raise BadCredentialsError, "Login at first." unless agent.cookies.find { |c| c.name == 'MSPPre' && c.value == options[:username] }
page = agent.get('http://mail.live.com/mail/PrintShell.aspx?type=contact')
rows = page.search("//div[@class='ContactsPrintPane cPrintContact BorderTop']")
rows.collect do |row|
name = row.search("//div[@class='cDisplayName']").first.innerText.strip
name = name[0,(name.size-3)]
email = row.search("/table/tr/td[@class='Value']").find { |v| v.inner_text =~ /.*@.*/ }.inner_text.strip rescue ""
{ :name => name, :email => email }
end
end
|
#login ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/address_fetcher/hotmail.rb', line 9
def login
page = @agent.get("http://login.live.com/login.srf?")
login_form = page.form("f1")
login_form.login = options[:username]
login_form.passwd = options[:password]
page = @agent.submit(login_form)
raise BadCredentialsError, "Wrong username and password pair" if page.body =~ /The e-mail address or password is incorrect/
page = agent.get( page.body.scan(/http\:\/\/[^"]+/).first )
end
|