Class: Broadcast::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/broadcast/connection.rb

Overview

HTTP transport. Owns request building, response/error mapping, retries, redirects, and debug logging. Split out of Client so Client stays a thin facade over configuration and resource sub-clients.

Constant Summary collapse

MAX_REDIRECTS =
3
REDIRECT_CODES =
[301, 302, 307, 308].freeze

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Connection

Returns a new instance of Connection.



24
25
26
27
# File 'lib/broadcast/connection.rb', line 24

def initialize(config)
  @config = config
  @debug_logger = DebugLogger.new(config)
end

Instance Method Details

#request(method, path, payload = nil, headers: {}, raw: false) ⇒ Object

Parameters:

  • raw (Boolean) (defaults to: false)

    return the response body as a String instead of parsing it as JSON — for text/plain endpoints such as /api/v1/skill.



31
32
33
34
35
36
37
38
# File 'lib/broadcast/connection.rb', line 31

def request(method, path, payload = nil, headers: {}, raw: false)
  uri = build_uri(path, method, payload)
  context = { headers: headers, raw: raw, redirects: 0 }

  retry_with_backoff { execute(method, uri, payload, context) }
rescue Net::OpenTimeout, Net::ReadTimeout => e
  raise Broadcast::TimeoutError, "Request timeout: #{e.message}"
end