Class: Broadcast::Configuration

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

Constant Summary collapse

WARNINGS_MODES =

How to handle the warnings array the API returns on successful writes (docs: api-response-warnings):

:log    — warn through `logger` if one is set (default)
:raise  — raise Broadcast::WarningError; note the write already happened
:ignore — leave them on the response for the caller to inspect
%i[log raise ignore].freeze
ENV_HOST =

Env vars use the same names as the Broadcast CLI's ~/.config/broadcast/config, so a machine set up for the CLI can drive the gem with no extra config.

'BROADCAST_HOST'
ENV_TOKEN =
'BROADCAST_API_TOKEN'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/broadcast/configuration.rb', line 29

def initialize
  @api_token = ENV.fetch(ENV_TOKEN, nil)
  # No default host. Broadcast is self-hosted-first — every instance lives
  # at its own domain, so any built-in guess is wrong for nearly everyone.
  @host = ENV.fetch(ENV_HOST, nil)
  @timeout = 30
  @open_timeout = 10
  @retry_attempts = 3
  @retry_delay = 1
  # Ceiling for a server-supplied Retry-After. Without it a long rate-limit
  # window would block the caller for as long as the server asked.
  @max_retry_delay = 30
  @warnings_mode = :log
  @logger = nil
  @debug = false
  @broadcast_channel_id = nil
end

Instance Attribute Details

#api_tokenObject

Returns the value of attribute api_token.



17
18
19
# File 'lib/broadcast/configuration.rb', line 17

def api_token
  @api_token
end

#broadcast_channel_idObject

Returns the value of attribute broadcast_channel_id.



17
18
19
# File 'lib/broadcast/configuration.rb', line 17

def broadcast_channel_id
  @broadcast_channel_id
end

#debugObject

Returns the value of attribute debug.



17
18
19
# File 'lib/broadcast/configuration.rb', line 17

def debug
  @debug
end

#hostObject

Returns the value of attribute host.



17
18
19
# File 'lib/broadcast/configuration.rb', line 17

def host
  @host
end

#loggerObject

Returns the value of attribute logger.



17
18
19
# File 'lib/broadcast/configuration.rb', line 17

def logger
  @logger
end

#max_retry_delayObject

Returns the value of attribute max_retry_delay.



17
18
19
# File 'lib/broadcast/configuration.rb', line 17

def max_retry_delay
  @max_retry_delay
end

#open_timeoutObject

Returns the value of attribute open_timeout.



17
18
19
# File 'lib/broadcast/configuration.rb', line 17

def open_timeout
  @open_timeout
end

#retry_attemptsObject

Returns the value of attribute retry_attempts.



17
18
19
# File 'lib/broadcast/configuration.rb', line 17

def retry_attempts
  @retry_attempts
end

#retry_delayObject

Returns the value of attribute retry_delay.



17
18
19
# File 'lib/broadcast/configuration.rb', line 17

def retry_delay
  @retry_delay
end

#timeoutObject

Returns the value of attribute timeout.



17
18
19
# File 'lib/broadcast/configuration.rb', line 17

def timeout
  @timeout
end

#warnings_modeObject

Returns the value of attribute warnings_mode.



17
18
19
# File 'lib/broadcast/configuration.rb', line 17

def warnings_mode
  @warnings_mode
end

Instance Method Details

#validate!Object

Raises:



47
48
49
50
51
52
53
54
# File 'lib/broadcast/configuration.rb', line 47

def validate!
  raise ConfigurationError, 'api_token is required' if blank?(api_token)
  raise ConfigurationError, host_missing_message if blank?(host)

  self.host = host.to_s.strip.chomp('/')
  validate_host_scheme!
  validate_warnings_mode!
end