Class: Async::HTTP::Faraday::Clients

Inherits:
Object
  • Object
show all
Defined in:
lib/async/http/faraday/clients.rb

Overview

An interface for creating and managing HTTP clients.

Direct Known Subclasses

PersistentClients

Class Method Summary collapse

Instance Method Summary collapse

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(**options, &block)
	@options = options
	@block = block
end

Class Method Details

.callObject

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

#closeObject

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