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 +4 -4
- data/README.md +8 -2
- data/emailist.gemspec +1 -0
- data/lib/emailist/errors.rb +2 -1
- data/lib/emailist/version.rb +1 -1
- data/lib/emailist.rb +56 -15
- data/spec/emailist_spec.rb +15 -7
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b41ead369300322d3a618548b730b1e54500bb8
|
4
|
+
data.tar.gz: 1a8e709aa20fdd8f3dfccd02cec1150665251661
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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.
|
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
data/lib/emailist/errors.rb
CHANGED
data/lib/emailist/version.rb
CHANGED
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
|
-
#
|
131
|
-
#
|
132
|
-
#
|
133
|
-
|
134
|
-
|
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
|
data/spec/emailist_spec.rb
CHANGED
@@ -73,18 +73,26 @@ describe "Emailist" do
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
-
|
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
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
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
|
-
|
87
|
-
|
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.
|
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
|