kameleoon-client-ruby 3.17.3 → 3.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c0d4abc01c7fc06b5cc0b0613dde8a40e004d6d11b358092398498a2c59ee766
4
- data.tar.gz: ec89564082cb1b270a9453c63741f1ae505c46dcbbc52fd583927b603a98a26f
3
+ metadata.gz: 916619df3b6cdccaf7999889e5f646bcbbfcba29eb6960bbf3374607100c1efe
4
+ data.tar.gz: d38b503e8cbf9d6df0a0639292b8b5436a59b4544ea53b45ab4d738a5b556dec
5
5
  SHA512:
6
- metadata.gz: 7b1e31f65a0c314810b5e020570d52cee18bc1a6cbe41bbdc564114dd9136257e78c06fd55b07a04106d42bfa996a3f979438647105df7d18d299cdb282dbc1d
7
- data.tar.gz: df793d553ff36d2e98e118fe5c2bc846417900958d81262bb9ec7fe0dc233a86420bb9c93b793b91beec097a073dba81907dee2290fa1b7b82ddf03dd297a59f
6
+ metadata.gz: 1d154b47a9375184a1e2375cce4654b7615f51f37f656db8124228e0cce3f83414185f0ae53b40d704432c3d2ae1abb05d6700af504ce015b77df22d46caa02e
7
+ data.tar.gz: 730008de9284005e1401352e48bf2707ae8707456f04e8131cfda0e6b666ba59cf5399f541d01b0b5a5baba83ac7acd78a79e82920a191bc7c49fa6dab5e4dd3
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'data'
4
+
5
+ module Kameleoon
6
+ # ApplicationVersion contains information about the application version on the visitor's device.
7
+ # It is used for targeting by application version.
8
+ class ApplicationVersion < Data
9
+ attr_reader :version
10
+
11
+ # @param [String] version Application version (semantic versioning: major, major.minor, or major.minor.patch)
12
+ def initialize(version)
13
+ super(DataType::APPLICATION_VERSION)
14
+ @version = version
15
+ end
16
+
17
+ def to_s
18
+ "ApplicationVersion{version:#{@version}}"
19
+ end
20
+ end
21
+ end
@@ -20,6 +20,7 @@ module Kameleoon
20
20
  GEOLOCATION = 'GEOLOCATION'
21
21
  VISITOR_VISITS = 'VISITOR_VISITS'
22
22
  TARGETED_SEGMENT = 'TARGETED_SEGMENT'
23
+ APPLICATION_VERSION = 'APPLICATION_VERSION'
23
24
  end
24
25
 
25
26
  module DataState
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'concurrent'
4
4
  require 'time'
5
+ require 'kameleoon/data/application_version'
5
6
  require 'kameleoon/data/browser'
6
7
  require 'kameleoon/data/cbscores'
7
8
  require 'kameleoon/data/conversion'
@@ -103,6 +104,13 @@ module Kameleoon
103
104
  operating_system
104
105
  end
105
106
 
107
+ def application_version
108
+ application_version = @data.application_version
109
+ Logging::KameleoonLogger.debug('CALL/RETURN: Visitor.application_version -> (application_version: %s)',
110
+ application_version)
111
+ application_version
112
+ end
113
+
106
114
  def cookie
107
115
  cookie = @data.cookie
108
116
  Logging::KameleoonLogger.debug('CALL/RETURN: Visitor.cookie -> (cookie: %s)', cookie)
@@ -275,6 +283,8 @@ module Kameleoon
275
283
  @data.cookie = data
276
284
  when OperatingSystem
277
285
  @data.set_operating_system(data, overwrite)
286
+ when ApplicationVersion
287
+ @data.set_application_version(data, overwrite)
278
288
  when Geolocation
279
289
  @data.set_geolocation(data, overwrite)
280
290
  when KcsHeat
@@ -305,7 +315,8 @@ module Kameleoon
305
315
  end
306
316
 
307
317
  class VisitorData
