Class: AddressFetcher::Yahoo

Inherits:
Base
  • Object
show all
Defined in:
lib/address_fetcher/yahoo.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/yahoo.rb', line 5

def =~(options)
  options && options[:username] =~ /@yahoo.com$/i ? true : false
end

#do_fetchObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/address_fetcher/yahoo.rb', line 22

def do_fetch
  page = @agent.get("http://address.yahoo.com/?1=&VPC=import_export")
  raise BadCredentialsError, "Login at first" if page.body =~ /To access Yahoo! Address Book\.\.\..*Sign in./m

  form = page.forms.last
  csv = @agent.submit(form, form.buttons[2])
  result = []
  FasterCSV.parse(csv.body, :headers => true) do |row|
    name = ""
    name = [row[0], row[2]].select { |v| v.any? }.join(" ") rescue ""
    name = row[4] if name.empty?
    name = row[7] if name.empty?

    email = row[4]
    email = "#{row[7]}@yahoo.com" if email.empty?

    result << {:name  => name, :email => email}
  end
  result
end

#loginObject



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/address_fetcher/yahoo.rb', line 9

def 
  page = @agent.get('https://login.yahoo.com/config/login_verify2')
   = page.form('login_form')
  . = options[:username]
  .passwd = options[:password]
  page = @agent.submit()

  raise BadCredentialsError, "Wrong username and password pair." if page.body =~ /Invalid ID or password./

  url = page.search('//meta').first.attributes['content'].split(/url=/).last rescue nil
  page = @agent.get url
end