ezclient 1.4.0 → 1.5.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 +4 -4
- data/.rubocop.yml +1 -1
- data/.travis.yml +9 -8
- data/bin/rspec +29 -0
- data/ezclient.gemspec +1 -1
- data/lib/ezclient.rb +13 -6
- data/lib/ezclient/client.rb +8 -10
- data/lib/ezclient/persistent_client.rb +27 -0
- data/lib/ezclient/persistent_client_registry.rb +23 -0
- data/lib/ezclient/request.rb +0 -1
- data/lib/ezclient/version.rb +1 -1
- metadata +11 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4f9418b8f7468e16261c321cf17ea9ee34e8c2168fda6b936a56b8c88db20ad
|
4
|
+
data.tar.gz: a82af3a1afcd6baa5cdc8e04521db679670b854631843fe3171714f3f4900488
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0c28a22832ce80a471d1fa16483fb0fcbab35550879e8132b6ee4849633489ce49cac1c03dc377ee0936033c9db9d144892644a598313e6d6a20efbf8eda5e4
|
7
|
+
data.tar.gz: 60fc3ff9026c5984d9548a9f420e65d7c3bd223efb29fd96daafbbcb3d725ac3ddd680d94d3121a60fe5b0a21c9ea8d08fa14128ca6883305e921a151360f270
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
language: ruby
|
2
2
|
|
3
|
-
|
3
|
+
os: linux
|
4
4
|
|
5
|
-
|
6
|
-
- 2.4
|
7
|
-
- 2.5
|
8
|
-
- 2.6
|
9
|
-
- ruby-head
|
5
|
+
dist: xenial
|
10
6
|
|
11
7
|
before_install: gem install bundler
|
12
8
|
|
13
|
-
|
9
|
+
jobs:
|
14
10
|
fast_finish: true
|
11
|
+
include:
|
12
|
+
- rvm: 2.5
|
13
|
+
- rvm: 2.6
|
14
|
+
- rvm: 2.7
|
15
|
+
- rvm: ruby-head
|
15
16
|
allow_failures:
|
16
|
-
|
17
|
+
- rvm: ruby-head
|
data/bin/rspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rspec' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("bundle", __dir__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if /This file was generated by Bundler/.match?(File.read(bundle_binstub, 300))
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load Gem.bin_path("rspec-core", "rspec")
|
data/ezclient.gemspec
CHANGED
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
5
|
require "ezclient/version"
|
6
6
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
|
-
spec.required_ruby_version = ">= 2.
|
8
|
+
spec.required_ruby_version = ">= 2.5.0"
|
9
9
|
|
10
10
|
spec.name = "ezclient"
|
11
11
|
spec.version = EzClient::VERSION
|
data/lib/ezclient.rb
CHANGED
@@ -1,15 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "http"
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
|
5
|
+
require_relative "ezclient/version"
|
6
|
+
require_relative "ezclient/client"
|
7
|
+
require_relative "ezclient/persistent_client"
|
8
|
+
require_relative "ezclient/persistent_client_registry"
|
9
|
+
require_relative "ezclient/request"
|
10
|
+
require_relative "ezclient/response"
|
11
|
+
require_relative "ezclient/errors"
|
12
|
+
require_relative "ezclient/check_options"
|
10
13
|
|
11
14
|
module EzClient
|
12
15
|
def self.new(*args)
|
13
16
|
Client.new(*args)
|
14
17
|
end
|
18
|
+
|
19
|
+
def self.get_time
|
20
|
+
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
21
|
+
end
|
15
22
|
end
|
data/lib/ezclient/client.rb
CHANGED
@@ -19,7 +19,6 @@ class EzClient::Client
|
|
19
19
|
|
20
20
|
def initialize(options = {})
|
21
21
|
self.request_options = options
|
22
|
-
self.clients = {}
|
23
22
|
EzClient::CheckOptions.call(options, REQUEST_OPTION_KEYS)
|
24
23
|
end
|
25
24
|
|
@@ -30,7 +29,7 @@ class EzClient::Client
|
|
30
29
|
api_auth = options.delete(:api_auth)
|
31
30
|
|
32
31
|
if keep_alive_timeout
|
33
|
-
client =
|
32
|
+
client = persistent_client_registry.for(url, timeout: keep_alive_timeout)
|
34
33
|
else
|
35
34
|
client = HTTP::Client.new
|
36
35
|
end
|
@@ -40,20 +39,19 @@ class EzClient::Client
|
|
40
39
|
end
|
41
40
|
end
|
42
41
|
|
43
|
-
def perform(*args)
|
44
|
-
request(*args).perform
|
42
|
+
def perform(*args, **kwargs)
|
43
|
+
request(*args, **kwargs).perform
|
45
44
|
end
|
46
45
|
|
47
|
-
def perform!(*args)
|
48
|
-
request(*args).perform!
|
46
|
+
def perform!(*args, **kwargs)
|
47
|
+
request(*args, **kwargs).perform!
|
49
48
|
end
|
50
49
|
|
51
50
|
private
|
52
51
|
|
53
|
-
attr_accessor :request_options
|
52
|
+
attr_accessor :request_options
|
54
53
|
|
55
|
-
def
|
56
|
-
|
57
|
-
clients[uri.origin] ||= HTTP.persistent(uri.origin, timeout: timeout)
|
54
|
+
def persistent_client_registry
|
55
|
+
@persistent_client_registry ||= EzClient::PersistentClientRegistry.new
|
58
56
|
end
|
59
57
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class EzClient::PersistentClient
|
4
|
+
extend Forwardable
|
5
|
+
|
6
|
+
def_delegators :http_client, :build_request, :default_options, :timeout
|
7
|
+
|
8
|
+
attr_accessor :origin, :keep_alive_timeout, :last_request_at
|
9
|
+
|
10
|
+
def initialize(origin, keep_alive_timeout)
|
11
|
+
self.origin = origin
|
12
|
+
self.keep_alive_timeout = keep_alive_timeout
|
13
|
+
self.last_request_at = nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def perform(*args)
|
17
|
+
http_client.perform(*args).tap do
|
18
|
+
self.last_request_at = EzClient.get_time
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def http_client
|
25
|
+
@http_client ||= HTTP.persistent(origin, timeout: keep_alive_timeout)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class EzClient::PersistentClientRegistry
|
4
|
+
def initialize
|
5
|
+
self.registry = {}
|
6
|
+
end
|
7
|
+
|
8
|
+
def for(url, timeout:)
|
9
|
+
cleanup_registry!
|
10
|
+
uri = HTTP::URI.parse(url)
|
11
|
+
registry[uri.origin] ||= EzClient::PersistentClient.new(uri.origin, timeout)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
attr_accessor :registry
|
17
|
+
|
18
|
+
def cleanup_registry!
|
19
|
+
registry.delete_if do |_key, value|
|
20
|
+
EzClient.get_time - value.last_request_at >= value.keep_alive_timeout
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/ezclient/request.rb
CHANGED
@@ -103,7 +103,6 @@ class EzClient::Request
|
|
103
103
|
def perform_request
|
104
104
|
with_retry do
|
105
105
|
# Use original client so that connection can be reused
|
106
|
-
# client.perform(http_request, http_options)
|
107
106
|
res = client.perform(http_request, http_options)
|
108
107
|
return res unless follow
|
109
108
|
|
data/lib/ezclient/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ezclient
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuri Smirnov
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
@@ -136,7 +136,7 @@ dependencies:
|
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
|
-
description:
|
139
|
+
description:
|
140
140
|
email:
|
141
141
|
- tycooon@yandex.ru
|
142
142
|
- oss@umbrellio.biz
|
@@ -153,12 +153,15 @@ files:
|
|
153
153
|
- README.md
|
154
154
|
- Rakefile
|
155
155
|
- bin/console
|
156
|
+
- bin/rspec
|
156
157
|
- ezclient.gemspec
|
157
158
|
- gemfiles/http3.gemfile
|
158
159
|
- lib/ezclient.rb
|
159
160
|
- lib/ezclient/check_options.rb
|
160
161
|
- lib/ezclient/client.rb
|
161
162
|
- lib/ezclient/errors.rb
|
163
|
+
- lib/ezclient/persistent_client.rb
|
164
|
+
- lib/ezclient/persistent_client_registry.rb
|
162
165
|
- lib/ezclient/request.rb
|
163
166
|
- lib/ezclient/response.rb
|
164
167
|
- lib/ezclient/version.rb
|
@@ -166,7 +169,7 @@ homepage: https://github.com/umbrellio/ezclient
|
|
166
169
|
licenses:
|
167
170
|
- MIT
|
168
171
|
metadata: {}
|
169
|
-
post_install_message:
|
172
|
+
post_install_message:
|
170
173
|
rdoc_options: []
|
171
174
|
require_paths:
|
172
175
|
- lib
|
@@ -174,15 +177,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
174
177
|
requirements:
|
175
178
|
- - ">="
|
176
179
|
- !ruby/object:Gem::Version
|
177
|
-
version: 2.
|
180
|
+
version: 2.5.0
|
178
181
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
179
182
|
requirements:
|
180
183
|
- - ">="
|
181
184
|
- !ruby/object:Gem::Version
|
182
185
|
version: '0'
|
183
186
|
requirements: []
|
184
|
-
rubygems_version: 3.
|
185
|
-
signing_key:
|
187
|
+
rubygems_version: 3.1.2
|
188
|
+
signing_key:
|
186
189
|
specification_version: 4
|
187
190
|
summary: An HTTP gem wrapper for easy persistent connections and more.
|
188
191
|
test_files: []
|