308
- attr_reader :time_started, :mutex, :device, :browser, :geolocation, :operating_system, :visitor_visits
318
+ attr_reader :time_started, :mutex, :device, :browser, :geolocation, :operating_system, :visitor_visits,
319
+ :application_version
309
320
  attr_accessor :last_activity_time, :legal_consent, :user_agent, :cookie, :kcs_heat, :cbscores,
310
321
  :mapping_identifier, :forced_variations, :simulated_variations
311
322
 
@@ -462,6 +473,10 @@ module Kameleoon
462
473
  @operating_system = operating_system if overwrite || @operating_system.nil?
463
474
  end
464
475
 
476
+ def set_application_version(application_version, overwrite)
477
+ @application_version = application_version if overwrite || @application_version.nil?
478
+ end
479
+
465
480
  def set_cbscores(cbs, overwrite)
466
481
  @cbscores = cbs if overwrite || @cbscores.nil?
467
482
  end
@@ -72,10 +72,10 @@ module Kameleoon
72
72
  @visitors.size
73
73
  end
74
74
 
75
- def add_data(visitor_code, *args, overwrite: true)
75
+ def add_data(visitor_code, *args, overwrite: true, track: true)
76
76
  Logging::KameleoonLogger.debug(
77
- "CALL: VisitorManager.add_data(visitor_code: '%s', args: %s, overwrite: %s)",
78
- visitor_code, args, overwrite
77
+ "CALL: VisitorManager.add_data(visitor_code: '%s', args: %s, overwrite: %s, track: %s)",
78
+ visitor_code, args, overwrite, track
79
79
  )
80
80
  visitor = get_or_create_visitor(visitor_code)
81
81
  cdi = @data_manager.data_file.custom_data_info
@@ -87,12 +87,13 @@ module Kameleoon
87
87
  when Conversion
88
88
  data = process_conversion(data, cdi)
89
89
  end
90
+ data.mark_as_sent if !track && data.respond_to?(:mark_as_sent)
90
91
  args[i] = data
91
92
  end
92
93
  visitor.add_data(*args, overwrite: overwrite)
93
94
  Logging::KameleoonLogger.debug(
94
- "RETURN: VisitorManager.add_data(visitor_code: '%s', args: %s, overwrite: %s) -> (visitor)",
95
- visitor_code, args, overwrite
95
+ "RETURN: VisitorManager.add_data(visitor_code: '%s', args: %s, overwrite: %s, track: %s) -> (visitor)",
96
+ visitor_code, args, overwrite, track
96
97
  )
97
98
  visitor
98
99
  end
@@ -162,17 +162,18 @@ module Kameleoon
162
162
  #
163
163
  # @param [String] visitor_code Visitor code
164
164
  # @param [...Data] data Data to associate with the visitor code
165
+ # @param [Bool] track A boolean indicating whether the data should be tracked (sent to server). Default is true.
165
166
  #
166
167
  # @raise [Kameleoon::Exception::VisitorCodeInvalid] If the visitor code is empty or longer than 255 chars
167
168
  #
168
- def add_data(visitor_code, *args)
169
- Logging::KameleoonLogger.info("CALL: KameleoonClient.add_data(visitor_code: '%s', args: %s)",
170
- visitor_code, args)
169
+ def add_data(visitor_code, *args, track: true)
170
+ Logging::KameleoonLogger.info("CALL: KameleoonClient.add_data(visitor_code: '%s', args: %s, track: %s)",
171
+ visitor_code, args, track)
171
172
  Utils::VisitorCode.validate(visitor_code)
172
- @visitor_manager.add_data(visitor_code, *args)
173
+ @visitor_manager.add_data(visitor_code, *args, track: track)
173
174
  Logging::KameleoonLogger.info(
174
- "RETURN: KameleoonClient.add_data(visitor_code: '%s', args: %s)",
175
- visitor_code, args
175
+ "RETURN: KameleoonClient.add_data(visitor_code: '%s', args: %s, track: %s)",
176
+ visitor_code, args, track
176
177
  )
177
178
  end
178
179
 
@@ -9,8 +9,8 @@ module Kameleoon
9
9
  DEFAULT_SESSION_DURATION_MINUTES = 30
