blackstack-core 1.2.29 → 1.2.30
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.
- checksums.yaml +4 -4
- data/examples/example01.rb +0 -0
- data/examples/example02.rb +0 -0
- data/lib/blackstack-core.rb +0 -0
- data/lib/extend_datetime.rb +0 -0
- data/lib/extend_exception.rb +0 -0
- data/lib/extend_fixnum.rb +0 -0
- data/lib/extend_float.rb +0 -0
- data/lib/extend_string.rb +0 -0
- data/lib/extend_time.rb +0 -0
- data/lib/functions.rb +80 -25
- metadata +3 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6319585aa6afd55c363b5b7e59acc4afe407a741d22306831b3c5cef48724c76
|
4
|
+
data.tar.gz: 2d7e134595693737c9beb9cfabaf05ac502a7631a79bafbbb5b60ae03cd90512
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6d4de6e017a5871b60a1d1f3a987e9233ac2df83700ba3d794ddf843f5ffd3ec30de9efd4544eb4415e4f9381898826dd80647d8250c89d6d0f3001c38355ed
|
7
|
+
data.tar.gz: 3e8c922cb98658ef9677b4e5badb5e4592f112b71d6a76d79ac59361f19cfbb0ad94558bbaea5a6ad99493a876eda33f224ccdde11e0cebc4d4e09716a70c0a7
|
data/examples/example01.rb
CHANGED
File without changes
|
data/examples/example02.rb
CHANGED
File without changes
|
data/lib/blackstack-core.rb
CHANGED
File without changes
|
data/lib/extend_datetime.rb
CHANGED
File without changes
|
data/lib/extend_exception.rb
CHANGED
File without changes
|
data/lib/extend_fixnum.rb
CHANGED
File without changes
|
data/lib/extend_float.rb
CHANGED
File without changes
|
data/lib/extend_string.rb
CHANGED
File without changes
|
data/lib/extend_time.rb
CHANGED
File without changes
|
data/lib/functions.rb
CHANGED
@@ -862,6 +862,10 @@ module BlackStack
|
|
862
862
|
DEFAULT_SSL_VERIFY_MODE = OpenSSL::SSL::VERIFY_NONE
|
863
863
|
SUCCESS = 'success'
|
864
864
|
|
865
|
+
DEFAULT_OPEN_TIMEOUT = 10 # seconds to wait for the initial connection
|
866
|
+
DEFAULT_READ_TIMEOUT = 30 # seconds to wait for each response
|
867
|
+
DEFAULT_RETRY_ATTEMPTS = 3
|
868
|
+
|
865
869
|
@@lockfiles = []
|
866
870
|
|
867
871
|
@@max_api_call_channels = 0 # 0 means infinite
|
@@ -927,32 +931,83 @@ module BlackStack
|
|
927
931
|
#
|
928
932
|
# TODO: parameter support_redirections has been deprecated.
|
929
933
|
#
|
930
|
-
def self.call_post(url,
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
934
|
+
def self.call_post(url,
|
935
|
+
body = {},
|
936
|
+
ssl_verify_mode = BlackStack::Netting::DEFAULT_SSL_VERIFY_MODE,
|
937
|
+
support_redirections = true)
|
938
|
+
|
939
|
+
max_redirects = 5
|
940
|
+
attempts = 0
|
941
|
+
|
942
|
+
while attempts < DEFAULT_RETRY_ATTEMPTS
|
943
|
+
begin
|
944
|
+
uri = URI.parse(url)
|
945
|
+
|
946
|
+
# Create a basic Faraday connection
|
947
|
+
conn = Faraday.new(
|
948
|
+
url: "#{uri.scheme}://#{uri.host}",
|
949
|
+
ssl: { verify: ssl_verify_mode != OpenSSL::SSL::VERIFY_NONE },
|
950
|
+
request: {
|
951
|
+
open_timeout: DEFAULT_OPEN_TIMEOUT,
|
952
|
+
timeout: DEFAULT_READ_TIMEOUT
|
953
|
+
}
|
954
|
+
) do |f|
|
955
|
+
f.adapter Faraday.default_adapter
|
956
|
+
end
|
957
|
+
|
958
|
+
# Perform the initial POST request
|
959
|
+
response = conn.post(uri.path) do |req|
|
960
|
+
req.body = JSON.generate(body) # Manually serialize to JSON
|
961
|
+
req.headers['Content-Type'] = 'application/json'
|
962
|
+
req.headers['Accept'] = 'application/json'
|
963
|
+
end
|
964
|
+
|
965
|
+
# Manually handle HTTP redirects if requested
|
966
|
+
redirect_count = 0
|
967
|
+
while support_redirections &&
|
968
|
+
response.status.between?(300, 399) &&
|
969
|
+
response.headers['location'] &&
|
970
|
+
redirect_count < max_redirects
|
971
|
+
|
972
|
+
redirect_count += 1
|
973
|
+
new_url = URI.join(url, response.headers['location']).to_s
|
974
|
+
|
975
|
+
# Update `url` for the next iteration
|
976
|
+
url = new_url
|
977
|
+
uri = URI.parse(new_url)
|
978
|
+
|
979
|
+
response = conn.post(uri.path) do |req|
|
980
|
+
req.body = JSON.generate(body)
|
981
|
+
req.headers['Content-Type'] = 'application/json'
|
982
|
+
req.headers['Accept'] = 'application/json'
|
983
|
+
end
|
984
|
+
end
|
985
|
+
|
986
|
+
# Raise an error if the final response is not 2xx
|
987
|
+
unless response.success?
|
988
|
+
raise "HTTP #{response.status}: #{response.body}"
|
989
|
+
end
|
990
|
+
|
991
|
+
# If all is good, return the Faraday response object
|
992
|
+
return response
|
993
|
+
|
994
|
+
rescue Errno::ETIMEDOUT, Timeout::Error, Faraday::ConnectionFailed => e
|
995
|
+
# Basic retry logic for transient network errors
|
996
|
+
attempts += 1
|
997
|
+
if attempts < DEFAULT_RETRY_ATTEMPTS
|
998
|
+
sleep_time = 2**attempts
|
999
|
+
sleep(sleep_time) # Exponential backoff
|
1000
|
+
retry
|
1001
|
+
else
|
1002
|
+
# Too many failures, re-raise
|
1003
|
+
raise e
|
1004
|
+
end
|
1005
|
+
rescue => e
|
1006
|
+
# For any other error, just re-raise
|
1007
|
+
raise e
|
1008
|
+
end
|
953
1009
|
end
|
954
|
-
|
955
|
-
end
|
1010
|
+
end # def self.call_post
|
956
1011
|
|
957
1012
|
# TODO: deprecated
|
958
1013
|
def self.api_call(url, params={}, method=BlackStack::Netting::CALL_METHOD_POST, ssl_verify_mode=BlackStack::Netting::DEFAULT_SSL_VERIFY_MODE, max_retries=5)
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blackstack-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.30
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leandro Daniel Sardi
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date: 2025-01-
|
10
|
+
date: 2025-01-30 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: content_spinning
|
@@ -86,7 +85,6 @@ homepage: https://rubygems.org/gems/blackstack-core
|
|
86
85
|
licenses:
|
87
86
|
- MIT
|
88
87
|
metadata: {}
|
89
|
-
post_install_message:
|
90
88
|
rdoc_options: []
|
91
89
|
require_paths:
|
92
90
|
- lib
|
@@ -101,8 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
99
|
- !ruby/object:Gem::Version
|
102
100
|
version: '0'
|
103
101
|
requirements: []
|
104
|
-
rubygems_version: 3.3
|
105
|
-
signing_key:
|
102
|
+
rubygems_version: 3.6.3
|
106
103
|
specification_version: 4
|
107
104
|
summary: Core modules, functions and constants for the BlackStack framework.
|
108
105
|
test_files: []
|