Class: EzClient::Client
- Inherits:
-
Object
- Object
- EzClient::Client
- Defined in:
- lib/ezclient/client.rb
Constant Summary collapse
- REQUEST_OPTION_KEYS =
%i[ api_auth basic_auth cookies headers keep_alive max_retries on_complete on_error on_retry retry_exceptions ssl_context timeout follow error_wrapper ].freeze
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #perform(*args, **kwargs) ⇒ Object
- #perform!(*args, **kwargs) ⇒ Object
- #request(verb, url, **options) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
21 22 23 24 |
# File 'lib/ezclient/client.rb', line 21 def initialize( = {}) self. = EzClient::CheckOptions.call(, REQUEST_OPTION_KEYS) end |
Instance Method Details
#perform(*args, **kwargs) ⇒ Object
46 47 48 |
# File 'lib/ezclient/client.rb', line 46 def perform(*args, **kwargs) request(*args, **kwargs).perform end |
#perform!(*args, **kwargs) ⇒ Object
50 51 52 |
# File 'lib/ezclient/client.rb', line 50 def perform!(*args, **kwargs) request(*args, **kwargs).perform! end |
#request(verb, url, **options) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ezclient/client.rb', line 26 def request(verb, url, **) = { **, ** } keep_alive_timeout = .delete(:keep_alive) api_auth = .delete(:api_auth) ssl_context = [:ssl_context] if keep_alive_timeout client = persistent_client_registry.for( url, ssl_context: ssl_context, timeout: keep_alive_timeout ) else client = HTTP::Client.new end EzClient::Request.new(verb, url, client: client, **).tap do |request| request.api_auth!(*api_auth) if api_auth end end |