10
10
  DEFAULT_TIMEOUT_MILLISECONDS = 10_000
11
11
  DEFAULT_TRACKING_INTERVAL_MILLISECONDS = 1000
12
- MIN_TRACKING_INTERVAL_MILLISECONDS = 300
13
- MAX_TRACKING_INTERVAL_MILLISECONDS = 1000
12
+ MIN_TRACKING_INTERVAL_MILLISECONDS = 1000
13
+ MAX_TRACKING_INTERVAL_MILLISECONDS = 5000
14
14
 
15
15
  attr_reader :client_id, :client_secret, :refresh_interval_second, :session_duration_second,
16
16
  :default_timeout_millisecond, :tracking_interval_second, :environment, :top_level_domain,
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'kameleoon/logging/kameleoon_logger'
4
+
5
+ module Kameleoon
6
+ # SemVersion is a utility class for semantic version comparison
7
+ class SemVersion
8
+ include Comparable
9
+
10
+ attr_reader :major, :minor, :patch
11
+
12
+ def initialize(major = 0, minor = 0, patch = 0)
13
+ @major = major
14
+ @minor = minor
15
+ @patch = patch
16
+ end
17
+
18
+ def <=>(other)
19
+ return nil unless other.is_a?(SemVersion)
20
+
21
+ c = @major <=> other.major
22
+ return c unless c.zero?
23
+
24
+ c = @minor <=> other.minor
25
+ return c unless c.zero?
26
+
27
+ @patch <=> other.patch
28
+ end
29
+
30
+ def to_f
31
+ "#{@major}.#{@minor}".to_f
32
+ end
33
+
34
+ def self.from_string(version_string)
35
+ return nil unless version_string.is_a?(String)
36
+
37
+ versions = [0, 0, 0]
38
+ version_parts = version_string.split('.')
39
+ return nil unless version_parts.length >= 1
40
+
41
+ version_parts.each_with_index do |part, i|
42
+ break if i >= 3
43
+
44
+ begin
45
+ versions[i] = Integer(part)
46
+ rescue ArgumentError
47
+ Logging::KameleoonLogger.error("Invalid version component, index: %s, value: '%s'", i, part)
48
+ return nil
49
+ end
50
+ end
51
+
52
+ SemVersion.new(versions[0], versions[1], versions[2])
53
+ end
54
+ end
55
+ end
@@ -31,6 +31,7 @@ module Kameleoon
31
31
  SAME_DAY_VISITS = 'SAME_DAY_VISITS'
32
32
  NEW_VISITORS = 'NEW_VISITORS'
33
33
  HEAT_SLICE = 'HEAT_SLICE'
34
+ APPLICATION_VERSION = 'APPLICATION_VERSION'
34
35
  end
35
36
 
36
37
  module Operator
@@ -1,4 +1,5 @@
1
1
  require_relative 'conditions/custom_datum'
2
+ require_relative 'conditions/version_condition'
2
3
  require_relative 'conditions/target_experiment_condition'
3
4
  require_relative 'conditions/target_feature_flag_condition'
4
5
  require_relative 'conditions/target_personalization_condition'
@@ -77,6 +78,8 @@ module Kameleoon
77
78
  TimeElapsedSinceVisitCondition.new(condition_json)
78
79
  when ConditionType::HEAT_SLICE
79
80
  KcsHeatRangeCondition.new(condition_json)
81
+ when ConditionType::APPLICATION_VERSION
82
+ VersionCondition.new(condition_json)
80
83
  else
81
84
  Logging::KameleoonLogger.info("Unexpected TargetingConditionType: '%s'", cond_type)
82
85
  UnknownCondition.new(condition_json)
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'kameleoon/data/browser'
4
4
  require 'kameleoon/logging/kameleoon_logger'
5
- require 'kameleoon/sdk_version'
5
+ require 'kameleoon/sem_version'
6
6
 
7
7
  module Kameleoon
8
8
  # @api private
@@ -33,7 +33,7 @@ module Kameleoon
33
33
 
34
34
  return true if @version.nil?
35
35
 
