emailist 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ea1f09f66e64ad8005b9d4e80a07eaa83abdfac4
4
- data.tar.gz: 2c2f3d54c20853665a717038512e5813de2f1815
3
+ metadata.gz: 5b41ead369300322d3a618548b730b1e54500bb8
4
+ data.tar.gz: 1a8e709aa20fdd8f3dfccd02cec1150665251661
5
5
  SHA512:
6
- metadata.gz: 2f0808c9a72e5575db6dc6fe02c6984308e44c737f9ab3b79b88251b31aa5546e4b2103906a5481314b85d6fa9728b4dfbb8ff096abbdc32a3c0b7ab1c59b3f1
7
- data.tar.gz: b57d4132097165d97a5f658a53aec0c33638df8e410e169e54da0d7024204be28e8f5579e6f49d67acde76814ee5b219110f01be4f2c60e6445d0b7b8999631d
6
+ metadata.gz: 576e5cf4f9814273e94be3441a064eb7f07117c1ef2c98bb11a93f54a28c826efbd4c5577e171dfb2430510a9d72e40743d998482dbea57d5a30b6a74a8191b1
7
+ data.tar.gz: 97d3312b05ce5fb86e2d74e69c483f6eded698fa7ede435d8a0a9300c467ec3d6834d3754215a872a62d6424a87f23c8ece627a05462ba6524254548753b2e3a
data/README.md CHANGED
@@ -50,16 +50,22 @@ Invalid emails are attempted to be cleaned:
50
50
  emails.add('fred.smith@example.com.')
51
51
  => ['fred.smith@example.com']
52
52
 
53
- Finally, invalid TLDs raise `Emailist::InvalidTLD`:
53
+ Invalid TLDs (after cleaning) raise `Emailist::InvalidTLD`:
54
54
 
55
55
  emails = Emailist.new
56
56
  emails.add('bob.jones@fooo.baar')
57
57
  => # raises Emailist::InvalidTLD
58
58
 
59
+ Finally, if you want to verify hosts (example.com in bob.jones@example.com), do:
60
+
61
+ emails = Emailist.new(verify_hosts: true)
62
+ emails.add('bob.jones@af983h98hsdf98hgiau3hnvgbjiobj8.com')
63
+ => # raises Emailist::HostDead
64
+
59
65
  ## Ideas For Improvement
60
66
 
61
67
  1. Some kind of "best-guess" algorithm that can take invalid TLDs and find the most likely intended TLD (e.g. I'm getting some emails from my parser that have an 'E', like 'bob.jones@blah.comE' -- this clearly is supposed to be '.com'). Perhaps Levenshtein distance could be useful for this.
62
- 2. Ping email domains and raise an error when they're unresponsive. Not sure if this is a good idea, though. Might have some negative side effects that I'm not considering.
68
+ 2. Fix `possible_email` gem -- Rapportive still has an API but they've modified it, so the code for the gem doesn't work. This will require reverse-engineering the API, as they don't offer access publicly. Not sure if it's even possible, but worth a try.
63
69
 
64
70
  ## Contributing
65
71
 
data/emailist.gemspec CHANGED
@@ -27,5 +27,6 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency "rspec"
28
28
  spec.add_development_dependency "shoulda-matchers"
29
29
 
30
+ spec.add_runtime_dependency "net-ping"
30
31
  spec.add_runtime_dependency "possible_email"
31
32
  end
@@ -1,5 +1,6 @@
1
1
  class Emailist < Array
2
2
  class InvalidTLD < StandardError; end
3
3
  class InvalidEmailFormat < StandardError; end
4
- class CantVerifyProfile < StandardError; end
4
+ class HostDead < StandardError; end
5
+ class ProfileNotFound < StandardError; end
5
6
  end
@@ -1,3 +1,3 @@
1
1
  class Emailist < Array
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.12"
3
3
  end
data/lib/emailist.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require "net/ping"
1
2
  require "possible_email"
2
3
 
3
4
  require "emailist/version"
@@ -18,7 +19,8 @@ class Emailist < Array
18
19
  ]
19
20
 
20
21
 
21
- def initialize(verify_profiles: false)
22
+ def initialize(verify_hosts: false, verify_profiles: false)
23
+ @verify_hosts = verify_hosts
22
24
  @verify_profiles = verify_profiles
23
25
  end
24
26
 
@@ -127,21 +129,12 @@ class Emailist < Array
127
129
 
128
130
  email = "#{local}@#{domain}".downcase
