Class: Async::HTTP::Client
- Inherits:
-
Object
- Object
- Async::HTTP::Client
- Defined in:
- lib/async/http/client.rb
Constant Summary collapse
- VERBS =
['GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE']
Instance Attribute Summary collapse
-
#authority ⇒ Object
readonly
Returns the value of attribute authority.
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
#protocol ⇒ Object
readonly
Returns the value of attribute protocol.
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(endpoint, protocol = nil, authority = nil, **options) ⇒ Client
constructor
A new instance of Client.
- #request(*args) ⇒ Object
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, = nil, **) @endpoint = endpoint @protocol = protocol || endpoint.protocol @authority = || endpoint.hostname @connections = connect(**) end |
Instance Attribute Details
#authority ⇒ Object (readonly)
Returns the value of attribute authority.
39 40 41 |
# File 'lib/async/http/client.rb', line 39 def @authority end |
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
37 38 39 |
# File 'lib/async/http/client.rb', line 37 def endpoint @endpoint end |
#protocol ⇒ Object (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
#close ⇒ Object
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 |