Class: Airbrake::RemoteSettings::SettingsData Private

Inherits:
Object
  • Object
show all
Defined in:
lib/airbrake-ruby/remote_settings/settings_data.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.

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.

Examples:

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

settings_data.interval #=> 600

Since:

  • v5.0.0

Constant Summary collapse

DEFAULT_INTERVAL =

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.

Returns how frequently we should poll the config API.

Returns:

  • (Integer)

    how frequently we should poll the config API

Since:

  • v5.0.0

600
API_VER =

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.

Returns API version of the S3 API to poll.

Returns:

  • (String)

    API version of the S3 API to poll

Since:

  • v5.0.0

'2020-06-18'.freeze
CONFIG_ROUTE_PATTERN =

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.

Returns what path to poll.

Returns:

  • (String)

    what path to poll

Since:

  • v5.0.0

"%<host>s/#{API_VER}/config/%<project_id>s/config.json".freeze
SETTINGS =

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.

Returns the hash of all supported settings where the value is the name of the setting returned by the API.

Returns:

  • (Hash{Symbol=>String})

    the hash of all supported settings where the value is the name of the setting returned by the API

Since:

  • v5.0.0

{
  errors: 'errors'.freeze,
  apm: 'apm'.freeze,
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(project_id, data) ⇒ SettingsData

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 SettingsData.

Parameters:

  • project_id (Integer)
  • data (Hash{String=>Object})

Since:

  • v5.0.0



36
37
38
39
# File 'lib/airbrake-ruby/remote_settings/settings_data.rb', line 36

def initialize(project_id, data)
  @project_id = project_id
  @data = data
end

Instance Method Details

#apm_hostString?

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 the host, which provides the API endpoint to which APM data should be sent.

Returns:

  • (String, nil)

    the host, which provides the API endpoint to which APM data should be sent

Since:

  • v5.0.0



96
97
98
99
100
# 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) ⇒ String

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 where the config is stored on S3.

Parameters:

  • remote_config_host (String)

Returns:

  • (String)

    where the config is stored on S3.

Since:

  • v5.0.0



60
61
62
63
64
65
66
67
68
69
70
# 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_hostString?

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 the host, which provides the API endpoint to which exceptions should be sent.

Returns:

  • (String, nil)

    the host, which provides the API endpoint to which exceptions should be sent

Since:

  • v5.0.0



88
89
90
91
92
# 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?Boolean

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 whether error notifications are enabled.

Returns:

  • (Boolean)

    whether error notifications are enabled

Since:

  • v5.0.0



73
74
75
76
77
# 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

#intervalInteger

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 how frequently we should poll for the config.

Returns:

  • (Integer)

    how frequently we should poll for the config

Since:

  • v5.0.0



52
53
54
55
56
# 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) ⇒ self

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.

Merges the given hash with internal data.

Parameters:

  • hash (Hash{String=>Object})

Returns:

  • (self)

Since:

  • v5.0.0



45
46
47
48
49
# File 'lib/airbrake-ruby/remote_settings/settings_data.rb', line 45

def merge!(hash)
  @data.merge!(hash)

  self
end

#performance_stats?Boolean

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 whether APM is enabled.

Returns:

  • (Boolean)

    whether APM is enabled

Since:

  • v5.0.0



80
81
82
83
84
# 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_hHash{String=>Object}

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 raw representation of JSON payload.

Returns:

  • (Hash{String=>Object})

    raw representation of JSON payload

Since:

  • v5.0.0



103
104
105
# File 'lib/airbrake-ruby/remote_settings/settings_data.rb', line 103

def to_h
  @data.dup
end