blackstack_commons 1.1.1 → 1.1.3

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/functions.rb +23 -3
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b16eddbef98aff39c1cb81554010dbdc60de5472
4
- data.tar.gz: bcf83e2ac13d78fef9f6ad4b3e2cce9697ade899
3
+ metadata.gz: 7f7a293a50e22ed06866076eecefe468960dc91b
4
+ data.tar.gz: 616e25fdc589bef581450cfd07e19efebadd5705
5
5
  SHA512:
6
- metadata.gz: 72205392a13372b1d4fc1c849d5b53f73e38b005c0252cc5867e8c685b8631429922d3b28eab47dacb1f691f94cd8c35daebe799c40aa16d2b16187bee4a3b26
7
- data.tar.gz: ec39230b49470fe1de49e3e549251163f42040bd66b64ee14eefa75f52c3d7080723750c1f52bec074b4c751883ff3146edf578de00c01ea7466587161dc0ba5
6
+ metadata.gz: 4927a8ebeaf4508b041ed442ba55f048c8f21845066528ffcdb8c6afbf8f7435ee68444b5866f8b43cd0376cc4813f5d83453a60c4e1d41afbdbef78055ff2f5
7
+ data.tar.gz: 3375ec35d1b820b61139b473015521d781ceb855c694d7aaf5b72cf18e6bbdd3a851963ea755f4c4658c4c5e467aa1bc9808ee47f0697c845818f7b88cff3bac
data/lib/functions.rb CHANGED
@@ -476,10 +476,24 @@ module BlackStack
476
476
  end
477
477
  end
478
478
 
479
- # New call_post
480
- def self.call_post(url, params = {}, ssl_verify_mode=BlackStack::Netting::DEFAULT_SSL_VERIFY_MODE)
479
+ # Call the API and return th result.
480
+ # url: valid internet address
481
+ # params: hash of params to attach in the call
482
+ # ssl_verify_mode: you can disabele SSL verification here.
483
+ # 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.
484
+ # TODO: setup max_simultaneus_calls in the configurtion file.
485
+ def self.call_post(url, params = {}, ssl_verify_mode=BlackStack::Netting::DEFAULT_SSL_VERIFY_MODE, max_channels=10)
486
+ # build the lockfile name
487
+ x = rand(max_channels.to_i)
488
+ lockfilename = "./apicall.channel_{x.to_s}.lock"
489
+ lockfile = File.open(lockfilename, "w")
490
+
491
+ # lock the file
492
+ lockfile.flock(File::LOCK_EX)
493
+
494
+ # do the call
481
495
  uri = URI(url)
482
- Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https', :verify_mode => ssl_verify_mode) do |http|
496
+ ret = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https', :verify_mode => ssl_verify_mode) do |http|
483
497
  req = Net::HTTP::Post.new(uri)
484
498
  req['Content-Type'] = 'application/json'
485
499
  req.set_form_data(params)
@@ -492,6 +506,12 @@ module BlackStack
492
506
  res.error!
493
507
  end
494
508
  end
509
+
510
+ # release the file
511
+ lockfile.flock(File::LOCK_UN)
512
+
513
+ # return
514
+ ret
495
515
  end
496
516
 
497
517
  #
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.1
4
+ version: 1.1.3
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-01-02 00:00:00.000000000 Z
11
+ date: 2020-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: content_spinning