Async::HTTP::FaradaySourceAsyncHTTPFaradayClients

class Clients

An interface for creating and managing HTTP clients.

Definitions

def self.call(...)

Create a new instance of the class.

Implementation

def self.call(...)
	new(...)
end

def initialize(**options, &block)

Create a new interface for managing HTTP clients.

Signature

parameter options Hash

The options to create the clients with.

parameter block Proc

An optional block to call with the client before it is used.

Implementation

def initialize(**options, &block)
	@options = options
	@block = block
end

def close

Close all clients.

Implementation

def close
end

def make_client(endpoint)

Make a new client for the given endpoint.

Signature

parameter endpoint IO::Endpoint::Generic

The endpoint to create the client for.

Implementation

def make_client(endpoint)
	client = Client.new(endpoint, **@options)
	
	return @block&.call(client) || client
end

def with_client(endpoint)

Get a client for the given endpoint.

Signature

parameter endpoint IO::Endpoint::Generic

The endpoint to get the client for.

yields {|client| ...}

A client for the given endpoint.

Implementation

def with_client(endpoint)
	client = make_client(endpoint)
	
	yield client
ensure
	client&.close
end

def with_proxied_client(proxy_endpoint, endpoint)

Get a client for the given proxy endpoint and endpoint.

Signature

parameter proxy_endpoint IO::Endpoint::Generic

The proxy endpoint to use.

parameter endpoint IO::Endpoint::Generic

The endpoint to get the client for.

yields {|client| ...}

A client for the given endpoint.

Implementation

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