blackstack_commons 1.1.33 → 1.1.39

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/extend_string.rb +9 -0
  3. data/lib/functions.rb +13 -11
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 96d14cd4096908b9904b488cb6d0b50f4ba46e1a
4
- data.tar.gz: 39cf2e762c291ca387e954efc5ce83919a61637a
3
+ metadata.gz: c8acfc5933e79875afb408c20432834ff6b53fe3
4
+ data.tar.gz: f6cc85064a417aadc4704d4b288a8b412647350b
5
5
  SHA512:
6
- metadata.gz: b9a3ac449388ea64b55f269397ec5dd304b54ab748b1e3aea83fdc731cabc552dc4e542996b96b7a058043c7622ded33a8ccc290aa12c736b2b1e7d2b323f934
7
- data.tar.gz: 4d61c4496735d814c33559705940998ae8cb6718ba35b6f8faddf5b64585328fd545d82bc39b825301925e883287aed6f5c0acb761a4e85830ba7d66442b909a
6
+ metadata.gz: ab382d63132e69f50a0c17f821f5672230e0deb75c6aebc8c9a95118cf194886a8a4cf80f8c40a227fd320b95a5a473093350c3a003ab9479a99c0135cd87682
7
+ data.tar.gz: d45eaf198ec84572d13ab34768ba4b596aee4ab30bd8bf0ad84ec159968527490b309ff059e94882df46c9aeb04b8c577428170e455c26fec3445691e19df7fb
@@ -108,4 +108,13 @@ class String
108
108
  BlackStack::Strings::Encoding::encode_html(self.to_s)
109
109
  end
110
110
 
111
+ # Escapes carriage returns and single and double quotes for JavaScript segments.
112
+ # reference: https://api.rubyonrails.org/classes/ActionView/Helpers/JavaScriptHelper.html
113
+ def escape_javascript
114
+ s = self.dup
115
+ js_escape_map = { '\\' => '\\\\', "</" => '<\/', "\r\n" => '\n', "\n" => '\n', "\r" => '\n', '"' => '\\"', "'" => "\\'", "`" => "\\`", "$" => "\\$" }
116
+ js_escape_map.each { | x, y | s.gsub!(x,y) }
117
+ s
118
+ end
119
+
111
120
  end # class String
@@ -16,7 +16,7 @@ module BlackStack
16
16
  # * https://stackoverflow.com/questions/8577223/ruby-get-the-file-being-executed
17
17
  # * https://stackoverflow.com/questions/7399882/ruby-getting-path-from-pathfilename/7400057
18
18
  #
19
- def self.require_in_working_path(filename, path,show_path_info=false)
19
+ def self.require_in_working_path(filename, path, show_path_info=false)
20
20
  puts '' if show_path_info
21
21
  path = File.expand_path File.dirname(path)
22
22
  #path = Dir.pwd
@@ -246,7 +246,7 @@ module BlackStack
246
246
  # units: it is a positive integer
247
247
  def self.encode_period(period, units)
248
248
  s = "Last "
249
- s += units.to_s + " " if units.to_i > 1
249
+ s += units.to_i.to_s + " " if units.to_i > 1
250
250
  s += "Hours" if period.upcase == "H" && units.to_i != 1
251
251
  s += "Days" if period.upcase == "D" && units.to_i != 1
252
252
  s += "Weeks" if period.upcase == "W" && units.to_i != 1
@@ -512,7 +512,7 @@ module BlackStack
512
512
  end
513
513
 
514
514
  # New call_get
515
- def self.call_get(url, params = {}, ssl_verify_mode=BlackStack::Netting::DEFAULT_SSL_VERIFY_MODE)
515
+ def self.call_get(url, params = {}, ssl_verify_mode=BlackStack::Netting::DEFAULT_SSL_VERIFY_MODE, support_redirections=true)
516
516
  uri = URI(url)
517
517
  uri.query = URI.encode_www_form(params)
