blackstack_commons 1.1.26 → 1.1.28

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 +29 -20
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1cc95c11625700337bb0e751d017c74576e88928
4
- data.tar.gz: 2d59f66329d8a08b2a8ed24df9daa5d86e0f0b5f
3
+ metadata.gz: b57115faaf3a00b4a0cc954244de3d33fa9b00fa
4
+ data.tar.gz: 58107d6e5250b684e336d02bac25e8790599ac60
5
5
  SHA512:
6
- metadata.gz: b497184aa100f95b4e5339f67d7a3f82ef15554467c785f98eb41342b2c0644bf30d7ad12b37c8432601e7d4b9e3e6ece79b83193601a93f0a804447c5dd36b1
7
- data.tar.gz: 53b0926d2ccc8697d9702bec33ad63fc7ab89b4f691f24d5937f4cb1f422bf839548b361ef2e940f95b367c872f29b40633a56c47aaaa4764771c46e9166326c
6
+ metadata.gz: ecc986a230a3bd4bc56c59c5240349ecb887cf4ed84656dab07b4cc2196a859eccf66f5bdb513727bc806627f63cb515f345aa42a53c369c4d3f95087f385993
7
+ data.tar.gz: 1f9ddbcc4429c33a55643a8379f60f169379343b2841f06c3b1abfa634b5ea2496ea28a8458c88e0e7fd988e6658c4b626fef9e5ef88eee143fb5aa4167938ad
data/lib/functions.rb CHANGED
@@ -1,20 +1,27 @@
1
+
1
2
  module BlackStack
2
3
 
3
- # This method does a require of the config.rb that must then then
4
- # ruby script that is running, or where an .exe file genrated by
5
- # OCRA is running.
6
- #
7
- # When you run an OCRA .exe file, such .exe will unpackage the ruby
8
- # script in a temporal folder. So any require will look for conf.rb
9
- # into the temporal folder.
10
- #
11
- # This function resolves that problem, by forcing the require to look
12
- # into the folder where the .exe command is hosted.
13
- #
14
- def self.require_local(source_dir, filename='config.rb')
15
- source_dir = File.expand_path('..', source_dir)
16
- require File.expand_path('config', source_dir)
17
- end
4
+ # -----------------------------------------------------------------------------------------
5
+ # OCRA Supporting Functions
6
+ # -----------------------------------------------------------------------------------------
7
+ module OCRA
8
+ # OCRA files run into a temp folder, where the script is unpacked.
9
+ #
10
+ # This function is useful to require a configuration file when the
11
+ # script is running inside an OCRA temp folder, since the local folder
12
+ # of the running command is not the filder where the exe file is hosted.
13
+ #
14
+ # More information: https://stackoverflow.com/questions/1937743/how-to-get-the-current-working-directorys-absolute-path-from-irb
15
+ #
16
+ def self.require_in_working_path(filename, show_path_info=false)
17
+ puts '' if show_path_info
18
+ path = File.expand_path File.dirname(__FILE__)
19
+ puts "require_in_working_path.path:#{path}:." if show_path_info
20
+ file = "#{path}/#{filename}"
21
+ puts "require_in_working_path.file:#{file}:." if show_path_info
22
+ require file
23
+ end
24
+ end # module OCRA
18
25
 
19
26
  # -----------------------------------------------------------------------------------------
20
27
  # DateTime Functions
@@ -523,18 +530,18 @@ module BlackStack
523
530
  # ssl_verify_mode: you can disabele SSL verification here.
524
531
  # 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.
525
532
  # TODO: setup max_simultaneus_calls in the configurtion file.
526
- def self.call_post(url, params = {}, ssl_verify_mode=BlackStack::Netting::DEFAULT_SSL_VERIFY_MODE, use_lockfile=true, allow_redirection=true)
533
+ def self.call_post(url, params = {}, ssl_verify_mode=BlackStack::Netting::DEFAULT_SSL_VERIFY_MODE, use_lockfile=true)
527
534
  # build the lockfile name
528
535
  x = 0
529
-
530
536
  if BlackStack::Netting.max_api_call_channels.to_i > 0
531
537
  raise "Max Channels cannot be higher than #{BlackStack::Netting.lockfiles.size.to_s}" if BlackStack::Netting.max_api_call_channels > BlackStack::Netting.lockfiles.size
532
538
  x = rand(BlackStack::Netting.max_api_call_channels)
533
539
  # lock the file
534
540
  BlackStack::Netting.lockfiles[x].flock(File::LOCK_EX) if use_lockfile
535
541
  end
536
-
542
+
537
543
  begin
544
+
538
545
  # do the call
539
546
  uri = URI(url)
540
547
  ret = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https', :verify_mode => ssl_verify_mode) do |http|
@@ -545,23 +552,25 @@ module BlackStack
545
552
  res = http.request req
546
553
  case res
547
554
  when Net::HTTPSuccess then res
548
- when Net::HTTPRedirection then
549
- BlackStack::Netting::call_post(URI(res['location']), params, BlackStack::Netting::DEFAULT_SSL_VERIFY_MODE, false, false) if allow_redirection
555
+ when Net::HTTPRedirection then BlackStack::Netting::call_post(URI(res['location']), params, BlackStack::Netting::DEFAULT_SSL_VERIFY_MODE, false)
550
556
  else
551
557
  res.error!
552
558
  end
553
559
  end
560
+
554
561
  # release the file
555
562
  BlackStack::Netting.lockfiles[x].flock(File::LOCK_UN) if use_lockfile && BlackStack::Netting.max_api_call_channels.to_i > 0
556
563
  rescue => e
557
564
  # release the file
558
565
  BlackStack::Netting.lockfiles[x].flock(File::LOCK_UN) if use_lockfile && BlackStack::Netting.max_api_call_channels.to_i > 0
566
+
559
567
  # elevo la excepcion
560
568
  raise e
561
569
  ensure
562
570
  # release the file
563
571
  BlackStack::Netting.lockfiles[x].flock(File::LOCK_UN) if use_lockfile && BlackStack::Netting.max_api_call_channels.to_i > 0
564
572
  end
573
+
565
574
  # return
566
575
  ret
567
576
  end
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.26
4
+ version: 1.1.28
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-06 00:00:00.000000000 Z
11
+ date: 2020-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: content_spinning