module ClientApiBuilder::NetHTTP::Request

Constants

METHOD_TO_NET_HTTP_CLASS

Copied from ruby-doc.org/stdlib-2.7.1/libdoc/net/http/rdoc/Net/HTTP.html

Public Instance Methods

request(method:, uri:, body:, headers:, connection_options:) { |response| ... } click to toggle source
# File lib/client_api_builder/net_http_request.rb, line 26
def request(method:, uri:, body:, headers:, connection_options:)
  request = METHOD_TO_NET_HTTP_CLASS[method].new(uri.request_uri, headers)
  request.body = body if body

  Net::HTTP.start(uri.hostname, uri.port, connection_options.merge(use_ssl: uri.scheme == 'https')) do |http|
    http.request(request) do |response|
      yield response if block_given?
    end
  end
end
stream(method:, uri:, body:, headers:, connection_options:) { |response, chunk| ... } click to toggle source
# File lib/client_api_builder/net_http_request.rb, line 37
def stream(method:, uri:, body:, headers:, connection_options:)
  request(method: method, uri: uri, body: body, headers: headers, connection_options: connection_options) do |response|
    response.read_body do |chunk|
      yield response, chunk
    end
  end
end
stream_to_file(method:, uri:, body:, headers:, connection_options:, file:) click to toggle source
# File lib/client_api_builder/net_http_request.rb, line 51
def stream_to_file(method:, uri:, body:, headers:, connection_options:, file:)
  mode = connection_options.delete(:file_mode) || 'wb'
  File.open(file, mode) do |io|
    stream_to_io(method: method, uri: uri, body: body, headers: headers, connection_options: connection_options, io: io)
  end
end
stream_to_io(method:, uri:, body:, headers:, connection_options:, io:) click to toggle source
# File lib/client_api_builder/net_http_request.rb, line 45
def stream_to_io(method:, uri:, body:, headers:, connection_options:, io:)
  stream(method: method, uri: uri, body: body, headers: headers, connection_options: connection_options) do |_, chunk|
    io.write chunk
  end
end