Class: Blackbook::Importer::Yahoo
- Inherits:
-
PageScraper
- Object
- Base
- PageScraper
- Blackbook::Importer::Yahoo
- Defined in:
- lib/blackbook/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/blackbook/importer/yahoo.rb', line 12 def =~( = {}) && [:username] =~ /@yahoo.com$/i ? true : false end |
#login ⇒ Object
login for Yahoo!
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/blackbook/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) # Check for login success raise( Blackbook::BadCredentialsError, "That username and password was not accepted. Please check them and try again." ) if page.body =~ /Invalid ID or password./ true end |
#prepare ⇒ Object
prepare the importer
34 35 36 |
# File 'lib/blackbook/importer/yahoo.rb', line 34 def prepare login end |
#scrape_contacts ⇒ Object
scrape yahoo contacts
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/blackbook/importer/yahoo.rb', line 41 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 raise( Blackbook::BadCredentialsError, "Must be authenticated to access contacts." ) 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].blank? && [:username] =~ /^#{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 |