restful_client 1.0.0 → 1.1.0
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 +5 -5
- data/.travis.yml +1 -1
- data/lib/restful_client.rb +16 -8
- data/restful_client.gemspec +1 -1
- metadata +6 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: fb2e3bbbe3c0e81b0449b9dc0231ee925fe14c8fecae5918cebf181974addb18
|
|
4
|
+
data.tar.gz: 22c1095b54d3375e20fcd229e6ffcb79cebc2bfa4a4118947f114f3ef92d0e3c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6ca3fbc03892cc5a7c0eb238d5a01f1f0419f3c3a025c670a18c1ca10ad455c1dbd92e32f1df56c9e254b5b894441825cccac5df3a1c7c232facad2fa5384aa9
|
|
7
|
+
data.tar.gz: d85e49990eeaf1973aebf1334ecd82c7556bfc78fa5102b300cb6a0d564b4dcf0a9f618210cf6e0c63c517067fc8d03bb07c80a4b08f79b8c6f9b470250283f8
|
data/.travis.yml
CHANGED
data/lib/restful_client.rb
CHANGED
|
@@ -41,7 +41,7 @@ module RestfulClient
|
|
|
41
41
|
url = RestfulClientUri.uri_join(callerr_config(caller)['url'], path)
|
|
42
42
|
headers = { 'Accept' => 'application/json' }
|
|
43
43
|
headers.merge!(extra.fetch('headers', {}))
|
|
44
|
-
request_args = { headers: headers, method: 'GET', timeout:
|
|
44
|
+
request_args = { headers: headers, method: 'GET', timeout: timeout_for(caller), params: params }.merge(extra.fetch('args', {}))
|
|
45
45
|
request = Typhoeus::Request.new(url, request_args.merge(extra.fetch('args', {})))
|
|
46
46
|
run_safe_request(caller, request, true, &on_error_block)
|
|
47
47
|
end
|
|
@@ -49,7 +49,7 @@ module RestfulClient
|
|
|
49
49
|
def post(caller, path, payload, extra = {}, &on_error_block)
|
|
50
50
|
url = RestfulClientUri.uri_join(callerr_config(caller)['url'], path)
|
|
51
51
|
headers, payload_as_str = prepare_payload_with_headers(payload, extra.fetch('headers', {}))
|
|
52
|
-
request_args = { headers: headers, method: 'POST', body: payload_as_str, timeout:
|
|
52
|
+
request_args = { headers: headers, method: 'POST', body: payload_as_str, timeout: timeout_for(caller) }
|
|
53
53
|
request = Typhoeus::Request.new(url, request_args.merge(extra.fetch('args', {})))
|
|
54
54
|
run_safe_request(caller, request, false, &on_error_block)
|
|
55
55
|
end
|
|
@@ -57,7 +57,7 @@ module RestfulClient
|
|
|
57
57
|
def delete(caller, path, payload = {}, extra = {}, &on_error_block)
|
|
58
58
|
url = RestfulClientUri.uri_join(callerr_config(caller)['url'], path)
|
|
59
59
|
headers, payload_as_str = prepare_payload_with_headers(payload, extra.fetch('headers', {}))
|
|
60
|
-
request_args = { headers: headers, method: 'DELETE', body: payload_as_str, timeout:
|
|
60
|
+
request_args = { headers: headers, method: 'DELETE', body: payload_as_str, timeout: timeout_for(caller) }
|
|
61
61
|
request = Typhoeus::Request.new(url, request_args.merge(extra.fetch('args', {})))
|
|
62
62
|
run_safe_request(caller, request, true, &on_error_block)
|
|
63
63
|
end
|
|
@@ -65,7 +65,7 @@ module RestfulClient
|
|
|
65
65
|
def put(caller, path, payload, extra = {}, &on_error_block)
|
|
66
66
|
url = RestfulClientUri.uri_join(callerr_config(caller)['url'], path)
|
|
67
67
|
headers, payload_as_str = prepare_payload_with_headers(payload, extra.fetch('headers', {}))
|
|
68
|
-
request = Typhoeus::Request.new(url, headers: headers, method: 'PUT', body: payload_as_str, timeout:
|
|
68
|
+
request = Typhoeus::Request.new(url, headers: headers, method: 'PUT', body: payload_as_str, timeout: timeout_for(caller))
|
|
69
69
|
run_safe_request(caller, request, false, &on_error_block)
|
|
70
70
|
end
|
|
71
71
|
|
|
@@ -78,10 +78,10 @@ module RestfulClient
|
|
|
78
78
|
def run_safe_request(caller, request, retry_if_needed, &on_error_block)
|
|
79
79
|
@@timeout_occured_count = 0
|
|
80
80
|
if !use_jynx?
|
|
81
|
-
response = run_request(request.dup, __method__, false)
|
|
81
|
+
response = run_request(request.dup, __method__, false, caller)
|
|
82
82
|
elsif ServiceJynx.alive?(caller)
|
|
83
83
|
begin
|
|
84
|
-
response = run_request(request.dup, __method__, retry_if_needed)
|
|
84
|
+
response = run_request(request.dup, __method__, retry_if_needed, caller)
|
|
85
85
|
end while response.is_a?(Typhoeus::Response)
|
|
86
86
|
|
|
87
87
|
response
|
|
@@ -99,7 +99,7 @@ module RestfulClient
|
|
|
99
99
|
on_error_block.call("Exception in #{caller} execution - #{e.message}") if on_error_block
|
|
100
100
|
end
|
|
101
101
|
|
|
102
|
-
def run_request(request, method, retry_if_needed)
|
|
102
|
+
def run_request(request, method, retry_if_needed, service_name)
|
|
103
103
|
logger.debug { "#{__method__} :: Request :: #{request.inspect}" }
|
|
104
104
|
request.options[:headers].merge!('X-Forwarded-For' => $client_ip) if $client_ip
|
|
105
105
|
request.options[:headers].merge!('User-Agent' => user_agent)
|
|
@@ -117,7 +117,7 @@ module RestfulClient
|
|
|
117
117
|
# Timeout occured
|
|
118
118
|
elsif response.timed_out?
|
|
119
119
|
@@timeout_occured_count += 1
|
|
120
|
-
skip_raise = (retry_if_needed && @@timeout_occured_count <=
|
|
120
|
+
skip_raise = (retry_if_needed && @@timeout_occured_count <= retries_for(service_name))
|
|
121
121
|
|
|
122
122
|
error_type = 'TimeoutOccured'
|
|
123
123
|
error_description = prettify_logger(error_type, request, response)
|
|
@@ -209,4 +209,12 @@ module RestfulClient
|
|
|
209
209
|
"#{type} #{response.code}/#{response.return_code} for: #{request.options.fetch(:method)}, "\
|
|
210
210
|
"#{request.base_url}, Total time: #{response.total_time} seconds"
|
|
211
211
|
end
|
|
212
|
+
|
|
213
|
+
def timeout_for(service_name)
|
|
214
|
+
callerr_config(service_name)['timeout'] || timeout
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
def retries_for(service_name)
|
|
218
|
+
callerr_config(service_name)['retries'] || retries
|
|
219
|
+
end
|
|
212
220
|
end
|
data/restful_client.gemspec
CHANGED
|
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
|
3
3
|
|
|
4
4
|
Gem::Specification.new do |spec|
|
|
5
5
|
spec.name = 'restful_client'
|
|
6
|
-
spec.version = '1.
|
|
6
|
+
spec.version = '1.1.0'
|
|
7
7
|
spec.authors = ['Avner Cohen']
|
|
8
8
|
spec.email = ['israbirding@gmail.com']
|
|
9
9
|
spec.description = 'An HTTP framework for micro-services based environment, build on top of Typheous and Service Jynx'
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: restful_client
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Avner Cohen
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-09-14 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: service_jynx
|
|
@@ -69,7 +69,7 @@ homepage: https://github.com/AvnerCohen/restful-client
|
|
|
69
69
|
licenses:
|
|
70
70
|
- MIT
|
|
71
71
|
metadata: {}
|
|
72
|
-
post_install_message:
|
|
72
|
+
post_install_message:
|
|
73
73
|
rdoc_options: []
|
|
74
74
|
require_paths:
|
|
75
75
|
- lib
|
|
@@ -84,9 +84,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
84
84
|
- !ruby/object:Gem::Version
|
|
85
85
|
version: '0'
|
|
86
86
|
requirements: []
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
signing_key:
|
|
87
|
+
rubygems_version: 3.3.27
|
|
88
|
+
signing_key:
|
|
90
89
|
specification_version: 4
|
|
91
90
|
summary: An HTTP framework for micro-services based environment
|
|
92
91
|
test_files:
|