518
518
  Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https', :verify_mode => ssl_verify_mode) do |http|
@@ -521,7 +521,7 @@ module BlackStack
521
521
  res = http.request req
522
522
  case res
523
523
  when Net::HTTPSuccess then res
524
- when Net::HTTPRedirection then BlackStack::Netting::call_get(URI(res['location']), params)
524
+ when Net::HTTPRedirection then BlackStack::Netting::call_get(URI(res['location']), params, false) if support_redirections
525
525
  else
526
526
  res.error!
527
527
  end
@@ -534,7 +534,8 @@ module BlackStack
534
534
  # ssl_verify_mode: you can disabele SSL verification here.
535
535
  # max_channels: this method use lockfiles to prevent an excesive number of API calls from each datacenter. There is not allowed more simultaneous calls than max_channels.
536
536
  # TODO: setup max_simultaneus_calls in the configurtion file.
537
- def self.call_post(url, params = {}, ssl_verify_mode=BlackStack::Netting::DEFAULT_SSL_VERIFY_MODE, use_lockfile=true)
537
+ def self.call_post(url, params = {}, ssl_verify_mode=BlackStack::Netting::DEFAULT_SSL_VERIFY_MODE, support_redirections=true)
538
+ =begin
538
539
  # build the lockfile name
539
540
  x = 0
540
541
  if BlackStack::Netting.max_api_call_channels.to_i > 0
@@ -543,9 +544,10 @@ module BlackStack
543
544
  # lock the file
544
545
  BlackStack::Netting.lockfiles[x].flock(File::LOCK_EX) if use_lockfile
545
546
  end
546
-
547
+ =end
547
548
  begin
548
-
549
+ #puts
550
+ #puts "call_post:#{url}:."
549
551
  # do the call
550
552
  uri = URI(url)
551
553
  ret = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https', :verify_mode => ssl_verify_mode) do |http|
@@ -556,23 +558,23 @@ module BlackStack
556
558
  res = http.request req
557
559
  case res
558
560
  when Net::HTTPSuccess then res
559
- when Net::HTTPRedirection then BlackStack::Netting::call_post(URI(res['location']), params, BlackStack::Netting::DEFAULT_SSL_VERIFY_MODE, false)
561
+ when Net::HTTPRedirection then BlackStack::Netting::call_post(URI(res['location']), params, BlackStack::Netting::DEFAULT_SSL_VERIFY_MODE, false) if support_redirections
560
562
  else
561
563
  res.error!
562
564
  end
563
565
  end
564
566
 
565
567
  # release the file
566
- BlackStack::Netting.lockfiles[x].flock(File::LOCK_UN) if use_lockfile && BlackStack::Netting.max_api_call_channels.to_i > 0
568
+ # BlackStack::Netting.lockfiles[x].flock(File::LOCK_UN) if use_lockfile && BlackStack::Netting.max_api_call_channels.to_i > 0
567
569
  rescue => e
568
570
  # release the file
569
- BlackStack::Netting.lockfiles[x].flock(File::LOCK_UN) if use_lockfile && BlackStack::Netting.max_api_call_channels.to_i > 0
571
+ # BlackStack::Netting.lockfiles[x].flock(File::LOCK_UN) if use_lockfile && BlackStack::Netting.max_api_call_channels.to_i > 0
570
572
 
571
573
  # elevo la excepcion
572
574
  raise e
573
575
  ensure
574
576
  # release the file
575
- BlackStack::Netting.lockfiles[x].flock(File::LOCK_UN) if use_lockfile && BlackStack::Netting.max_api_call_channels.to_i > 0
577
+ # BlackStack::Netting.lockfiles[x].flock(File::LOCK_UN) if use_lockfile && BlackStack::Netting.max_api_call_channels.to_i > 0
576
578
  end
577
579
 
578
580
  # return
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: 1.1.33
4
+ version: 1.1.39
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: 2020-05-24 00:00:00.000000000 Z
11
+ date: 2020-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: content_spinning