kameleoon-client-ruby 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c3ada1f2651143c67ac458a8adab629e1d6ad17e95a204809a0a2b44f0ee3a28
4
- data.tar.gz: 306fab877c00913cc4b13cecfdf9e773c2bb735be110747df37d509b537d2e01
3
+ metadata.gz: 7d51a71ea79cd23f422a5235fce6f2e3fb94cae538b01222dd4c23b770985e59
4
+ data.tar.gz: 29f2501a20ffedf1637ee6d441b637358982761955d6235317f49b5284f17b70
5
5
  SHA512:
6
- metadata.gz: 38ff8932ce2f9a0e9d72644ae47de0d0f34434943f33328f0459607e34769c83e64ff6325989f9722cc8cb202d440d5d8891dea073179d269e01d6b49fa361f9
7
- data.tar.gz: b3ee0f99356eac881b01970269cde022435872c270268ffc6ec8c0dc0d31abe3816914a497edb15e744810f60190165c84424f4799876ff56d1e24e1590d56f8
6
+ metadata.gz: 7f4855238a2e8731458757336bc964a36d537e77e7e1b30eb73b5c7e270ee59ee021813b620c0997b9781a8e062b10f3a4797eaceffcd9ca731e5e86f11f1e12
7
+ data.tar.gz: e7d3659d4de54bc0be3aadf6ed96d213bf148ce481306ad8668b589dd892a26a74e78206c6d78dd9577c915e96bab1351c19f08c95ce8b4ae85aaef237b6bd6f
@@ -37,21 +37,13 @@ module Kameleoon
37
37
  ##
38
38
  # You should create Client with the Client Factory only.
39
39
  #
40
- def initialize(site_code, path_config_file, interval, default_timeout, client_id = nil, client_secret = nil)
41
- config = YAML.load_file(path_config_file)
40
+ def initialize(site_code, config)
42
41
  @site_code = site_code
43
- @default_timeout = config['default_timeout'] || default_timeout # in ms
44
- refresh_interval = config['actions_configuration_refresh_interval']
45
- @interval = refresh_interval.nil? ? interval : "#{refresh_interval}m"
42
+ read_config(config)
46
43
  @real_time_configuration_service = nil
47
44
  @update_configuration_handler = nil
48
45
  @fetch_configuration_update_job = nil
49
- @client_id = client_id || config['client_id']
50
- @client_secret = client_secret || config['client_secret']
51
- @data_maximum_size = config['visitor_data_maximum_size'] || 500 # mb
52
- @environment = config['environment'] || DEFAULT_ENVIRONMENT
53
46
  @settings = Kameleoon::Configuration::Settings.new
54
- @verbose_mode = config['verbose_mode'] || false
55
47
  @experiments = []
56
48
  @feature_flags = []
57
49
  @data = {}
@@ -513,11 +505,23 @@ module Kameleoon
513
505
  private
514
506
 
515
507
  REFERENCE = 0
516
- DEFAULT_ENVIRONMENT = 'production'
517
508
  CACHE_EXPIRATION_TIMEOUT = 5
518
509
  attr :site_code, :client_id, :client_secret, :access_token, :experiments, :feature_flags, :scheduler, :data,
519
510
  :tracking_url, :default_timeout, :interval, :memory_limit, :verbose_mode
520
511
 
512
+ def read_config(config)
513
+ @client_id = config.client_id
514
+ @client_secret = config.client_secret
515
+ @default_timeout = config.default_timeout # in ms
516
+ @interval = "#{config.configuration_refresh_interval}m"
517
+ @data_maximum_size = config.visitor_data_maximum_size
518
+ @environment = config.environment
519
+ @verbose_mode = config.verbose_mode
520
+ if @client_id.nil? || @client_secret.nil?
521
+ warn 'Kameleoon SDK: Credentials are invalid: client_id or client_secret (or both) are empty'
522
+ end
523
+ end
524
+
521
525
  def fetch_configuration
522
526
  Rufus::Scheduler.singleton.in '0s' do
