appending 1.3 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/appending.rb +61 -54
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6aba4c7137d9bb38b7745f054b0682ee73f6f205a16a36d7a606e90d3d5b1bf7
4
- data.tar.gz: 3511f4baef20d5894233963cc64c4345c2d50aa25b7ecf6b0389711fa75d236b
3
+ metadata.gz: e018ab896cfc8ade090d1520b22241d6a6ff94af9680466ce659aa5ad6e7fb9b
4
+ data.tar.gz: 1d9ddd8428910b8085399bbcdbba8198cb05bdc112200714844c29a35bde0ff0
5
5
  SHA512:
6
- metadata.gz: b97ace460781406e62d594a3be139d417d6627720d210bc4e41860e3bc95572d6802a734a550cd181aa0ecd8e1a7e8623fed8f2a901f38d1f821c722c4d4cec6
7
- data.tar.gz: bc607df66c32d6ef1de92d5c3a90bf5df2de10b280adb2da6db9bddae34405fed7d7d1160825e97197080ac4f9002868b081c3d191441f5147e60b0be4d1397d
6
+ metadata.gz: 721ec624c8fe4594ab7fff4aac354fbc0dafb1215abb5c5c51c88d942eb8929877fa4bfe85ae4b9f960166caee84bd480ba318c26b998d3b4b68dd4aa69c6539
7
+ data.tar.gz: 9a16c08e7ff289a88253b81dafe553aee4792672e4ac83c4325e554a9da743ddf9282f0ee13f9c4d5ce312694268882da2daad730d28aade85777c69268ec2d1
data/lib/appending.rb CHANGED
@@ -183,35 +183,11 @@ module BlackStack
183
183
  params = {
184
184
  :email => email,
185
185
  }
186
- res = BlackStack::Netting::call_get(url, params)
186
+ # send HTTP-GET request to @@verifier_url, using the standard HTTP module
187
+ res = Net::HTTP.get_response(URI.parse("#{url}?email=#{params[:email]}"))
187
188
  parsed = JSON.parse(res.body)
188
- parsed['status'] == 'success'
189
- end
190
-
191
- # verify an email address
192
- def self.append(fname, lname, domain)
193
- ret = []
194
- if !catch_all?(domain)
195
- EmailVerifier.config do |config|
196
- config.verifier_email = "leandro.sardi@expandedventure.com"
197
- end
198
- [
199
- "#{fname}@#{domain}",
200
- "#{lname}@#{domain}",
201
-
202
- "#{fname}.#{lname}@#{domain}",
203
- "#{lname}.#{fname}@#{domain}",
204
-
205
- "#{fname}#{lname}@#{domain}",
206
- "#{lname}#{fname}@#{domain}",
207
-
208
- "#{fname[0]}#{lname}@#{domain}",
209
- "#{fname[0]}.#{lname}@#{domain}",
210
- ].each { |email|
211
- ret << email.downcase if verify(email)
212
- }
213
- end
214
- ret
189
+ #parsed = JSON.parse(`curl --location --request GET '#{url}?email=#{email}' --header 'Content-Type: application/json'`)
190
+ parsed['status'] == 'success'
215
191
  end
216
192
 
217
193
  # This is a support method for the `append` methods.
@@ -262,8 +238,8 @@ module BlackStack
262
238
 
263
239
  # Find a person in the indexes by its full name and company name.
264
240
  # Append all the information in the index row.
265
- def self.find_persons_with_full_name(name, cname)
266
- l = BlackStack::Appending.logger || BlackStack::DummyLogger.new
241
+ def self.find_persons_with_full_name(name, cname, l=nil)
242
+ l = BlackStack::DummyLogger.new if l.nil?
267
243
 
268
244
  l.logs "Guessing fname from #{name}... "
269
245
  fname = BlackStack::Appending::cleanup_fname(name)
@@ -273,13 +249,13 @@ module BlackStack
273
249
  lname = BlackStack::Appending::cleanup_lname(name)
274
250
  l.logf lname
275
251
 
276
- BlackStack::Appending.find_persons(fname, lname, cname)
252
+ BlackStack::Appending.find_persons(fname, lname, cname, l)
277
253
  end
278
254
 
279
255
  # Find a person in the indexes by its first name, last name and company name.
280
256
  # Append all the information in the index row.
