network-client 1.1.5 → 1.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 69bc26f62b6e80de3ad2d7ec172477b1bf8e9977
4
- data.tar.gz: b5e873f8f2a1824428365ed72bf0c8d995cf03c5
3
+ metadata.gz: 75b9ed5e72145a53a1dc73e09fed8a698cb7f723
4
+ data.tar.gz: 0fc103daaef34021254fcfcc00d7ebf624db40df
5
5
  SHA512:
6
- metadata.gz: 52a46ce916e2a56e75b027684891d3910f0c9b671b99cf3260199a70f3d3cfec513846eb28255521e8dc6fcc38a81d15113cf26ec41a22aa860355b5d9ae2370
7
- data.tar.gz: c250a7b4eba369c875e55a1df6ae532d86f8909f5d1a5d1922921ba84d6fbd98c81e9a8b7df03dd8f1162acc6acb9c2d6fb78fa3948ef4aba9976cb04ab431d3
6
+ metadata.gz: 3d969c67f60e33fd89d143a9939e16c39d27908a5ef3e25ecce35475d5f1be026732b4dd34a1fdec0859856724de0465ba3fff9ad9a0b21b1930d4c53f61ebbe
7
+ data.tar.gz: 10e9c5c9b8c12d651288bf50da04f925f526696dba0b9091a14cf0ad0cfe4b4129f531e0d9527f9ae90204c09d75c450e980e84273e044cbfaacdce36af7f254
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- network-client (1.1.5)
4
+ network-client (1.1.6)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -24,37 +24,40 @@ module NetworkClient
24
24
 
25
25
  attr_reader :username, :password, :default_headers, :logger, :tries
26
26
 
27
- # error list for retrying strategy.
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
- # error list for stop and propagate strategy.
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
- # Uri for the host with schema and port. any other segment like paths will be discarded.
42
+ # Uri for the host with schema and port. any other segment like paths will be discarded.
40
43
  # *tries*:
41
- # Number to specify how many is to repeat failed calls. Default is 2.
44
+ # Number to specify how many is to repeat failed calls. Default is 2.
42
45
  # *headers*:
43
- # Hash to contain any common HTTP headers to be set in client calls.
46
+ # Hash to contain any common HTTP headers to be set in client calls.
44
47
  # *username*:
45
- # for HTTP basic authentication. Applies on all requests. Default to nil.
48
+ # for HTTP basic authentication. Applies on all requests. Default to nil.
46
49
  # *password*:
47
- # for HTTP basic authentication. Applies on all requests. Default to nil.
50
+ # for HTTP basic authentication. Applies on all requests. Default to nil.
51
+ #
52
+ # === Example:
53
+ # require "network-client"
48
54
  #
49
- # ==== Example:
50
- # => require "network-client"
51
- # =>
52
- # => github_client = NetworkClient::Client.new(endpoint: 'https://api.github.com')
53
- # => github_client.get '/emojis'
54
- # => { "+1": "https://assets-cdn.github.com/images/icons/emoji/unicode/1f44d.png?v7",
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 = '/' if path.nil? || path.empty?
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
@@ -1,3 +1,3 @@
1
1
  module NetworkClient
2
- VERSION = "1.1.5"
2
+ VERSION = "1.1.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: network-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.5
4
+ version: 1.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abdullah Barrak (abarrak)