Class: Broadcast::Configuration
- Inherits:
-
Object
- Object
- Broadcast::Configuration
- Defined in:
- lib/broadcast/configuration.rb
Constant Summary collapse
- WARNINGS_MODES =
How to handle the
warningsarray 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
-
#api_token ⇒ Object
Returns the value of attribute api_token.
-
#broadcast_channel_id ⇒ Object
Returns the value of attribute broadcast_channel_id.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#host ⇒ Object
Returns the value of attribute host.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#max_retry_delay ⇒ Object
Returns the value of attribute max_retry_delay.
-
#open_timeout ⇒ Object
Returns the value of attribute open_timeout.
-
#retry_attempts ⇒ Object
Returns the value of attribute retry_attempts.
-
#retry_delay ⇒ Object
Returns the value of attribute retry_delay.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#warnings_mode ⇒ Object
Returns the value of attribute warnings_mode.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #validate! ⇒ Object
Constructor Details
#initialize ⇒ Configuration
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_token ⇒ Object
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_id ⇒ Object
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 |
#debug ⇒ Object
Returns the value of attribute debug.
17 18 19 |
# File 'lib/broadcast/configuration.rb', line 17 def debug @debug end |
#host ⇒ Object
Returns the value of attribute host.
17 18 19 |
# File 'lib/broadcast/configuration.rb', line 17 def host @host end |
#logger ⇒ Object
Returns the value of attribute logger.
17 18 19 |
# File 'lib/broadcast/configuration.rb', line 17 def logger @logger end |
#max_retry_delay ⇒ Object
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_timeout ⇒ Object
Returns the value of attribute open_timeout.
17 18 19 |
# File 'lib/broadcast/configuration.rb', line 17 def open_timeout @open_timeout end |
#retry_attempts ⇒ Object
Returns the value of attribute retry_attempts.
17 18 19 |
# File 'lib/broadcast/configuration.rb', line 17 def retry_attempts @retry_attempts end |
#retry_delay ⇒ Object
Returns the value of attribute retry_delay.
17 18 19 |
# File 'lib/broadcast/configuration.rb', line 17 def retry_delay @retry_delay end |
#timeout ⇒ Object
Returns the value of attribute timeout.
17 18 19 |
# File 'lib/broadcast/configuration.rb', line 17 def timeout @timeout end |
#warnings_mode ⇒ Object
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
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, if blank?(host) self.host = host.to_s.strip.chomp('/') validate_host_scheme! validate_warnings_mode! end |