email2face 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,6 +1,5 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem 'json', :require => 'json'
4
3
  gem 'capybara', :require => 'capybara'
5
4
  gem 'capybara-webkit', :require => 'capybara/webkit'
6
5
  gem 'headless', :require => "headless"
data/Gemfile.lock CHANGED
@@ -62,7 +62,6 @@ DEPENDENCIES
62
62
  capybara-webkit
63
63
  headless
64
64
  jeweler (~> 1.8.3)
65
- json
66
65
  rdoc (~> 3.12)
67
66
  shoulda
68
67
  simplecov
data/README.md CHANGED
@@ -4,7 +4,7 @@ You give it an email. It gives you their face.
4
4
 
5
5
  ## Dependencies & Warnings
6
6
 
7
- It needs a Facebook account to work. I *do not* recommend using your own Facebook, and, to demotivate you from doing that, it stores the Facebook account you give it in plaintext. In other words, if you give it your Facebook account, then it's going to be *very* easy for other people to get access to your Facebook, so make a fake Facebook for using this.
7
+ It needs a Facebook account to work. I *do not* recommend using your own Facebook because it stores the Facebook account in plaintext. So, make a fake Facebook for it. I've included a default one, but it'll probably be banned by the time you get to it.
8
8
 
9
9
  ### Before jumping in
10
10
 
@@ -29,8 +29,6 @@ $ sudo pacman -S xorg-server-xvfb qtwebkit
29
29
  $ sudo apt-get install xvfb libqtwebkit4 libqtwebkit4-dev
30
30
  ```
31
31
 
32
- **You need to make a fake Facebook account to use this!**
33
-
34
32
  ## Using it
35
33
 
36
34
  Start off by installing the gem:
@@ -39,17 +37,29 @@ Start off by installing the gem:
39
37
  gem install 'email2face'
40
38
  ```
41
39
 
42
- Then, we pass in the email, with the Facebook account in a hash:
40
+ Then, we just give Email2Face the email we want a face for:
43
41
 
44
42
  ```ruby
45
43
  require 'email2face'
46
44
  Email2Face.face("my.email@facebook.com")
47
45
  ```
48
- I've included a fake Facebook by default. However, it could be disabled at any time.
49
46
 
50
- When you want to change the Facebook account, just run
47
+ ### Changing the Facebook Account
48
+ It's unlikely the included Facebook account will work for long. So, you may need to make a fake Facebook for it. Do not use your own because it's possible that Facebook may ban it.
49
+
50
+ #### With Ruby on Rails:
51
+
52
+ * Create a new file in `config/initializers` called `facebook.rb`
53
+
54
+ * Open that file in a text editor, and drop in the following:
51
55
 
