Class: Nombaone::Internal::NetHTTPConnection Private

Inherits:
Object
  • Object
show all
Defined in:
lib/nombaone/internal/http_client.rb,
sig/nombaone/internal.rbs

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

The default connection: a single Net::HTTP round-trip. Returns a Response for any HTTP status (2xx, 4xx, 5xx alike) and raises only on transport failure — a timeout (TimeoutError) or an unreachable/broken connection (ConnectionError). Distinguishing our own read timeout (a specific Net::*Timeout) from a caller's own Timeout.timeout (a bare Timeout::Error, left to propagate) is what lets the SDK retry the former and never retry the latter.

Constant Summary collapse

METHOD_CLASSES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Returns:

  • (Hash[Symbol, untyped])
{
  get: Net::HTTP::Get,
  post: Net::HTTP::Post,
  patch: Net::HTTP::Patch,
  put: Net::HTTP::Put,
  delete: Net::HTTP::Delete,
}.freeze

Instance Method Summary collapse

Instance Method Details

#execute(method:, url:, headers:, body:, timeout:) ⇒ Nombaone::Internal::Response

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/nombaone/internal/http_client.rb', line 36

def execute(method:, url:, headers:, body:, timeout:)
  uri = URI.parse(url)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = uri.scheme == "https"
  http.open_timeout = timeout
  http.read_timeout = timeout
  http.write_timeout = timeout if http.respond_to?(:write_timeout=)

  response = http.request(build_request(method, uri, headers, body))
  Response.new(status: response.code.to_i, headers: header_hash(response),
               body: response.body)
rescue Net::OpenTimeout, Net::ReadTimeout, Net::WriteTimeout
  raise Nombaone::TimeoutError, "The request to NombaOne timed out after #{timeout}s."
rescue SocketError, SystemCallError, OpenSSL::SSL::SSLError, IOError,
       Net::HTTPBadResponse, Net::ProtocolError => e
  raise Nombaone::ConnectionError, "Could not reach the NombaOne API: #{e.message}"
end