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
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.
-
#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, environment: nil, top_level_domain: nil, verbose_mode: false) ⇒ KameleoonClientConfig
constructor
A new instance of KameleoonClientConfig.
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, environment: nil, top_level_domain: nil, verbose_mode: false) ⇒ KameleoonClientConfig
Returns a new instance of KameleoonClientConfig.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 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 |
# File 'lib/kameleoon/kameleoon_client_config.rb', line 13 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, environment: nil, top_level_domain: nil, verbose_mode: false ) 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 @verbose_mode = verbose_mode || false @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 log('Configuration refresh interval must have positive value. ' \ "Default refresh interval (#{DEFAULT_REFRESH_INTERVAL_MINUTES} minutes) is 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 log('Session duration must have positive value. ' \ "Default session duration (#{DEFAULT_SESSION_DURATION_MINUTES} minutes) is 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 log('Default timeout must have positive value. ' \ "Default timeout (#{DEFAULT_TIMEOUT_MILLISECONDS} ms) is applied.") @default_timeout_millisecond = DEFAULT_TIMEOUT_MILLISECONDS else @default_timeout_millisecond = default_timeout_millisecond end @environment = environment if top_level_domain.nil? log('Setting top level domain is strictly recommended, otherwise you may have problems when using subdomains.') end @top_level_domain = top_level_domain end |
Instance Attribute Details
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
10 11 12 |
# File 'lib/kameleoon/kameleoon_client_config.rb', line 10 def client_id @client_id end |
#client_secret ⇒ Object (readonly)
Returns the value of attribute client_secret.
10 11 12 |
# File 'lib/kameleoon/kameleoon_client_config.rb', line 10 def client_secret @client_secret end |
#default_timeout_millisecond ⇒ Object (readonly)
Returns the value of attribute default_timeout_millisecond.
10 11 12 |
# File 'lib/kameleoon/kameleoon_client_config.rb', line 10 def default_timeout_millisecond @default_timeout_millisecond end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
10 11 12 |
# File 'lib/kameleoon/kameleoon_client_config.rb', line 10 def environment @environment end |
#refresh_interval_second ⇒ Object (readonly)
Returns the value of attribute refresh_interval_second.
10 11 12 |
# File 'lib/kameleoon/kameleoon_client_config.rb', line 10 def refresh_interval_second @refresh_interval_second end |
#session_duration_second ⇒ Object (readonly)
Returns the value of attribute session_duration_second.
10 11 12 |
# File 'lib/kameleoon/kameleoon_client_config.rb', line 10 def session_duration_second @session_duration_second end |
#top_level_domain ⇒ Object (readonly)
Returns the value of attribute top_level_domain.
10 11 12 |
# File 'lib/kameleoon/kameleoon_client_config.rb', line 10 def top_level_domain @top_level_domain end |
#verbose_mode ⇒ Object (readonly)
Returns the value of attribute verbose_mode.
10 11 12 |
# File 'lib/kameleoon/kameleoon_client_config.rb', line 10 def verbose_mode @verbose_mode end |
Class Method Details
.read_from_yaml(path) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/kameleoon/kameleoon_client_config.rb', line 67 def self.read_from_yaml(path) yaml = YAML.load_file(path) if File.exist?(path) if yaml.nil? warn "Kameleoon SDK: 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'], environment: yaml['environment'], top_level_domain: yaml['top_level_domain'], verbose_mode: yaml['verbose_mode'] ) end |