lib/ezclient/client.rb in ezclient-1.4.0 vs lib/ezclient/client.rb in ezclient-1.5.0
- old
+ new
@@ -17,43 +17,41 @@
follow
].freeze
def initialize(options = {})
self.request_options = options
- self.clients = {}
EzClient::CheckOptions.call(options, REQUEST_OPTION_KEYS)
end
def request(verb, url, **options)
options = { **request_options, **options }
keep_alive_timeout = options.delete(:keep_alive)
api_auth = options.delete(:api_auth)
if keep_alive_timeout
- client = persistent_client_for(url, timeout: keep_alive_timeout)
+ client = persistent_client_registry.for(url, timeout: keep_alive_timeout)
else
client = HTTP::Client.new
end
EzClient::Request.new(verb, url, client: client, **options).tap do |request|
request.api_auth!(*api_auth) if api_auth
end
end
- def perform(*args)
- request(*args).perform
+ def perform(*args, **kwargs)
+ request(*args, **kwargs).perform
end
- def perform!(*args)
- request(*args).perform!
+ def perform!(*args, **kwargs)
+ request(*args, **kwargs).perform!
end
private
- attr_accessor :request_options, :clients
+ attr_accessor :request_options
- def persistent_client_for(url, timeout: 600)
- uri = HTTP::URI.parse(url)
- clients[uri.origin] ||= HTTP.persistent(uri.origin, timeout: timeout)
+ def persistent_client_registry
+ @persistent_client_registry ||= EzClient::PersistentClientRegistry.new
end
end