Class: Graybook::Importer::Yahoo
- Inherits:
-
PageScraper
- Object
- Base
- PageScraper
- Graybook::Importer::Yahoo
- Defined in:
- lib/graybook/importer/yahoo.rb
Overview
contacts importer for Yahoo!
Instance Attribute Summary
Attributes inherited from PageScraper
Attributes inherited from Base
Instance Method Summary collapse
-
#=~(options = {}) ⇒ Object
Matches this importer to an user’s name/address.
-
#login ⇒ Object
login for Yahoo!.
-
#prepare ⇒ Object
prepare the importer.
-
#scrape_contacts ⇒ Object
scrape yahoo contacts.
Methods inherited from PageScraper
#create_agent, #fetch_contacts!, #strip_html
Methods inherited from Base
#fetch_contacts!, #import, #service_name
Instance Method Details
#=~(options = {}) ⇒ Object
Matches this importer to an user’s name/address
12 13 14 |
# File 'lib/graybook/importer/yahoo.rb', line 12 def =~( = {}) && [:username] =~ /@yahoo.co(m|\.uk)$/i ? true : false end |
#login ⇒ Object
login for Yahoo!
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/graybook/importer/yahoo.rb', line 19 def login page = agent.get('https://login.yahoo.com/config/login_verify2?') form = page.forms.first form.login = [:username].split("@").first form.passwd = [:password] page = agent.submit(form, form..first) if page.body =~ /Invalid ID or password./ || page.body =~ /This ID is not yet taken./ return Graybook::Problem.new("Username and password were not accepted. Please check them and try again.") end true end |
#prepare ⇒ Object
prepare the importer
36 37 38 |
# File 'lib/graybook/importer/yahoo.rb', line 36 def prepare login end |
#scrape_contacts ⇒ Object
scrape yahoo contacts
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/graybook/importer/yahoo.rb', line 43 def scrape_contacts page = agent.get("http://address.yahoo.com/?1=&VPC=import_export") if page.body =~ /To access Yahoo! Address Book\.\.\..*Sign in./m return Graybook::Problem.new("Username and password were not accepted. Please check them and try again.") end form = page.forms.last csv = agent.submit(form, form.[2]) # third button is Yahoo-format CSV contact_rows = FasterCSV.parse(csv.body) labels = contact_rows.shift # TODO: Actually use the labels to find the indexes of the data we want contact_rows.collect do |row| next if !row[7].empty? && [:username] =~ /^#{Regexp.escape(row[7])}/ # Don't collect self { :name => "#{row[0]} #{row[2]}".to_s, :email => (row[4] || "#{row[7]}@yahoo.com") # email is a field in the data, but will be blank for Yahoo users so we create their email address } end end |