class Email2Face
Public Class Methods
configure_capybara()
click to toggle source
# File lib/email2face.rb, line 80 def self.configure_capybara Capybara.app = self Capybara.javascript_driver = :webkit Capybara.current_driver = :webkit Capybara.run_server = false end
face(email)
click to toggle source
# File lib/email2face.rb, line 30 def self.face(email) if @@username == FAKE_FACEBOOK_USERNAME no_login_details(email) end html = face_html(email) get_face(html) end
face_html(email)
click to toggle source
# File lib/email2face.rb, line 42 def self.face_html(email) Email2Face.configure_capybara Headless.ly do browser = Capybara::Session.new(:webkit, browser) #self.driver.header("User-Agent", CHROME_USER_AGENT) browser.visit "https://www.facebook.com/login.php" browser.within "#loginform" do browser.fill_in "email", :with => self.username browser.fill_in "pass", :with => self.password browser.click_button "Log In" end if browser.driver.cookies["c_user", ".facebook.com"] url = "https://www.facebook.com/search/results.php?o=2048&init=s%3Aemail&q=#{ email.sub("@", "%40") }" browser.visit url return browser.html else login_failed! end end end
get_face(html)
click to toggle source
# File lib/email2face.rb, line 67 def self.get_face(html) parser = Nokogiri::HTML(html) element = parser.xpath("//*[@id='pagelet_search_results_objects']/div/div/div/div/div[2]/div[1]/a") || parser.xpath('//*[@id="js_0"]') || parser.xpath("//*[@id=\"js_1\"]") href = element.attribute("href") uri = URI.parse(href) uri.host = "graph.facebook.com" uri.path = uri.path + "/picture" raise if uri.path.include?("profile.php") || href == nil uri.to_s rescue "I couldn't find a face for that email :(. It's also possible that Facebook has asked for a security check on that account, which means that you should sign in and perform the security check." end
login_failed!()
click to toggle source
# File lib/email2face.rb, line 63 def self.login_failed! "Couldn't login to Facebook. Maybe you misspelled your username or password?" end
no_login_details(email)
click to toggle source
# File lib/email2face.rb, line 38 def self.no_login_details(email) puts "You didn't specify a Facebook account, so I set you up with the default fake Facebook account. It might not work for long." end
password()
click to toggle source
# File lib/email2face.rb, line 22 def self.password @@password end
password=(password)
click to toggle source
# File lib/email2face.rb, line 26 def self.password=(password) @@password = password end
username()
click to toggle source
# File lib/email2face.rb, line 14 def self.username @@username end
username=(username)
click to toggle source
# File lib/email2face.rb, line 18 def self.username=(username) @@username = username end