blackstack_commons 0.0.16 → 0.0.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/functions.rb +143 -0
  3. metadata +5 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5aca35493bf21923dc3c0479dc67ddb700d34541
4
- data.tar.gz: 7f8b76d7fe177684af3b961689852a7a33b4d07b
3
+ metadata.gz: a6ab4c21a6f6cf0ff81035fa7f09d0be05c113d4
4
+ data.tar.gz: 31141034849f46b3681e718d854d51b6bca10890
5
5
  SHA512:
6
- metadata.gz: 7c6eb8bc9526ee4c19181eb48fdc1deea4ed985a4f494ebd9f24915b7856ad732c15ab58ebfb009d88266dfff22f1e829dee5601a5c0438105859bb2d99ebe3a
7
- data.tar.gz: 6fe0d63b677c23fcd56cf58b02c88a8e0dbae38c1ae10854a4385dc19bb84b1fbf00476bf407616adf4c815932d39ee6c95ae6992bd210f9d576960b33810617
6
+ metadata.gz: a455c47b52c54b8d52919b8850593e7e2acb90c5300cb0580fb1e40301357481ac5473bdba81d6a6b302001b5a9f585f277f9248651b4256b89a6277eee470a2
7
+ data.tar.gz: 94893de40ffbc265b4a4246aa1d23a812ca7336ccea7aecc872ee172c1da97bcf84b4aad169360c9edf992b714b46d16c9d9d11deb87a6436ef8051a525a65c6
@@ -453,6 +453,7 @@ module BlackStack
453
453
  uri.query = URI.encode_www_form(params)
454
454
  Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https', :verify_mode => ssl_verify_mode) do |http|
455
455
  req = Net::HTTP::Get.new uri
456
+ #req.body = body if !body.nil?
456
457
  res = http.request req
457
458
  case res
458
459
  when Net::HTTPSuccess then res
@@ -470,6 +471,7 @@ module BlackStack
470
471
  req = Net::HTTP::Post.new(uri)
471
472
  req['Content-Type'] = 'application/json'
472
473
  req.set_form_data(params)
474
+ #req.body = body if !body.nil?
473
475
  res = http.request req
474
476
  case res
475
477
  when Net::HTTPSuccess then res
@@ -552,6 +554,147 @@ module BlackStack
552
554
  def self.file_age(filename)
553
555
  (Time.now - File.ctime(filename))/(24*3600)
554
556
  end
