Class: Email2Face

Inherits:
Object
  • Object
show all
Defined in:
lib/email2face.rb

Constant Summary collapse

@@username =

This is why you should make a fake Facebook account.

FAKE_FACEBOOK_USERNAME
@@password =
FAKE_FACEBOOK_PASSWORD

Class Method Summary collapse

Class Method Details

.configure_capybaraObject



80
81
82
83
84
85
# 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) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/email2face.rb', line 30

def self.face(email)
  if @@username == FAKE_FACEBOOK_USERNAME
    (email)
  end
  html = face_html(email)
  get_face(html)
end

.face_html(email) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# 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
      
    end
  end
end

.get_face(html) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
# 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!Object



63
64
65
# File 'lib/email2face.rb', line 63

def self.
  "Couldn't login to Facebook. Maybe you misspelled your username or password?"
end

.no_login_details(email) ⇒ Object



38
39
40
# File 'lib/email2face.rb', line 38

def self.(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

.passwordObject



22
23
24
# File 'lib/email2face.rb', line 22

def self.password
  @@password
end

.password=(password) ⇒ Object



26
27
28
# File 'lib/email2face.rb', line 26

def self.password=(password)
  @@password = password
end

.usernameObject



14
15
16
# File 'lib/email2face.rb', line 14

def self.username
  @@username
end

.username=(username) ⇒ Object



18
19
20
# File 'lib/email2face.rb', line 18

def self.username=(username)
  @@username = username
end