Class: Async::HTTP::Client

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

Constant Summary collapse

VERBS =
['GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE']

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint, protocol = nil, authority = nil, **options) ⇒ Client

Returns a new instance of Client.



28
29
30
31
32
33
34
35
# File 'lib/async/http/client.rb', line 28

def initialize(endpoint, protocol = nil, authority = nil, **options)
	@endpoint = endpoint
	
	@protocol = protocol || endpoint.protocol
	@authority = authority || endpoint.hostname
	
	@connections = connect(**options)
end

Instance Attribute Details

#authorityObject (readonly)

Returns the value of attribute authority.



39
40
41
# File 'lib/async/http/client.rb', line 39

def authority
  @authority
end

#endpointObject (readonly)

Returns the value of attribute endpoint.



37
38
39
# File 'lib/async/http/client.rb', line 37

def endpoint
  @endpoint
end

#protocolObject (readonly)

Returns the value of attribute protocol.



38
39
40
# File 'lib/async/http/client.rb', line 38

def protocol
  @protocol
end

Class Method Details

.open(*args, &block) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/async/http/client.rb', line 41

def self.open(*args, &block)
	client = self.new(*args)
	
	return client unless block_given?
	
	begin
		yield client
	ensure
		client.close
	end
end

Instance Method Details

#closeObject



53
54
55
# File 'lib/async/http/client.rb', line 53

def close
	@connections.close
end

#request(*args) ⇒ Object



65
66
67
68
69
# File 'lib/async/http/client.rb', line 65

def request(*args)
	@connections.acquire do |connection|
		connection.send_request(@authority, *args)
	end
end