appending 1.4 → 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 -51
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eaa340dc648f9c8e5eb15c6a871e7e2f4688aafa2c1674686351f71e32f0326b
4
- data.tar.gz: ca698fb7a9abcd78968a8fc0ea9d25352796052d5a2903a0b0c3cb732531aab7
3
+ metadata.gz: e018ab896cfc8ade090d1520b22241d6a6ff94af9680466ce659aa5ad6e7fb9b
4
+ data.tar.gz: 1d9ddd8428910b8085399bbcdbba8198cb05bdc112200714844c29a35bde0ff0
5
5
  SHA512:
6
- metadata.gz: 5f09789eb67bc56e93df692a7d63d0c41fea701297ab6691ee67a641b709927721bd2783a6c6915a33d18f8cebacbe635f534f49d5f0b9cc4bdbf45d7a9d4e1c
7
- data.tar.gz: e7a04a46cbecaeec589be05f29330ad40478fb16fc5516eea663b6edfbdf39dfd1cced15853b614d568704ecc1692086b1e145d60accf95e2c79595160e95920
6
+ metadata.gz: 721ec624c8fe4594ab7fff4aac354fbc0dafb1215abb5c5c51c88d942eb8929877fa4bfe85ae4b9f960166caee84bd480ba318c26b998d3b4b68dd4aa69c6539
7
+ data.tar.gz: 9a16c08e7ff289a88253b81dafe553aee4792672e4ac83c4325e554a9da743ddf9282f0ee13f9c4d5ce312694268882da2daad730d28aade85777c69268ec2d1
data/lib/appending.rb CHANGED
@@ -183,32 +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
- [
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
189
+ #parsed = JSON.parse(`curl --location --request GET '#{url}?email=#{email}' --header 'Content-Type: application/json'`)
190
+ parsed['status'] == 'success'
212
191
  end
213
192
 
214
193
  # This is a support method for the `append` methods.
@@ -259,8 +238,8 @@ module BlackStack
259
238
 
260
239
  # Find a person in the indexes by its full name and company name.
261
240
  # Append all the information in the index row.
262
- def self.find_persons_with_full_name(name, cname)
263
- 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?
264
243
 
265
244
  l.logs "Guessing fname from #{name}... "
266
245
  fname = BlackStack::Appending::cleanup_fname(name)
@@ -270,13 +249,13 @@ module BlackStack
270
249
  lname = BlackStack::Appending::cleanup_lname(name)
271
250
  l.logf lname
272
251
 
273
- BlackStack::Appending.find_persons(fname, lname, cname)
252
+ BlackStack::Appending.find_persons(fname, lname, cname, l)
274
253
  end
275
254
 
276
255
  # Find a person in the indexes by its first name, last name and company name.
277
256
  # Append all the information in the index row.
278
- def self.find_persons(fname, lname, cname)
279
- 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?
280
259
  h = {
281
260
  :matches => [],
282
261
  :enlapsed_seconds => 0,
@@ -310,8 +289,8 @@ module BlackStack
310
289
 
311
290
  # Find a company in the indexes by its first name, last name and company name.
312
291
  # Append all the information in the index row.
313
- def self.find_persons_by_company(cname)
314
- 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?
315
294
  h = {
316
295
  :matches => [],
317
296
  :enlapsed_seconds => 0,
@@ -339,8 +318,8 @@ module BlackStack
339
318
  h[:matches].map { |m| BlackStack::Appending::Result.new(m) }
340
319
  end
341
320
 
342
- def self.find_verified_emails_with_full_name(name, cname)
343
- 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?
344
323
 
345
324
  l.logs "Guessing fname from #{name}... "
346
325
  fname = BlackStack::Appending::cleanup_fname(name)
@@ -350,25 +329,27 @@ module BlackStack
350
329
  lname = BlackStack::Appending::cleanup_lname(name)
351
330
  l.logf lname
352
331
 
353
- BlackStack::Appending.find_verified_emails(fname, lname, cname)
332
+ BlackStack::Appending.find_verified_emails(fname, lname, cname, l)
354
333
  end
355
334
 
356
- def self.find_verified_emails(fname, lname, cname)
357
- 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?
358
337
  emails = []
359
338
  domains = []
360
339
  verified_emails = []
361
340
  # get lead emails from in the indexes
362
341
  l.logs ("Searching index emails... ")
363
- emails = BlackStack::Appending.find_persons(fname, lname, cname).map { |res|
342
+ emails = BlackStack::Appending.find_persons(fname, lname, cname, l).map { |res|
364
343
  res.emails
365
344
  }.flatten.uniq.reject { |email|
366
345
  email.to_s.empty?
367
- }
368
- 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})"
369
350
  # get company domains from the indexes
370
351
  l.logs ("Searching index domains... ")
371
- domains = BlackStack::Appending.find_persons_by_company(cname).map { |res|
352
+ domains = BlackStack::Appending.find_persons_by_company(cname, l).map { |res|
372
353
  res.company_domains
373
354
  }.flatten.reject { |email|
374
355
  email.to_s.empty?
@@ -376,22 +357,51 @@ module BlackStack
376
357
  # normalize domain
377
358
  domain.to_s.gsub('www.', '').downcase
378
359
  }.uniq
379
- 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})"
380
386
  # verify all the emails found in the indexes
381
- l.logs ("Verifying index emails... ")
387
+ l.logs ("Verifying emails... ")
382
388
  emails.each { |email|
383
389
  l.logs "Verifying #{email}... "
384
- domain = email.split('@').last
385
- verified_emails << email if BlackStack::Appending.verify(email) && !BlackStack::Appending.catch_all?(domain)
390
+ verified_emails << email if BlackStack::Appending.verify(email)
386
391
  l.done
392
+ break if verified_emails.size > 0
387
393
  }
388
394
  l.done
389
- # appending with domains found in the indexes
390
- l.logs ("Appending with domains... ")
391
- domains.each { |domain|
392
- l.logs "Appending with #{domain}... "
393
- verified_emails += BlackStack::Appending.append(fname, lname, domain)
394
- 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
395
405
  }
396
406
  l.done
397
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.4'
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