129
131
 
130
- # HAVE TO TRY AND REVERSE ENGINEER RAPPORTIVE/LINKEDIN API
131
- # FOR POSSIBLE_EMAIL GEM TO WORK. THIS FUNCTIONALITY REQUIRES
132
- # THAT API, WHICH APPARENTLY HAS BEEN SHUT DOWN FOR THE PUBLIC.
133
- =begin
134
- if @verify_profiles
135
- begin
136
- response = [PossibleEmail.find_profile(email)].flatten
137
- if response.empty?
138
- raise Emailist::CantVerifyProfile
139
- end
140
- rescue PossibleEmail::InvalidEmailFormat
141
- raise Emailist::InvalidEmailFormat
142
- end
132
+ #if @verify_profiles
133
+ # raise Emailist::ProfileNotFound if !profile_found?(email)
134
+ #end
135
+ if @verify_hosts
136
+ raise Emailist::HostDead if !host_alive?(email)
143
137
  end
144
- =end
145
138
 
146
139
  email
147
140
  end
@@ -153,5 +146,53 @@ private
153
146
  uniq!
154
147
  return self
155
148
  end
149
+
150
+ def host_alive?(email)
151
+ domain = email.split('@').last
152
+
153
+ result = if live_hosts.include?(domain)
154
+ true
155
+ elsif dead_hosts.include?(domain)
156
+ false
157
+ else
158
+ Net::Ping::External.new(domain).ping?
159
+ end
160
+
161
+ if result
162
+ live_hosts.push(domain)
163
+ live_hosts.uniq!
164
+ else
165
+ dead_hosts.push(domain)
166
+ dead_hosts.uniq!
167
+ end
168
+
169
+ result
170
+ end
171
+
172
+ def live_hosts
173
+ @live_hosts ||= []
174
+ end
175
+
176
+ def dead_hosts
177
+ @dead_hosts ||= []
178
+ end
179
+
180
+ def profile_found?(email)
181
+ # HAVE TO TRY AND REVERSE ENGINEER RAPPORTIVE/LINKEDIN API
182
+ # FOR POSSIBLE_EMAIL GEM TO WORK. THIS FUNCTIONALITY REQUIRES
183
+ # THAT API, WHICH APPARENTLY HAS BEEN SHUT DOWN FOR THE PUBLIC.
184
+ =begin
185
+ if @verify_profiles
186
+ begin
187
+ response = [PossibleEmail.find_profile(email)].flatten
188
+ if response.empty?
189
+ raise Emailist::CantVerifyProfile
190
+ end
191
+ rescue PossibleEmail::InvalidEmailFormat
192
+ raise Emailist::InvalidEmailFormat
193
+ end
194
+ end
195
+ =end
196
+ end
156
197
 
157
198
  end
@@ -73,18 +73,26 @@ describe "Emailist" do
73
73
  end
74
74
  end
75
75
 
76
- context "raises errors" do
76
+ describe "raises errors" do
77
77
  it "when an email contains no valid TLD" do
78
78
  expect { @email_list.add('bob.jones@yahoo.gloopoopoop') }.to raise_error Emailist::InvalidTLD
79
79
  end
80
80
 
81
- #it "when an email is in an invalid format (for possible_email)" do
82
- # @email_list = Emailist.new(verify_profiles: true)
83
- # expect { @email_list._push('bob.jones@gloopoopoop') }.to raise_error Emailist::InvalidEmailFormat
84
- #end
81
+ it "when an email's host is dead (with verify_hosts turned on)" do
82
+ @email_list = Emailist.new(verify_hosts: true)
83
+ expect { @email_list.add('bob.jones@gloopoop.poop.ad9f8u4nfaj0.com') }.to raise_error Emailist::HostDead
84
+ end
85
+ end
85
86
 
86
- #it "when a profile can't be verified" do
87
- #end
87
+ describe "does not raise errors" do
88
+ it "when an email contains a valid TLD" do
89
+ expect { @email_list.add('bob.jones@yahoo.com') }.to_not raise_error
90
+ end
91
+
92
+ it "when an email's host is up (with verify_hosts turned on)" do
93
+ @email_list = Emailist.new(verify_hosts: true)
94
+ expect { @email_list.add('bob.jones@yahoo.com') }.to_not raise_error
95
+ end
88
96
  end
89
97
 
90
98
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emailist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan Barron
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: net-ping
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: possible_email
71
85
  requirement: !ruby/object:Gem::Requirement