557
+
558
+
559
+ # TODO: Is not guaranteed this function works with 100% of the redirect-urls. This problem requires analysis and development of a general purpose algorith
560
+ # This function gets the final url from a redirect url.
561
+ # Not all the redirect-urls works the same way.
562
+ # Below are 3 examples. Each one works with 1 of the 2 strategies applied by this funcion.
563
+ # => url = "https://www.google.com.ar/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0CB0QFjAAahUKEwjCg8zMsNvGAhXMMj4KHWBfA50&url=https%3A%2F%2Fwww.linkedin.com%2Fpub%2Fdavid-bell%2F5%2F76a%2F12&ei=IGalVcLzFMzl-AHgvo3oCQ&usg=AFQjCNGMbF2vRIOWsRjF-bjjoG6Nl1wg_g&sig2=ZP6ZbZxpmTHw82rIP7YYew&bvm=bv.97653015,d.cWw"
564
+ # => url = "https://www.google.com.ar/url?q=https://www.linkedin.com/pub/mark-greene/2/bb8/b59&sa=U&ved=0CDoQFjAIahUKEwiqivi5sdvGAhWJg5AKHSzkB5o&usg=AFQjCNGE09H9hf92mfvwPVnComssDjBBCw"
565
+ # If the url is not a redirect-url, this function returns the same url.
566
+ =begin
567
+ def get_redirect(url)
568
+ begin
569
+ res = nil
570
+ httpc = HTTPClient.new
571
+ resp = httpc.get(url)
572
+ res = resp.header['Location']
573
+
574
+ if res.size == 0
575
+ uri = URI.parse(url)
576
+ uri_params = CGI.parse(uri.query)
577
+ redirected_url = uri_params['url'][0]
578
+
579
+ if ( redirected_url != nil )
580
+ res = redirected_url
581
+ else
582
+ res = url
583
+ end
584
+ else
585
+ res = res[0]
586
+ end
587
+ rescue
588
+ res = url
589
+ end
590
+ return res
591
+ end
592
+ =end
593
+ # returns a hash with the parametes in the url
594
+ def self.params(url)
595
+ # TODO: Corregir este parche:
596
+ # => El codigo de abajo usa la URL de una busqueda en google. Esta url generara una excepcion cuando se intenta parsear sus parametros.
597
+ # => Ejecutar las 2 lineas de abajo para verificar.
598
+ # => url = "https://www.google.com/webhp#q=[lead+generation]+%22John%22+%22Greater+New+York+City+Area+*+Financial+Services%22+site:linkedin.com%2Fpub+-site:linkedin.com%2Fpub%2Fdir"
599
+ # => p = CGI::parse(URI.parse(url).query)
600
+ # => La linea de abajo hace un gsbub que hace que esta url siga funcionando como busqueda de google, y ademas se posible parsearla.
601
+ url = url.gsub("webhp#q=", "webhp?q=")
602
+
603
+ return CGI::parse(URI.parse(url).query)
604
+ end
605
+
606
+ # Add a parameter to the url. It doesn't validate if the param already exists.
607
+ def self.add_param(url, param_name, param_value)
608
+ uri = URI(url)
609
+ params = URI.decode_www_form(uri.query || '')
610
+
611
+ if (params.size==0)
612
+ params << [param_name, param_value]
613
+ uri.query = URI.encode_www_form(params)
614
+ return uri.to_s
615
+ else
616
+ uri.query = URI.encode_www_form(params)
617
+ return uri.to_s + "&" + param_name + "=" + param_value
618
+ end
619
+ end
620
+
621
+ # Changes the value of a parameter in the url. It doesn't validate if the param already exists.
622
+ def self.change_param(url, param_name, param_value)
623
+ uri = URI(url)
624
+ # params = URI.decode_www_form(uri.query || [])
625
+ params = CGI.parse(uri.query)
626
+ params["start"] = param_value
627
+ uri.query = URI.encode_www_form(params)
628
+ uri.to_s
629
+ end
630
+
631
+ # Change or add the value of a parameter in the url, depending if the parameter already exists or not.
632
+ def self.set_param(url, param_name, param_value)
633
+ params = BlackStack::Netting::params(url)
634
+ if ( params.has_key?(param_name) == true )
635
+ newurl = BlackStack::Netting::change_param(url, param_name, param_value)
636
+ else
637
+ newurl = BlackStack::Netting::add_param(url, param_name, param_value)
638
+ end
639
+ return newurl
640
+ end
641
+
642
+ # get the domain from any url
643
+ def self.getDomainFromUrl(url)
644
+ if (url !~ /^http:\/\//i && url !~ /^https:\/\//i)
645
+ url = "http://#{url}"
646
+ end
647
+
648
+ if (URI.parse(url).host == nil)
649
+ raise "Cannot get domain for #{url}"
650
+ end
651
+
652
+ if (url.to_s.length>0)
653
+ return URI.parse(url).host.sub(/^www\./, '')
654
+ else
655
+ return nil
656
+ end
657
+ end
658
+
659
+ def self.getDomainFromEmail(email)
660
+ if email.email?
661
+ return email.split("@").last
662
+ else
663
+ raise "getDomainFromEmail: Wrong email format."
664
+ end
665
+ end
666
+
667
+ def self.getWhoisDomains(domain, allow_heuristic_to_avoid_hosting_companies=false)
668
+ a = Array.new
669
+ c = Whois::Client.new
670
+ r = c.lookup(domain)
671
+
672
+ res = r.to_s.scan(/Registrant Email: (#{BlackStack::Strings::MATCH_EMAIL})/).first
673
+ if (res!=nil)
674
+ a << BlackStack::Netting::getDomainFromEmail(res[0].downcase)
675
+ end
676
+
677
+ res = r.to_s.scan(/Admin Email: (#{BlackStack::Strings::MATCH_EMAIL})/).first
678
+ if (res!=nil)
679
+ a << BlackStack::Netting::getDomainFromEmail(res[0].downcase)
680
+ end
681
+
682
+ res = r.to_s.scan(/Tech Email: (#{BlackStack::Strings::MATCH_EMAIL})/).first
683
+ if (res!=nil)
684
+ a << BlackStack::Netting::getDomainFromEmail(res[0].downcase)
685
+ end
686
+
687
+ # remover duplicados
688
+ a = a.uniq
689
+
690
+ #
691
+ if (allow_heuristic_to_avoid_hosting_companies==true)
692
+ # TODO: develop this feature
693
+ end
694
+
695
+ return a
696
+ end
697
+
555
698
  end # module Netting
556
699
 
557
700
  end # module BlackStack
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blackstack_commons
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.20
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: 2019-11-15 00:00:00.000000000 Z
11
+ date: 2019-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: content_spinning
@@ -50,7 +50,7 @@ dependencies:
50
50
  - - ">="
51
51
  - !ruby/object:Gem::Version
52
52
  version: 1.8.1
53
- description: 'Find documentation here: https://github.com/leandrosardi/blackstack_commons.'
53
+ description: 'THIS GEM IS STILL IN DEVELOPMENT STAGE. Find documentation here: https://github.com/leandrosardi/blackstack_commons.'
54
54
  email: leandro.sardi@expandedventure.com
55
55
  executables: []
56
56
  extensions: []
@@ -89,5 +89,6 @@ rubyforge_project:
89
89
  rubygems_version: 2.4.5.1
90
90
  signing_key:
91
91
  specification_version: 4
92
- summary: Commons classes, functions and constants for the BlackStack framework.
92
+ summary: THIS GEM IS STILL IN DEVELOPMENT STAGE. Commons classes, functions and constants
93
+ for the BlackStack framework.
93
94
  test_files: []