network-client 1.1.5 → 1.1.6
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/Gemfile.lock +1 -1
- data/lib/network-client/core.rb +27 -17
- data/lib/network-client/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75b9ed5e72145a53a1dc73e09fed8a698cb7f723
|
4
|
+
data.tar.gz: 0fc103daaef34021254fcfcc00d7ebf624db40df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d969c67f60e33fd89d143a9939e16c39d27908a5ef3e25ecce35475d5f1be026732b4dd34a1fdec0859856724de0465ba3fff9ad9a0b21b1930d4c53f61ebbe
|
7
|
+
data.tar.gz: 10e9c5c9b8c12d651288bf50da04f925f526696dba0b9091a14cf0ad0cfe4b4129f531e0d9527f9ae90204c09d75c450e980e84273e044cbfaacdce36af7f254
|
data/Gemfile.lock
CHANGED
data/lib/network-client/core.rb
CHANGED
@@ -24,37 +24,40 @@ module NetworkClient
|
|
24
24
|
|
25
25
|
attr_reader :username, :password, :default_headers, :logger, :tries
|
26
26
|
|
27
|
-
#
|
27
|
+
# Error list for retrying strategy.
|
28
28
|
# Initially contains common errors encountered usually in net calls.
|
29
29
|
attr_accessor :errors_to_recover
|
30
30
|
|
31
|
-
#
|
31
|
+
# Error list for stop and propagate strategy.
|
32
32
|
# Takes priority over *:errors_to_recover*.
|
33
33
|
# Do not assign ancestor error classes here that prevent retry for descendant ones.
|
34
34
|
attr_accessor :errors_to_propagate
|
35
35
|
|
36
|
+
##
|
36
37
|
# Construct and prepare client for requests targeting :endpoint.
|
37
38
|
#
|
39
|
+
# === Parameters:
|
40
|
+
#
|
38
41
|
# *endpoint*:
|
39
|
-
#
|
42
|
+
# Uri for the host with schema and port. any other segment like paths will be discarded.
|
40
43
|
# *tries*:
|
41
|
-
#
|
44
|
+
# Number to specify how many is to repeat failed calls. Default is 2.
|
42
45
|
# *headers*:
|
43
|
-
#
|
46
|
+
# Hash to contain any common HTTP headers to be set in client calls.
|
44
47
|
# *username*:
|
45
|
-
#
|
48
|
+
# for HTTP basic authentication. Applies on all requests. Default to nil.
|
46
49
|
# *password*:
|
47
|
-
#
|
50
|
+
# for HTTP basic authentication. Applies on all requests. Default to nil.
|
51
|
+
#
|
52
|
+
# === Example:
|
53
|
+
# require "network-client"
|
48
54
|
#
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
# => "-1": "https://assets-cdn.github.com/images/icons/emoji/unicode/1f44e.png?v7",
|
56
|
-
# => "100": "https://assets-cdn.github.com/images/icons/emoji/unicode/1f4af.png?v7",
|
57
|
-
# => ... }
|
55
|
+
# github_client = NetworkClient::Client.new(endpoint: 'https://api.github.com')
|
56
|
+
# github_client.get '/emojis'
|
57
|
+
# #=> { "+1": "https://assets-cdn.github.com/images/icons/emoji/unicode/1f44d.png?v7",
|
58
|
+
# "-1": "https://assets-cdn.github.com/images/icons/emoji/unicode/1f44e.png?v7",
|
59
|
+
# "100": "https://assets-cdn.github.com/images/icons/emoji/unicode/1f4af.png?v7",
|
60
|
+
# ... }
|
58
61
|
#
|
59
62
|
def initialize(endpoint:, tries: 2, headers: {}, username: nil, password: nil)
|
60
63
|
@uri = URI.parse(endpoint)
|
@@ -128,6 +131,7 @@ module NetworkClient
|
|
128
131
|
Net::ReadTimeout,
|
129
132
|
Net::OpenTimeout,
|
130
133
|
Errno::ECONNREFUSED,
|
134
|
+
Errno::ETIMEDOUT,
|
131
135
|
OpenSSL::SSL::SSLError,
|
132
136
|
SocketError]
|
133
137
|
@errors_to_propagate = [Net::HTTPRequestURITooLarge,
|
@@ -207,13 +211,15 @@ module NetworkClient
|
|
207
211
|
if params.nil? || params.empty?
|
208
212
|
path
|
209
213
|
else
|
214
|
+
params = stringify_keys(params)
|
210
215
|
encoded = URI.encode_www_form(params)
|
211
216
|
[path, encoded].join("?")
|
212
217
|
end
|
213
218
|
end
|
214
219
|
|
215
220
|
def formulate_path(path)
|
216
|
-
path = '/'
|
221
|
+
path = '/' if path.nil? || path.empty?
|
222
|
+
path.strip! if path.respond_to?(:strip)
|
217
223
|
path.prepend('/') unless path.chars.first == '/'
|
218
224
|
path
|
219
225
|
end
|
@@ -225,5 +231,9 @@ module NetworkClient
|
|
225
231
|
def warn_on_retry(message)
|
226
232
|
@logger.warn("\n#{LOG_TAG} #{message} \nRetrying now ..")
|
227
233
|
end
|
234
|
+
|
235
|
+
def stringify_keys(params)
|
236
|
+
params.respond_to?(:keys) ? params.collect { |k, v| [k.to_s, v] }.to_h : params
|
237
|
+
end
|
228
238
|
end
|
229
239
|
end
|