523
527
  log('Initial configuration fetch is started.')
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kameleoon
4
+ # Client configuration which can be used instead of an external configuration file
5
+ class ClientConfig
6
+ CONFIGURATION_UPDATE_INTERVAL = 60
7
+ VISITOR_DATA_MAXIMUM_SIZE = 500
8
+ DEFAULT_TIMEOUT = 2000 # milli-seconds
9
+
10
+ attr_reader :client_id, :client_secret, :data_refresh_interval, :default_timeout, :configuration_refresh_interval,
11
+ :visitor_data_maximum_size, :environment, :verbose_mode
12
+
13
+ def initialize(
14
+ client_id: nil,
15
+ client_secret: nil,
16
+ configuration_refresh_interval: CONFIGURATION_UPDATE_INTERVAL,
17
+ default_timeout: DEFAULT_TIMEOUT,
18
+ visitor_data_maximum_size: VISITOR_DATA_MAXIMUM_SIZE,
19
+ environment: nil,
20
+ verbose_mode: false
21
+ )
22
+ @client_id = client_id
23
+ @client_secret = client_secret
24
+ @configuration_refresh_interval = configuration_refresh_interval || CONFIGURATION_UPDATE_INTERVAL
25
+ @default_timeout = default_timeout || DEFAULT_TIMEOUT
26
+ @visitor_data_maximum_size = visitor_data_maximum_size || VISITOR_DATA_MAXIMUM_SIZE
27
+ @environment = environment
28
+ @verbose_mode = verbose_mode || false
29
+ end
30
+
31
+ def self.make_from_yaml(yaml)
32
+ yaml ||= {}
33
+ ClientConfig.new(
34
+ client_id: yaml['client_id'],
35
+ client_secret: yaml['client_secret'],
36
+ configuration_refresh_interval: yaml['actions_configuration_refresh_interval'],
37
+ default_timeout: yaml['default_timeout'],
38
+ visitor_data_maximum_size: yaml['visitor_data_maximum_size'],
39
+ environment: yaml['environment'],
40
+ verbose_mode: yaml['verbose_mode']
41
+ )
42
+ end
43
+ end
44
+ end
@@ -1,29 +1,43 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'kameleoon/client'
4
+ require 'kameleoon/client_config'
4
5
 
5
6
  module Kameleoon
6
7
  # A Factory class for creating kameleoon clients
7
8
  module ClientFactory
8
- CONFIGURATION_UPDATE_INTERVAL = '60m'
9
9
  CONFIG_PATH = '/etc/kameleoon/client-ruby.yaml'
10
- DEFAULT_TIMEOUT = 2000 # milli-seconds
11
10
 
12
11
  @clients = {}
13
12
 
14
- def self.create(site_code, config_path = CONFIG_PATH, client_id = nil, client_secret = nil)
15
- if @clients[site_code].nil?
16
- client = Client.new(site_code, config_path, CONFIGURATION_UPDATE_INTERVAL,
17
- DEFAULT_TIMEOUT, client_id, client_secret)
13
+ def self.create(site_code, config_path = CONFIG_PATH, config: nil)
14
+ if config.nil?
15
+ config_yaml = YAML.load_file(config_path) if File.exist?(config_path)
16
+ if config_yaml.nil?
17
+ warn "Kameleoon SDK: Configuration file with path #{config_path} does not exist" if config_yaml.nil?
18
+ config_yaml = {}
19
+ end
20
+ end
21
+ environment = config&.environment || (config_yaml || {})['environment']
22
+ client = @clients[get_client_key(site_code, environment)]
23
+ if client.nil?
24
+ config = ClientConfig.make_from_yaml(config_yaml) if config.nil?
25
+ client = Client.new(site_code, config)
18
26
  client.send(:log, "Client created with site code: #{site_code}")
19
27
  client.send(:fetch_configuration)
20
28
  @clients.store(site_code, client)
21
29
  end
22
- @clients[site_code]
30
+ client
31
+ end
32
+
33
+ def self.forget(site_code, environment = '')
34
+ @clients.delete(get_client_key(site_code, environment))
23
35
  end
24
36
 
25
- def self.forget(site_code)
26
- @clients.delete(site_code)
37
+ private_class_method
38
+
39
+ def self.get_client_key(site_code, environment)
40
+ site_code + (environment || '')
27
41
  end
28
42
  end
29
43
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Kameleoon
4
4
  SDK_NAME = 'RUBY'
5
- SDK_VERSION = '2.2.0'
5
+ SDK_VERSION = '2.3.0'
6
6
 
7
7
  # SdkManager is a helper method for fetching / obtaining version of SDK from string
8
8
  class SdkVersion
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kameleoon-client-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kameleoon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-14 00:00:00.000000000 Z
11
+ date: 2023-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: em-http-request
@@ -76,6 +76,7 @@ files:
76
76
  - README.md
77
77
  - lib/kameleoon.rb
78
78
  - lib/kameleoon/client.rb
79
+ - lib/kameleoon/client_config.rb
79
80
  - lib/kameleoon/configuration/experiment.rb
80
81
  - lib/kameleoon/configuration/feature_flag.rb
81
82
  - lib/kameleoon/configuration/rule.rb