281
- def self.find_persons(fname, lname, cname)
282
- l = BlackStack::Appending.logger || BlackStack::DummyLogger.new
257
+ def self.find_persons(fname, lname, cname, l=nil)
258
+ l = BlackStack::DummyLogger.new if l.nil?
283
259
  h = {
284
260
  :matches => [],
285
261
  :enlapsed_seconds => 0,
@@ -313,8 +289,8 @@ module BlackStack
313
289
 
314
290
  # Find a company in the indexes by its first name, last name and company name.
315
291
  # Append all the information in the index row.
316
- def self.find_persons_by_company(cname)
317
- l = BlackStack::Appending.logger || BlackStack::DummyLogger.new
292
+ def self.find_persons_by_company(cname, l=nil)
293
+ l = BlackStack::DummyLogger.new if l.nil?
318
294
  h = {
319
295
  :matches => [],
320
296
  :enlapsed_seconds => 0,
@@ -342,8 +318,8 @@ module BlackStack
342
318
  h[:matches].map { |m| BlackStack::Appending::Result.new(m) }
343
319
  end
344
320
 
345
- def self.find_verified_emails_with_full_name(name, cname)
346
- l = BlackStack::Appending.logger || BlackStack::DummyLogger.new
321
+ def self.find_verified_emails_with_full_name(name, cname, l=nil)
322
+ l = BlackStack::DummyLogger.new if l.nil?
347
323
 
348
324
  l.logs "Guessing fname from #{name}... "
349
325
  fname = BlackStack::Appending::cleanup_fname(name)
@@ -353,25 +329,27 @@ module BlackStack
353
329
  lname = BlackStack::Appending::cleanup_lname(name)
354
330
  l.logf lname
355
331
 
356
- BlackStack::Appending.find_verified_emails(fname, lname, cname)
332
+ BlackStack::Appending.find_verified_emails(fname, lname, cname, l)
357
333
  end
358
334
 
359
- def self.find_verified_emails(fname, lname, cname)
360
- l = BlackStack::Appending.logger || BlackStack::DummyLogger.new
335
+ def self.find_verified_emails(fname, lname, cname, l=nil)
336
+ l = BlackStack::DummyLogger.new if l.nil?
361
337
  emails = []
362
338
  domains = []
363
339
  verified_emails = []
364
340
  # get lead emails from in the indexes
365
341
  l.logs ("Searching index emails... ")
366
- emails = BlackStack::Appending.find_persons(fname, lname, cname).map { |res|
342
+ emails = BlackStack::Appending.find_persons(fname, lname, cname, l).map { |res|
367
343
  res.emails
368
344
  }.flatten.uniq.reject { |email|
369
345
  email.to_s.empty?
370
- }
371
- l.done
346
+ }.uniq
347
+ # remove duplications
348
+ emails = emails.map { |email| email.to_s.downcase.strip }.uniq
349
+ l.logf "done (#{emails.to_s})"
372
350
  # get company domains from the indexes
373
351
  l.logs ("Searching index domains... ")
374
- domains = BlackStack::Appending.find_persons_by_company(cname).map { |res|
352
+ domains = BlackStack::Appending.find_persons_by_company(cname, l).map { |res|
375
353
  res.company_domains
376
354
  }.flatten.reject { |email|
377
355
  email.to_s.empty?
@@ -379,22 +357,51 @@ module BlackStack
379
357
  # normalize domain
380
358
  domain.to_s.gsub('www.', '').downcase
381
359
  }.uniq
382
- l.done
360
+ # remove duplications
361
+ domains = domains.map { |domain| domain.to_s.downcase.strip }.uniq
362
+ l.logf "done (#{domains.to_s})"
363
+ # add emails using fname and lname and company domains
364
+ # if the domain has not a catch-all address, then add all possible email variations to the array `emails`.
365
+ # if the domain has a catch-all address, then remove all emails with such a domain from the array `emails`.
366
+ l.logs ("Building list of candidates... ")
367
+ domains.each { |domain|
368
+ if !BlackStack::Appending.catch_all?(domain)
369
+ emails += [
370
+ "#{fname}@#{domain}",
371
+ "#{lname}@#{domain}",
372
+ "#{fname}.#{lname}@#{domain}",
373
+ "#{lname}.#{fname}@#{domain}",
374
+ "#{fname}#{lname}@#{domain}",
375
+ "#{lname}#{fname}@#{domain}",
376
+ "#{fname[0]}#{lname}@#{domain}",
377
+ "#{fname[0]}.#{lname}@#{domain}",
378
+ ]
379
+ else
380
+ emails = emails.reject { |email| email =~ /@#{domain}$/ }
381
+ end
382
+ }
383
+ # delete duplicates
384
+ emails.uniq!
385
+ l.logf "done (#{emails.to_s})"
383
386
  # verify all the emails found in the indexes
384
- l.logs ("Verifying index emails... ")
387
+ l.logs ("Verifying emails... ")
385
388
  emails.each { |email|
386
389
  l.logs "Verifying #{email}... "
387
- domain = email.split('@').last
388
- verified_emails << email if BlackStack::Appending.verify(email) && !BlackStack::Appending.catch_all?(domain)
390
+ verified_emails << email if BlackStack::Appending.verify(email)
389
391
  l.done
392
+ break if verified_emails.size > 0
390
393
  }
391
394
  l.done
392
- # appending with domains found in the indexes
393
- l.logs ("Appending with domains... ")
394
- domains.each { |domain|
395
- l.logs "Appending with #{domain}... "
396
- verified_emails += BlackStack::Appending.append(fname, lname, domain)
397
- l.done
395
+ # verify all the emails found in the indexes
396
+ l.logs ("Double check emails... ")
397
+ verified_emails.each { |email|
398
+ l.logs "Double-checking #{email}... "
399
+ if BlackStack::Appending.verify(email)
400
+ l.logf 'keep'
401
+ else
402
+ verified_emails.delete(email)
403
+ l.logf "removed"
404
+ end
398
405
  }
399
406
  l.done
400
407
  # 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: '1.3'
4
+ version: 1.4.2
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: 2022-12-20 00:00:00.000000000 Z
11
+ date: 2023-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: csv