36
- version_number = SdkVersion.get_float_version(@version)
36
+ version_number = SemVersion.from_string(@version)&.to_f || Float::NAN
37
37
  return false if version_number.nan?
38
38
 
39
39
  case @version_match_type
@@ -1,8 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'kameleoon/data/data'
4
- require 'kameleoon/logging/kameleoon_logger'
5
3
  require 'kameleoon/version'
4
+ require_relative 'version_condition'
6
5
 
7
6
  module Kameleoon
8
7
  # @api private
@@ -18,12 +17,10 @@ module Kameleoon
18
17
  end
19
18
 
20
19
  # SdkLanguageCondition is a condition for checking targeting sdk type and version
21
- class SdkLanguageCondition < Condition
20
+ class SdkLanguageCondition < VersionCondition
22
21
  def initialize(json_condition)
23
22
  super(json_condition)
24
23
  @sdk_language = json_condition['sdkLanguage']
25
- @version = json_condition['version']
26
- @operator = json_condition['versionMatchType']
27
24
  end
28
25
 
29
26
  def check(data)
@@ -33,34 +30,9 @@ module Kameleoon
33
30
  private
34
31
 
35
32
  def check_targeting(sdk_info)
36
- return false if @sdk_language != sdk_info.language
37
-
38
- return true if @version.nil?
39
-
40
- version_components_condition = SdkVersion.get_version_components(@version)
41
- version_components_sdk_info = SdkVersion.get_version_components(sdk_info.version)
42
-
43
- return false if version_components_condition.nil? || version_components_sdk_info.nil?
44
-
45
- major_condition, minor_condition, patch_condition = version_components_condition
46
- major_sdk, minor_sdk, patch_sdk = version_components_sdk_info
47
-
48
- case @operator
49
- when Operator::EQUAL
50
- major_sdk == major_condition && minor_sdk == minor_condition && patch_sdk == patch_condition
51
- when Operator::GREATER
52
- major_sdk > major_condition ||
53
- (major_sdk == major_condition && minor_sdk > minor_condition) ||
54
- (major_sdk == major_condition && minor_sdk == minor_condition && patch_sdk > patch_condition)
55
- when Operator::LOWER
56
- major_sdk < major_condition ||
57
- (major_sdk == major_condition && minor_sdk < minor_condition) ||
58
- (major_sdk == major_condition && minor_sdk == minor_condition && patch_sdk < patch_condition)
59
- else
60
- Logging::KameleoonLogger.error("Unexpected comparing operation for 'SdkLanguage' condition: '#{@operator}'")
61
- false
62
- end
33
+ @sdk_language == sdk_info.language &&
34
+ (@version.nil? || compare_with_version(sdk_info.version))
63
35
  end
64
36
  end
65
37
  end
66
- end
38
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'kameleoon/logging/kameleoon_logger'
4
+ require 'kameleoon/sem_version'
5
+ require 'kameleoon/targeting/condition'
6
+
7
+ module Kameleoon
8
+ # @api private
9
+ module Targeting
10
+ # VersionCondition is a base class for conditions that compare versions.
11
+ # Subclasses should implement `check` method and call `compare_with_version` for version comparison.
12
+ class VersionCondition < Condition
13
+ def initialize(json_condition)
14
+ super(json_condition)
15
+ @version = json_condition['version']
16
+ @version_match_type = json_condition['versionMatchType']
17
+ @cached_version_condition = nil
18
+ end
19
+
20
+ def check(data)
21
+ data.is_a?(String) && compare_with_version(data)
22
+ end
23
+
24
+ protected
25
+
26
+ def compare_with_version(version)
27
+ @cached_version_condition ||= SemVersion.from_string(@version)
28
+ version_compare = SemVersion.from_string(version)
29
+
30
+ if @cached_version_condition.nil? || version_compare.nil?
31
+ Logging::KameleoonLogger.error(
32
+ "VersionCondition has unexpected values to compare, condition version: '%s', provided version: '%s'",
33
+ @version, version
34
+ )
35
+ return false
36
+ end
37
+
38
+ case @version_match_type
39
+ when Operator::EQUAL
40
+ version_compare == @cached_version_condition
41
+ when Operator::GREATER
42
+ version_compare > @cached_version_condition
43
+ when Operator::LOWER
44
+ version_compare < @cached_version_condition
45
+ else
46
+ Logging::KameleoonLogger.error(
47
+ "Unexpected comparing operation for '%s' condition: '%s'",
48
+ type, @version_match_type
49
+ )
50
+ false
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -92,6 +92,8 @@ module Kameleoon
92
92
  condition_data = VisitNumberTodayCondition::TargetingData.new(visitor&.time_started, visitor&.visitor_visits)
