Class: Async::HTTP::Faraday::Clients
- Inherits:
-
Object
- Object
- Async::HTTP::Faraday::Clients
- Defined in:
- lib/async/http/faraday/clients.rb
Overview
An interface for creating and managing HTTP clients.
Direct Known Subclasses
Class Method Summary collapse
-
.call ⇒ Object
Create a new instance of the class.
Instance Method Summary collapse
-
#close ⇒ Object
Close all clients.
-
#initialize(**options, &block) ⇒ Clients
constructor
Create a new interface for managing HTTP clients.
-
#make_client(endpoint) ⇒ Object
Make a new client for the given endpoint.
-
#with_client(endpoint) ⇒ Object
Get a client for the given endpoint.
-
#with_proxied_client(proxy_endpoint, endpoint) ⇒ Object
Get a client for the given proxy endpoint and endpoint.
Constructor Details
#initialize(**options, &block) ⇒ Clients
Create a new interface for managing HTTP clients.
27 28 29 30 |
# File 'lib/async/http/faraday/clients.rb', line 27 def initialize(**, &block) @options = @block = block end |
Class Method Details
.call ⇒ Object
Create a new instance of the class.
19 20 21 |
# File 'lib/async/http/faraday/clients.rb', line 19 def self.call(...) new(...) end |
Instance Method Details
#close ⇒ Object
Close all clients.
33 34 |
# File 'lib/async/http/faraday/clients.rb', line 33 def close end |
#make_client(endpoint) ⇒ Object
Make a new client for the given endpoint.
39 40 41 42 43 |
# File 'lib/async/http/faraday/clients.rb', line 39 def make_client(endpoint) client = Client.new(endpoint, **@options) return @block&.call(client) || client end |
#with_client(endpoint) ⇒ Object
Get a client for the given endpoint.
49 50 51 52 53 54 55 |
# File 'lib/async/http/faraday/clients.rb', line 49 def with_client(endpoint) client = make_client(endpoint) yield client ensure client&.close end |
#with_proxied_client(proxy_endpoint, endpoint) ⇒ Object
Get a client for the given proxy endpoint and endpoint.
62 63 64 65 66 67 68 69 70 |
# File 'lib/async/http/faraday/clients.rb', line 62 def with_proxied_client(proxy_endpoint, endpoint) client = make_client(proxy_endpoint) proxied_client = client.proxied_client(endpoint) yield proxied_client ensure proxied_client&.close client&.close end |