Class: Rubagent::HttpClient
- Inherits:
-
Object
- Object
- Rubagent::HttpClient
- Defined in:
- lib/rubagent/http_client.rb
Overview
HTTP client with streaming support
Constant Summary collapse
- SUPPORTED_METHODS =
%i[get post put patch delete].freeze
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #body ⇒ Object
- #headers ⇒ Object
-
#initialize(method:, url:, headers:, params:, body:, stream:, on_chunk:) ⇒ HttpClient
constructor
A new instance of HttpClient.
- #status ⇒ Object
Constructor Details
#initialize(method:, url:, headers:, params:, body:, stream:, on_chunk:) ⇒ HttpClient
Returns a new instance of HttpClient.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rubagent/http_client.rb', line 29 def initialize(method:, url:, headers:, params:, body:, stream:, on_chunk:) @uri = URI.parse(url) @uri.query = URI.encode_www_form(params) unless params.empty? @method = method @headers = headers @body = body @stream = stream @on_chunk = on_chunk perform_request end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
11 12 13 |
# File 'lib/rubagent/http_client.rb', line 11 def response @response end |
Instance Method Details
#body ⇒ Object
41 42 43 |
# File 'lib/rubagent/http_client.rb', line 41 def body @response_body end |
#headers ⇒ Object
49 50 51 |
# File 'lib/rubagent/http_client.rb', line 49 def headers response.to_hash end |
#status ⇒ Object
45 46 47 |
# File 'lib/rubagent/http_client.rb', line 45 def status response.code.to_i end |