Class: Rubagent::HttpClient

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#responseObject (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

#bodyObject



41
42
43
# File 'lib/rubagent/http_client.rb', line 41

def body
  @response_body
end

#headersObject



49
50
51
# File 'lib/rubagent/http_client.rb', line 49

def headers
  response.to_hash
end

#statusObject



45
46
47
# File 'lib/rubagent/http_client.rb', line 45

def status
  response.code.to_i
end