52
56
  ```ruby
53
- require 'email2face'
54
- Email2Face.face("my.email@facebook.com", { :username => "fb_account@example.com", :password => "fbpassword" })
55
- ```
57
+ Email2Face.username = "FAKE_FACEBOOK_USERNAME"
58
+ Email2Face.password = "FAKE_FACEBOOK_PASSWORD"
59
+ ```
60
+
61
+ You'll need to restart your application server for it to have any affect.
62
+
63
+ #### Without Ruby on Rails:
64
+
65
+ The code above wasn't specific to Ruby on Rails. Just set ```Email2Face.username``` and ```Email2Face.password``` to what you want.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
data/email2face.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "email2face"
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jarred Sumner"]
@@ -39,7 +39,6 @@ Gem::Specification.new do |s|
39
39
  s.specification_version = 3
40
40
 
41
41
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
42
- s.add_runtime_dependency(%q<json>, [">= 0"])
43
42
  s.add_runtime_dependency(%q<capybara>, [">= 0"])
44
43
  s.add_runtime_dependency(%q<capybara-webkit>, [">= 0"])
45
44
  s.add_runtime_dependency(%q<headless>, [">= 0"])
@@ -49,7 +48,6 @@ Gem::Specification.new do |s|
49
48
  s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
50
49
  s.add_development_dependency(%q<simplecov>, [">= 0"])
51
50
  else
52
- s.add_dependency(%q<json>, [">= 0"])
53
51
  s.add_dependency(%q<capybara>, [">= 0"])
54
52
  s.add_dependency(%q<capybara-webkit>, [">= 0"])
55
53
  s.add_dependency(%q<headless>, [">= 0"])
@@ -60,7 +58,6 @@ Gem::Specification.new do |s|
60
58
  s.add_dependency(%q<simplecov>, [">= 0"])
61
59
  end
62
60
  else
63
- s.add_dependency(%q<json>, [">= 0"])
64
61
  s.add_dependency(%q<capybara>, [">= 0"])
65
62
  s.add_dependency(%q<capybara-webkit>, [">= 0"])
66
63
  s.add_dependency(%q<headless>, [">= 0"])
data/lib/email2face.rb CHANGED
@@ -1,54 +1,45 @@
1
1
  require 'capybara/dsl'
2
2
  require 'capybara-webkit'
3
3
  require 'headless'
4
- require 'json'
4
+
5
+ FAKE_FACEBOOK_USERNAME = "anmail@email2face.net"
6
+ FAKE_FACEBOOK_PASSWORD = "thisisapassword"
5
7
 
6
8
  class Email2Face
7
- attr_accessor :username, :password, :verbose
9
+ # This is why you should make a fake Facebook account.
10
+ @@username = FAKE_FACEBOOK_USERNAME
11
+ @@password = FAKE_FACEBOOK_PASSWORD
8
12
 
9
- def self.filepath
10
- "#{ENV["HOME"]}/.sandvich"
13
+ def self.username
14
+ @@username
11
15
  end
12
16
 
13
- CHROME_USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.41 Safari/536.5
14
- "
17
+ def self.username=(username)
18
+ @@username = username
19
+ end
15
20
 
16
- def self.face(email, options = {}, from_thor = false)
17
- user = Email2Face.new
18
- if options[:username].nil? || options[:password].nil?
19
- user.load_auth_from_disk(options)
20
- else
21
- user.username = options[:username]
22
- user.password = options[:password]
23
- user.verbose = options[:verbose]
24
- end
25
- if user.username.nil? || user.username == "" || user.password.nil? || user.password == ""
26
- user.no_login_details(email)
27
- end
28
- html = user.face_html(email)
29
- return user.face(html)
21
+ def self.password
22
+ @@password
23
+ end
24
+
25
+ def self.password=(password)
26
+ @@password = password
30
27
  end
31
28
 
32
- def load_auth_from_disk(options)
33
- if File.exists?(Email2Face.filepath)
34
- json = JSON.parse(File.open(Email2Face.filepath, "r").read)
35
- self.username = json["username"]
36
- self.password = json["password"]
37
- self.verbose = options["verbose"]
29
+ def self.face(email)
30
+ if @@username == FAKE_FACEBOOK_USERNAME
31
+ no_login_details(email)
38
32
  end
33
+ html = face_html(email)
34
+ return get_face(html)
39
35
  end
40
36
 
41
- def no_login_details(email)
42
- options = {}
43
- options[:username] = 'anmail@email2face.net'
44
- options[:password] = 'thisisapassword'
45
- puts "You didn't specify a Facebook account, so I set you up with a fake Facebook account that might not work. When it stops working, just open up \"#{Email2Face.filepath}\" and change it there"
46
- Email2Face.face(email, options)
37
+ def self.no_login_details(email)
38
+ puts "You didn't specify a Facebook account, so I set you up with a fake Facebook account that might not work."
47
39
  end
48
40
 
49
- def face_html(email)
41
+ def self.face_html(email)
50
42
  configure_capybara
51
- puts "Logging in..." if self.verbose
52
43
  Headless.ly do
53
44
  browser = Capybara::Session.new(:webkit, browser)
54
45
  #self.driver.header("User-Agent", CHROME_USER_AGENT)
@@ -59,8 +50,6 @@ class Email2Face
59
50
  browser.click_button "Log In"
60
51
  end
61
52
  if browser.driver.cookies["c_user", ".facebook.com"]
62
- login_success!
63
- puts "Login Successful! Getting Face URL" if self.verbose
64
53
  url = "https://www.facebook.com/search/results.php?o=2048&init=s%3Aemail&q=#{ email.sub("@", "%40") }"
65
54
  browser.visit url
66
55
  return browser.html
@@ -70,30 +59,12 @@ class Email2Face
70
59
  end
71
60
  end
72
61
 
73
- def login_success!
74
- if File.exists?(Email2Face.filepath)
75
- File.delete(Email2Face.filepath)
76
- else
77
- File.new(Email2Face.filepath, "w")
78
- end
79
- File.open(Email2Face.filepath, "w") do |f|
80
- f.write(self.to_json)
81
- end
82
- end
83
-
84
- def to_json
85
- hash = Hash.new
86
- hash[:username] = self.username
87
- hash[:password] = self.password
88
- hash.to_json
89
- end
90
-
91
- def login_failed!
62
+ def self.login_failed!
92
63
  puts "Couldn't login to Facebook. Maybe you misspelled your username or password?"
93
64
  exit(0)
94
65
  end
95
66
 
96
- def face(html)
67
+ def self.get_face(html)
97
68
  parser = Nokogiri::HTML(html)
98
69
  element = parser.xpath("//*[@id='pagelet_search_results_objects']/div/div/div/div/div[2]/div[1]/a") || parser.xpath('//*[@id="js_0"]')
99
70
  href = element.attribute("href")
@@ -101,11 +72,11 @@ class Email2Face
101
72
  uri.host = "graph.facebook.com"
102
73
  uri.path = uri.path + "/picture"
103
74
  uri.to_s
104
- rescue Exception
75
+ rescue
105
76
  "I couldn't find a face for that email :("
106
77
  end
107
78
 
108
- def configure_capybara
79
+ def self.configure_capybara
109
80
  Capybara.app = self
110
81
  Capybara.javascript_driver = :webkit
111
82
  Capybara.current_driver = :webkit
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: email2face
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,22 +11,6 @@ bindir: bin
11
11
  cert_chain: []
12
12
  date: 2012-05-06 00:00:00.000000000 Z
13
13
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: json
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
30
14
  - !ruby/object:Gem::Dependency
31
15
  name: capybara
32
16
  requirement: !ruby/object:Gem::Requirement
@@ -192,7 +176,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
192
176
  version: '0'
193
177
  segments:
194
178
  - 0
195
- hash: -15428611
179
+ hash: -83936141
196
180
  required_rubygems_version: !ruby/object:Gem::Requirement
197
181
  none: false
198
182
  requirements: