class Airbrake::RemoteSettings::SettingsData

SettingsData is a container, which wraps JSON payload returned by the remote settings API. It exposes the payload via convenient methods and also ensures that in case some data from the payload is missing, a default value would be returned instead.

@example

# Create the object and pass initial data (empty hash).
settings_data = SettingsData.new({})

settings_data.interval #=> 600

@since v5.0.0 @api private

Constants

API_VER

@return [String] API version of the S3 API to poll

CONFIG_ROUTE_PATTERN

@return [String] what path to poll

DEFAULT_INTERVAL

@return [Integer] how frequently we should poll the config API

SETTINGS

@return [Hash{Symbol=>String}] the hash of all supported settings where

the value is the name of the setting returned by the API

Public Class Methods

new(project_id, data) click to toggle source

@param [Integer] project_id @param [Hash{String=>Object}] data

# File lib/airbrake-ruby/remote_settings/settings_data.rb, line 36
def initialize(project_id, data)
  @project_id = project_id
  @data = data
end

Public Instance Methods

apm_host() click to toggle source

@return [String, nil] the host, which provides the API endpoint to which

APM data should be sent
# File lib/airbrake-ruby/remote_settings/settings_data.rb, line 96
def apm_host
  return unless (s = find_setting(SETTINGS[:apm]))

  s['endpoint']
end
config_route(remote_config_host) click to toggle source

@param [String] remote_config_host @return [String] where the config is stored on S3.

# File lib/airbrake-ruby/remote_settings/settings_data.rb, line 60
def config_route(remote_config_host)
  if @data['config_route'] && !@data['config_route'].empty?
    return "#{remote_config_host.chomp('/')}/#{@data['config_route']}"
  end

  format(
    CONFIG_ROUTE_PATTERN,
    host: remote_config_host.chomp('/'),
    project_id: @project_id,
  )
end
error_host() click to toggle source

@return [String, nil] the host, which provides the API endpoint to which

exceptions should be sent
# File lib/airbrake-ruby/remote_settings/settings_data.rb, line 88
def error_host
  return unless (s = find_setting(SETTINGS[:errors]))

  s['endpoint']
end
error_notifications?() click to toggle source

@return [Boolean] whether error notifications are enabled

# File lib/airbrake-ruby/remote_settings/settings_data.rb, line 73
def error_notifications?
  return true unless (s = find_setting(SETTINGS[:errors]))

  s['enabled']
end
interval() click to toggle source

@return [Integer] how frequently we should poll for the config

# File lib/airbrake-ruby/remote_settings/settings_data.rb, line 52
def interval
  return DEFAULT_INTERVAL if !@data.key?('poll_sec') || !@data['poll_sec']

  @data['poll_sec'] > 0 ? @data['poll_sec'] : DEFAULT_INTERVAL
end
merge!(hash) click to toggle source

Merges the given hash with internal data.

@param [Hash{String=>Object}] hash @return [self]

# File lib/airbrake-ruby/remote_settings/settings_data.rb, line 45
def merge!(hash)
  @data.merge!(hash)

  self
end
performance_stats?() click to toggle source

@return [Boolean] whether APM is enabled

# File lib/airbrake-ruby/remote_settings/settings_data.rb, line 80
def performance_stats?
  return true unless (s = find_setting(SETTINGS[:apm]))

  s['enabled']
end
to_h() click to toggle source

@return [Hash{String=>Object}] raw representation of JSON payload

# File lib/airbrake-ruby/remote_settings/settings_data.rb, line 103
def to_h
  @data.dup
end

Private Instance Methods

find_setting(name) click to toggle source
# File lib/airbrake-ruby/remote_settings/settings_data.rb, line 109
def find_setting(name)
  return unless @data.key?('settings')

  @data['settings'].find { |s| s['name'] == name }
end