93
93
  when ConditionType::HEAT_SLICE
94
94
  condition_data = visitor&.kcs_heat
95
+ when ConditionType::APPLICATION_VERSION
96
+ condition_data = visitor&.application_version&.version
95
97
  end
96
98
  Logging::KameleoonLogger.debug(
97
99
  "RETURN: TargetingManager.get_condition_data(type: %s, visitor, visitor_code: '%s', campaign_id: %s) -> " \
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kameleoon
4
- SDK_VERSION = '3.17.3'
4
+ SDK_VERSION = '3.18.0'
5
5
  SDK_NAME = 'RUBY'
6
6
  end
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: 3.17.3
4
+ version: 3.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kameleoon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-01-22 00:00:00.000000000 Z
11
+ date: 2026-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: em-http-request
@@ -86,6 +86,7 @@ files:
86
86
  - lib/kameleoon/configuration/variable.rb
87
87
  - lib/kameleoon/configuration/variation.rb
88
88
  - lib/kameleoon/configuration/variation_exposition.rb
89
+ - lib/kameleoon/data/application_version.rb
89
90
  - lib/kameleoon/data/browser.rb
90
91
  - lib/kameleoon/data/cbscores.rb
91
92
  - lib/kameleoon/data/conversion.rb
@@ -145,7 +146,7 @@ files:
145
146
  - lib/kameleoon/real_time/sse_client.rb
146
147
  - lib/kameleoon/real_time/sse_message.rb
147
148
  - lib/kameleoon/real_time/sse_request.rb
148
- - lib/kameleoon/sdk_version.rb
149
+ - lib/kameleoon/sem_version.rb
149
150
  - lib/kameleoon/storage/cache.rb
150
151
  - lib/kameleoon/storage/cache_factory.rb
151
152
  - lib/kameleoon/targeting/condition.rb
@@ -172,6 +173,7 @@ files:
172
173
  - lib/kameleoon/targeting/conditions/target_personalization_condition.rb
173
174
  - lib/kameleoon/targeting/conditions/time_elapsed_since_visit_condition.rb
174
175
  - lib/kameleoon/targeting/conditions/unknown_condition.rb
176
+ - lib/kameleoon/targeting/conditions/version_condition.rb
175
177
  - lib/kameleoon/targeting/conditions/visit_number_today_condition.rb
176
178
  - lib/kameleoon/targeting/conditions/visit_number_total_condition.rb
177
179
  - lib/kameleoon/targeting/conditions/visitor_code_condition.rb
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'kameleoon/logging/kameleoon_logger'
4
-
5
- module Kameleoon
6
- # SdkManager is a helper method for fetching / obtaining version of SDK from string
7
- class SdkVersion
8
- def self.get_version_components(version_string)
9
- versions = [0, 0, 0]
10
-
11
- version_parts = version_string.split('.')
12
- version_parts.each_with_index do |part, i|
13
- versions[i] = Integer(part)
14
- rescue ArgumentError
15
- Logging::KameleoonLogger.error('Invalid version component, index: %s, value: %s', i, part)
16
- return nil
17
- end
18
- versions
19
- end
20
-
21
- def self.get_float_version(version_string)
22
- version_components = get_version_components(version_string)
23
-
24
- return Float::NAN if version_components.nil?
25
-
26
- major = version_components[0]
27
- minor = version_components[1]
28
- "#{major}.#{minor}".to_f
29
- end
30
- end
31
- end