Class: Kameleoon::KameleoonClientConfig
- Inherits:
-
Object
- Object
- Kameleoon::KameleoonClientConfig
- Defined in:
- lib/kameleoon/kameleoon_client_config.rb
Overview
KameleoonClient configuration which can be used instead of an external configuration file
Constant Summary collapse
- DEFAULT_REFRESH_INTERVAL_MINUTES =
60
- DEFAULT_SESSION_DURATION_MINUTES =
30
- DEFAULT_TIMEOUT_MILLISECONDS =
10_000
- DEFAULT_TRACKING_INTERVAL_MILLISECONDS =
1000
- MIN_TRACKING_INTERVAL_MILLISECONDS =
300
- MAX_TRACKING_INTERVAL_MILLISECONDS =
1000
Instance Attribute Summary collapse
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
readonly
Returns the value of attribute client_secret.
-
#default_timeout_millisecond ⇒ Object
readonly
Returns the value of attribute default_timeout_millisecond.
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#refresh_interval_second ⇒ Object
readonly
Returns the value of attribute refresh_interval_second.
-
#session_duration_second ⇒ Object
readonly
Returns the value of attribute session_duration_second.
-
#top_level_domain ⇒ Object
readonly
Returns the value of attribute top_level_domain.
-
#tracking_interval_second ⇒ Object
readonly
Returns the value of attribute tracking_interval_second.
-
#verbose_mode ⇒ Object
readonly
Returns the value of attribute verbose_mode.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(client_id, client_secret, refresh_interval_minute: DEFAULT_REFRESH_INTERVAL_MINUTES, session_duration_minute: DEFAULT_SESSION_DURATION_MINUTES, default_timeout_millisecond: DEFAULT_TIMEOUT_MILLISECONDS, tracking_interval_millisecond: DEFAULT_TRACKING_INTERVAL_MILLISECONDS, environment: nil, top_level_domain: nil, verbose_mode: nil) ⇒ KameleoonClientConfig
constructor
verbose_mode is DEPRECATED.
- #to_s ⇒ Object
Constructor Details
#initialize(client_id, client_secret, refresh_interval_minute: DEFAULT_REFRESH_INTERVAL_MINUTES, session_duration_minute: DEFAULT_SESSION_DURATION_MINUTES, default_timeout_millisecond: DEFAULT_TIMEOUT_MILLISECONDS, tracking_interval_millisecond: DEFAULT_TRACKING_INTERVAL_MILLISECONDS, environment: nil, top_level_domain: nil, verbose_mode: nil) ⇒ KameleoonClientConfig
verbose_mode is DEPRECATED. Please use ‘KameleoonLogger.log_level` instead.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/kameleoon/kameleoon_client_config.rb', line 33 def initialize( client_id, client_secret, refresh_interval_minute: DEFAULT_REFRESH_INTERVAL_MINUTES, session_duration_minute: DEFAULT_SESSION_DURATION_MINUTES, default_timeout_millisecond: DEFAULT_TIMEOUT_MILLISECONDS, tracking_interval_millisecond: DEFAULT_TRACKING_INTERVAL_MILLISECONDS, environment: nil, top_level_domain: nil, verbose_mode: nil ) raise Exception::ConfigCredentialsInvalid, 'Client ID is not specified' if client_id&.empty? != false raise Exception::ConfigCredentialsInvalid, 'Client secret is not specified' if client_secret&.empty? != false unless verbose_mode.nil? Logging::KameleoonLogger.warning( '[DEPRECATION] `verbose_mode` is deprecated. Please use `KameleoonLogger.log_level` instead.' ) end @verbose_mode = verbose_mode @client_id = client_id @client_secret = client_secret if refresh_interval_minute.nil? refresh_interval_minute = DEFAULT_REFRESH_INTERVAL_MINUTES elsif refresh_interval_minute <= 0 Logging::KameleoonLogger.warning(lambda { 'Configuration refresh interval must have positive value. ' \ "Default refresh interval (#{DEFAULT_REFRESH_INTERVAL_MINUTES} minutes) was applied." }) refresh_interval_minute = DEFAULT_REFRESH_INTERVAL_MINUTES end @refresh_interval_second = refresh_interval_minute * 60 if session_duration_minute.nil? session_duration_minute = DEFAULT_SESSION_DURATION_MINUTES elsif session_duration_minute <= 0 Logging::KameleoonLogger.warning(lambda { 'Session duration must have positive value. ' \ "Default session duration (#{DEFAULT_SESSION_DURATION_MINUTES} minutes) was applied." }) session_duration_minute = DEFAULT_SESSION_DURATION_MINUTES end @session_duration_second = session_duration_minute * 60 if default_timeout_millisecond.nil? @default_timeout_millisecond = DEFAULT_TIMEOUT_MILLISECONDS elsif default_timeout_millisecond <= 0 Logging::KameleoonLogger.warning(lambda { 'Default timeout must have positive value. ' \ "Default timeout (#{DEFAULT_TIMEOUT_MILLISECONDS} ms) was applied." }) @default_timeout_millisecond = DEFAULT_TIMEOUT_MILLISECONDS else @default_timeout_millisecond = default_timeout_millisecond end if tracking_interval_millisecond.nil? tracking_interval_millisecond = DEFAULT_TRACKING_INTERVAL_MILLISECONDS elsif tracking_interval_millisecond < MIN_TRACKING_INTERVAL_MILLISECONDS Logging::KameleoonLogger.warning(lambda { 'Tracking interval must not be shorter than ' \ "#{MIN_TRACKING_INTERVAL_MILLISECONDS} ms. Minimum possible interval was applied." }) tracking_interval_millisecond = MIN_TRACKING_INTERVAL_MILLISECONDS elsif tracking_interval_millisecond > MAX_TRACKING_INTERVAL_MILLISECONDS Logging::KameleoonLogger.warning(lambda { 'Tracking interval must not be longer than ' \ "#{MAX_TRACKING_INTERVAL_MILLISECONDS} ms. Maximum possible interval was applied." }) tracking_interval_millisecond = MAX_TRACKING_INTERVAL_MILLISECONDS end @tracking_interval_second = tracking_interval_millisecond / 1000.0 @environment = environment if top_level_domain.nil? Logging::KameleoonLogger.warning( 'Setting top level domain is strictly recommended, otherwise you may have problems when using subdomains.' ) end @top_level_domain = Utils::Domain.validate_top_level_domain(top_level_domain) end |
Instance Attribute Details
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
15 16 17 |
# File 'lib/kameleoon/kameleoon_client_config.rb', line 15 def client_id @client_id end |
#client_secret ⇒ Object (readonly)
Returns the value of attribute client_secret.
15 16 17 |
# File 'lib/kameleoon/kameleoon_client_config.rb', line 15 def client_secret @client_secret end |
#default_timeout_millisecond ⇒ Object (readonly)
Returns the value of attribute default_timeout_millisecond.
15 16 17 |
# File 'lib/kameleoon/kameleoon_client_config.rb', line 15 def default_timeout_millisecond @default_timeout_millisecond end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
15 16 17 |
# File 'lib/kameleoon/kameleoon_client_config.rb', line 15 def environment @environment end |
#refresh_interval_second ⇒ Object (readonly)
Returns the value of attribute refresh_interval_second.
15 16 17 |
# File 'lib/kameleoon/kameleoon_client_config.rb', line 15 def refresh_interval_second @refresh_interval_second end |
#session_duration_second ⇒ Object (readonly)
Returns the value of attribute session_duration_second.
15 16 17 |
# File 'lib/kameleoon/kameleoon_client_config.rb', line 15 def session_duration_second @session_duration_second end |
#top_level_domain ⇒ Object (readonly)
Returns the value of attribute top_level_domain.
15 16 17 |
# File 'lib/kameleoon/kameleoon_client_config.rb', line 15 def top_level_domain @top_level_domain end |
#tracking_interval_second ⇒ Object (readonly)
Returns the value of attribute tracking_interval_second.
15 16 17 |
# File 'lib/kameleoon/kameleoon_client_config.rb', line 15 def tracking_interval_second @tracking_interval_second end |
#verbose_mode ⇒ Object (readonly)
Returns the value of attribute verbose_mode.
15 16 17 |
# File 'lib/kameleoon/kameleoon_client_config.rb', line 15 def verbose_mode @verbose_mode end |
Class Method Details
.read_from_yaml(path) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/kameleoon/kameleoon_client_config.rb', line 119 def self.read_from_yaml(path) yaml = YAML.load_file(path) if File.exist?(path) if yaml.nil? Logging::KameleoonLogger.warning(-> { "Configuration file with path '#{path}' does not exist" }) yaml = {} end KameleoonClientConfig.new( yaml['client_id'], yaml['client_secret'], refresh_interval_minute: yaml['refresh_interval_minute'], session_duration_minute: yaml['session_duration_minute'], default_timeout_millisecond: yaml['default_timeout_millisecond'], tracking_interval_millisecond: yaml['tracking_interval_millisecond'], environment: yaml['environment'], top_level_domain: yaml['top_level_domain'], verbose_mode: yaml['verbose_mode'] ) end |
Instance Method Details
#to_s ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/kameleoon/kameleoon_client_config.rb', line 19 def to_s 'KameleoonClientConfig{' \ "client_id:'#{Utils::Strval.secret(@client_id)}'," \ "client_secret:'#{Utils::Strval.secret(@client_secret)}'," \ "refresh_interval_second:#{@refresh_interval_second}," \ "session_duration_second:#{@session_duration_second}," \ "environment:'#{@environment}'," \ "default_timeout_millisecond:#{@default_timeout_millisecond}," \ "top_level_domain:'#{@top_level_domain}'," \ "verbose_mode:#{verbose_mode}" \ '}' end |