Class: PoliPage::Internal::Transport Private

Inherits:
Object
  • Object
show all
Defined in:
lib/poli_page/internal/transport.rb

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.

Thin wrapper around ‘Net::HTTP`. The ONLY module that opens sockets (sdk-ruby-plan.md §3.2). Translates network-level exceptions into the `PoliPage::Error` hierarchy at the seam (§8 error mapping).

Honors ‘http_proxy`, `https_proxy`, and `no_proxy` environment variables by default (via `Net::HTTP`’s ‘:ENV` proxy resolution). Pass `proxy:` to force an explicit proxy URL or `ca_file:` / `ca_path:` to point at a custom CA bundle (e.g., a corporate MITM TLS-terminating proxy).

Defined Under Namespace

Classes: Response

Constant Summary collapse

VERBS =

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.

{
  get:    Net::HTTP::Get,
  post:   Net::HTTP::Post,
  delete: Net::HTTP::Delete
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(base_url:, timeout:, proxy: nil, ca_file: nil, ca_path: nil) ⇒ Transport

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.

Returns a new instance of Transport.



30
31
32
33
34
35
36
# File 'lib/poli_page/internal/transport.rb', line 30

def initialize(base_url:, timeout:, proxy: nil, ca_file: nil, ca_path: nil)
  @base_url = base_url
  @timeout  = timeout
  @proxy    = proxy
  @ca_file  = ca_file
  @ca_path  = ca_path
end

Instance Method Details

#execute(method:, path:, headers:, body: nil) ⇒ 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.

Parameters:

  • method (Symbol)

    :get, :post, or :delete

  • path (String)

    e.g. “/v1/render”

  • headers (Hash{String=>String})
  • body (String, nil) (defaults to: nil)

    JSON-encoded body or nil

Returns:

Raises:



44
45
46
47
48
49
50
51
52
# File 'lib/poli_page/internal/transport.rb', line 44

def execute(method:, path:, headers:, body: nil)
  uri = URI.parse(HTTP.build_url(@base_url, path))
  build_response(perform_request(uri, build_request(method, uri, headers, body)))
rescue Net::OpenTimeout, Net::ReadTimeout, Net::WriteTimeout
  raise PoliPage::TimeoutError.new(timeout: @timeout)
rescue SocketError, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ETIMEDOUT,
       Errno::EHOSTUNREACH, Errno::ENETUNREACH, OpenSSL::SSL::SSLError => e
  raise PoliPage::ConnectionError.new(message: e.message, cause: e)
end