appending 1.4 → 1.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/appending.rb +86 -51
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: add82355a1cc40388a4638c12458a7c85419d888c2faf290468293aa3d1c5318
|
4
|
+
data.tar.gz: 50b9b920c608bcb72a3ca9402be2bfc0bc60854c2ab0091e0662384c95995323
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29cf888c3f57d24ff03a0314450c1cc9f8882b4ffb7f0bf6e3a7c6ffae13f2b0c082541aede412141dea935713511292b8af93467335a6d636ab5abc2065120a
|
7
|
+
data.tar.gz: fdccb2a50a08b53dcfbc9736982cf57c1f224ace49931510e5562f2627279cdd7b41090df42925023b611c66394058f74e1c7b3853012f302169163f27817f52
|
data/lib/appending.rb
CHANGED
@@ -14,6 +14,8 @@ module BlackStack
|
|
14
14
|
@@phone_fields = []
|
15
15
|
@@company_domain_fields = []
|
16
16
|
|
17
|
+
@@zerobounce_api_key = nil
|
18
|
+
|
17
19
|
## @@logger
|
18
20
|
def self.set_logger(logger)
|
19
21
|
@@logger = logger
|
@@ -162,6 +164,23 @@ module BlackStack
|
|
162
164
|
@@email_fields = h[:email_fields] if h[:email_fields]
|
163
165
|
@@phone_fields = h[:phone_fields] if h[:phone_fields]
|
164
166
|
@@company_domain_fields = h[:company_domain_fields] if h[:company_domain_fields]
|
167
|
+
|
168
|
+
# zerobounce api key
|
169
|
+
@@zerobounce_api_key = h[:zerobounce_api_key] if h[:zerobounce_api_key]
|
170
|
+
end
|
171
|
+
|
172
|
+
# call zerobounce api
|
173
|
+
def self.zerobounce_verify(email)
|
174
|
+
# validation: email must be a string
|
175
|
+
raise "Invalid email: #{email.class}. Expected: String." if !email.is_a?(String)
|
176
|
+
url = "https://api.zerobounce.net/v2/validate"
|
177
|
+
params = {
|
178
|
+
:api_key => @@zerobounce_api_key,
|
179
|
+
:email => email,
|
180
|
+
:ip_address => nil,
|
181
|
+
}
|
182
|
+
res = BlackStack::Netting::call_get(url, params)
|
183
|
+
JSON.parse(res.body)
|
165
184
|
end
|
166
185
|
|
167
186
|
# return true if the domain get any random address as valid
|
@@ -183,32 +202,11 @@ module BlackStack
|
|
183
202
|
params = {
|
184
203
|
:email => email,
|
185
204
|
}
|
186
|
-
|
205
|
+
# send HTTP-GET request to @@verifier_url, using the standard HTTP module
|
206
|
+
res = Net::HTTP.get_response(URI.parse("#{url}?email=#{params[:email]}"))
|
187
207
|
parsed = JSON.parse(res.body)
|
188
|
-
parsed
|
189
|
-
|
190
|
-
|
191
|
-
# verify an email address
|
192
|
-
def self.append(fname, lname, domain)
|
193
|
-
ret = []
|
194
|
-
if !catch_all?(domain)
|
195
|
-
[
|
196
|
-
"#{fname}@#{domain}",
|
197
|
-
"#{lname}@#{domain}",
|
198
|
-
|
199
|
-
"#{fname}.#{lname}@#{domain}",
|
200
|
-
"#{lname}.#{fname}@#{domain}",
|
201
|
-
|
202
|
-
"#{fname}#{lname}@#{domain}",
|
203
|
-
"#{lname}#{fname}@#{domain}",
|
204
|
-
|
205
|
-
"#{fname[0]}#{lname}@#{domain}",
|
206
|
-
"#{fname[0]}.#{lname}@#{domain}",
|
207
|
-
].each { |email|
|
208
|
-
ret << email.downcase if BlackStack::Appending.verify(email)
|
209
|
-
}
|
210
|
-
end
|
211
|
-
ret
|
208
|
+
#parsed = JSON.parse(`curl --location --request GET '#{url}?email=#{email}' --header 'Content-Type: application/json'`)
|
209
|
+
parsed['status'] == 'success'
|
212
210
|
end
|
213
211
|
|
214
212
|
# This is a support method for the `append` methods.
|
@@ -259,8 +257,8 @@ module BlackStack
|
|
259
257
|
|
260
258
|
# Find a person in the indexes by its full name and company name.
|
261
259
|
# Append all the information in the index row.
|
262
|
-
def self.find_persons_with_full_name(name, cname)
|
263
|
-
l = BlackStack::
|
260
|
+
def self.find_persons_with_full_name(name, cname, l=nil)
|
261
|
+
l = BlackStack::DummyLogger.new if l.nil?
|
264
262
|
|
265
263
|
l.logs "Guessing fname from #{name}... "
|
266
264
|
fname = BlackStack::Appending::cleanup_fname(name)
|
@@ -270,13 +268,13 @@ module BlackStack
|
|
270
268
|
lname = BlackStack::Appending::cleanup_lname(name)
|
271
269
|
l.logf lname
|
272
270
|
|
273
|
-
BlackStack::Appending.find_persons(fname, lname, cname)
|
271
|
+
BlackStack::Appending.find_persons(fname, lname, cname, l)
|
274
272
|
end
|
275
273
|
|
276
274
|
# Find a person in the indexes by its first name, last name and company name.
|
277
275
|
# Append all the information in the index row.
|
278
|
-
def self.find_persons(fname, lname, cname)
|
279
|
-
l = BlackStack::
|
276
|
+
def self.find_persons(fname, lname, cname, l=nil)
|
277
|
+
l = BlackStack::DummyLogger.new if l.nil?
|
280
278
|
h = {
|
281
279
|
:matches => [],
|
282
280
|
:enlapsed_seconds => 0,
|
@@ -310,8 +308,8 @@ module BlackStack
|
|
310
308
|
|
311
309
|
# Find a company in the indexes by its first name, last name and company name.
|
312
310
|
# Append all the information in the index row.
|
313
|
-
def self.find_persons_by_company(cname)
|
314
|
-
l = BlackStack::
|
311
|
+
def self.find_persons_by_company(cname, l=nil)
|
312
|
+
l = BlackStack::DummyLogger.new if l.nil?
|
315
313
|
h = {
|
316
314
|
:matches => [],
|
317
315
|
:enlapsed_seconds => 0,
|
@@ -339,8 +337,8 @@ module BlackStack
|
|
339
337
|
h[:matches].map { |m| BlackStack::Appending::Result.new(m) }
|
340
338
|
end
|
341
339
|
|
342
|
-
def self.find_verified_emails_with_full_name(name, cname)
|
343
|
-
l = BlackStack::
|
340
|
+
def self.find_verified_emails_with_full_name(name, cname, l=nil)
|
341
|
+
l = BlackStack::DummyLogger.new if l.nil?
|
344
342
|
|
345
343
|
l.logs "Guessing fname from #{name}... "
|
346
344
|
fname = BlackStack::Appending::cleanup_fname(name)
|
@@ -350,25 +348,30 @@ module BlackStack
|
|
350
348
|
lname = BlackStack::Appending::cleanup_lname(name)
|
351
349
|
l.logf lname
|
352
350
|
|
353
|
-
BlackStack::Appending.find_verified_emails(fname, lname, cname)
|
351
|
+
BlackStack::Appending.find_verified_emails(fname, lname, cname, l)
|
354
352
|
end
|
355
353
|
|
356
|
-
def self.find_verified_emails(fname, lname, cname)
|
357
|
-
l = BlackStack::
|
354
|
+
def self.find_verified_emails(fname, lname, cname, l=nil)
|
355
|
+
l = BlackStack::DummyLogger.new if l.nil?
|
358
356
|
emails = []
|
359
357
|
domains = []
|
360
358
|
verified_emails = []
|
359
|
+
#
|
360
|
+
return verified_emails if cname =~ /Self.*employed/i
|
361
361
|
# get lead emails from in the indexes
|
362
362
|
l.logs ("Searching index emails... ")
|
363
|
-
emails = BlackStack::Appending.find_persons(fname, lname, cname).map { |res|
|
363
|
+
emails = BlackStack::Appending.find_persons(fname, lname, cname, l).map { |res|
|
364
364
|
res.emails
|
365
365
|
}.flatten.uniq.reject { |email|
|
366
366
|
email.to_s.empty?
|
367
|
-
}
|
368
|
-
|
367
|
+
}.uniq
|
368
|
+
# remove duplications
|
369
|
+
# IMPORTANT: be sure you have no spances, and no duplications, in order to don't repeat this issue https://github.com/leandrosardi/emails/issues/124
|
370
|
+
emails = emails.map { |email| email.to_s.downcase.strip }.uniq
|
371
|
+
l.logf "done (#{emails.to_s})"
|
369
372
|
# get company domains from the indexes
|
370
373
|
l.logs ("Searching index domains... ")
|
371
|
-
domains = BlackStack::Appending.find_persons_by_company(cname).map { |res|
|
374
|
+
domains = BlackStack::Appending.find_persons_by_company(cname, l).map { |res|
|
372
375
|
res.company_domains
|
373
376
|
}.flatten.reject { |email|
|
374
377
|
email.to_s.empty?
|
@@ -376,22 +379,54 @@ module BlackStack
|
|
376
379
|
# normalize domain
|
377
380
|
domain.to_s.gsub('www.', '').downcase
|
378
381
|
}.uniq
|
379
|
-
|
382
|
+
# remove duplications
|
383
|
+
# IMPORTANT: be sure you have no spances, and no duplications, in order to don't repeat this issue https://github.com/leandrosardi/emails/issues/124
|
384
|
+
domains = domains.map { |domain| domain.to_s.downcase.strip }.uniq
|
385
|
+
l.logf "done (#{domains.to_s})"
|
386
|
+
# add emails using fname and lname and company domains
|
387
|
+
# if the domain has not a catch-all address, then add all possible email variations to the array `emails`.
|
388
|
+
# if the domain has a catch-all address, then remove all emails with such a domain from the array `emails`.
|
389
|
+
l.logs ("Building list of candidates... ")
|
390
|
+
domains.each { |domain|
|
391
|
+
if !BlackStack::Appending.catch_all?(domain)
|
392
|
+
emails += [
|
393
|
+
"#{fname}@#{domain}",
|
394
|
+
"#{lname}@#{domain}",
|
395
|
+
"#{fname}.#{lname}@#{domain}",
|
396
|
+
"#{lname}.#{fname}@#{domain}",
|
397
|
+
"#{fname}#{lname}@#{domain}",
|
398
|
+
"#{lname}#{fname}@#{domain}",
|
399
|
+
"#{fname[0]}#{lname}@#{domain}",
|
400
|
+
"#{fname[0]}.#{lname}@#{domain}",
|
401
|
+
]
|
402
|
+
else
|
403
|
+
emails = emails.reject { |email| email =~ /@#{domain}$/ }
|
404
|
+
end
|
405
|
+
}
|
406
|
+
# delete duplicates
|
407
|
+
emails.uniq!
|
408
|
+
l.logf "done (#{emails.to_s})"
|
380
409
|
# verify all the emails found in the indexes
|
381
|
-
l.logs ("Verifying
|
410
|
+
l.logs ("Verifying emails... ")
|
382
411
|
emails.each { |email|
|
383
412
|
l.logs "Verifying #{email}... "
|
384
|
-
|
385
|
-
verified_emails << email if BlackStack::Appending.verify(email) && !BlackStack::Appending.catch_all?(domain)
|
413
|
+
verified_emails << email if BlackStack::Appending.verify(email)
|
386
414
|
l.done
|
415
|
+
# IMPORTANT: I added this line in order to resolve this issue https://github.com/leandrosardi/emails/issues/124
|
416
|
+
break if verified_emails.size > 0
|
387
417
|
}
|
388
418
|
l.done
|
389
|
-
#
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
419
|
+
# verify all the emails found in the indexes
|
420
|
+
# IMPORTANT: I added this double-check in order to don't repeat this issue https://github.com/leandrosardi/emails/issues/124
|
421
|
+
l.logs ("Double check emails... ")
|
422
|
+
verified_emails.each { |email|
|
423
|
+
l.logs "Double-checking #{email}... "
|
424
|
+
if BlackStack::Appending.verify(email)
|
425
|
+
l.logf 'keep'
|
426
|
+
else
|
427
|
+
verified_emails.delete(email)
|
428
|
+
l.logf "removed"
|
429
|
+
end
|
395
430
|
}
|
396
431
|
l.done
|
397
432
|
# return
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: appending
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leandro Daniel Sardi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: csv
|