kameleoon-client-ruby 2.0.0 → 2.1.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 +4 -4
- data/lib/kameleoon/client.rb +224 -153
- data/lib/kameleoon/configuration/feature_flag.rb +13 -24
- data/lib/kameleoon/configuration/rule.rb +17 -5
- data/lib/kameleoon/configuration/settings.rb +20 -0
- data/lib/kameleoon/cookie.rb +3 -3
- data/lib/kameleoon/data.rb +24 -18
- data/lib/kameleoon/hybrid/manager.rb +60 -0
- data/lib/kameleoon/real_time/real_time_configuration_service.rb +98 -0
- data/lib/kameleoon/real_time/real_time_event.rb +22 -0
- data/lib/kameleoon/real_time/sse_client.rb +111 -0
- data/lib/kameleoon/real_time/sse_message.rb +23 -0
- data/lib/kameleoon/real_time/sse_request.rb +59 -0
- data/lib/kameleoon/storage/cache.rb +84 -0
- data/lib/kameleoon/storage/cache_factory.rb +23 -0
- data/lib/kameleoon/targeting/condition.rb +4 -4
- data/lib/kameleoon/targeting/conditions/custom_datum.rb +60 -25
- data/lib/kameleoon/targeting/conditions/exclusive_experiment.rb +1 -1
- data/lib/kameleoon/targeting/conditions/target_experiment.rb +2 -2
- data/lib/kameleoon/version.rb +1 -1
- metadata +25 -3
- data/lib/kameleoon/configuration/feature_flag_v2.rb +0 -30
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'set'
|
4
|
+
require 'json'
|
3
5
|
require 'kameleoon/targeting/condition'
|
4
6
|
require 'kameleoon/exceptions'
|
5
7
|
|
@@ -14,7 +16,7 @@ module Kameleoon
|
|
14
16
|
@index = json_condition['customDataIndex']
|
15
17
|
|
16
18
|
if json_condition['valueMatchType'].nil?
|
17
|
-
raise Exception::
|
19
|
+
raise Exception::NotFound.new('valueMatchType'), 'valueMatchType missed'
|
18
20
|
end
|
19
21
|
|
20
22
|
@operator = json_condition['valueMatchType']
|
@@ -24,10 +26,22 @@ module Kameleoon
|
|
24
26
|
@type = ConditionType::CUSTOM_DATUM
|
25
27
|
|
26
28
|
if json_condition['include'].nil? && json_condition['isInclude'].nil?
|
27
|
-
raise Exception::
|
29
|
+
raise Exception::NotFound.new('include / isInclude missed'), 'include / isInclude missed'
|
28
30
|
end
|
29
31
|
|
30
32
|
@include = json_condition['include'] || json_condition['isInclude']
|
33
|
+
|
34
|
+
@op = {
|
35
|
+
Operator::MATCH.to_s => method(:op_match),
|
36
|
+
Operator::CONTAINS.to_s => method(:op_contains),
|
37
|
+
Operator::EXACT.to_s => method(:op_exact),
|
38
|
+
Operator::EQUAL.to_s => method(:op_equal),
|
39
|
+
Operator::GREATER.to_s => method(:op_greater),
|
40
|
+
Operator::LOWER.to_s => method(:op_lower),
|
41
|
+
Operator::IS_TRUE.to_s => method(:op_is_true),
|
42
|
+
Operator::IS_FALSE.to_s => method(:op_is_false),
|
43
|
+
Operator::AMONG_VALUES.to_s => method(:op_among_values),
|
44
|
+
}[@operator]
|
31
45
|
end
|
32
46
|
|
33
47
|
def check(datas)
|
@@ -35,32 +49,53 @@ module Kameleoon
|
|
35
49
|
custom_data = datas.select { |data| data.instance == DataType::CUSTOM && data.id == @index }.last
|
36
50
|
if custom_data.nil?
|
37
51
|
is_targeted = (@operator == Operator::UNDEFINED.to_s)
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
when Operator::CONTAINS.to_s
|
43
|
-
is_targeted = custom_data.value.to_s.include? @value
|
44
|
-
when Operator::EXACT.to_s
|
45
|
-
is_targeted = custom_data.value.to_s == @value.to_s
|
46
|
-
when Operator::EQUAL.to_s
|
47
|
-
is_targeted = custom_data.value.to_f == @value.to_f
|
48
|
-
when Operator::GREATER.to_s
|
49
|
-
is_targeted = custom_data.value.to_f > @value.to_f
|
50
|
-
when Operator::LOWER.to_s
|
51
|
-
is_targeted = custom_data.value.to_f < @value.to_f
|
52
|
-
when Operator::IS_TRUE.to_s
|
53
|
-
is_targeted = custom_data.value == 'true'
|
54
|
-
when Operator::IS_FALSE.to_s
|
55
|
-
is_targeted = custom_data.value == 'false'
|
56
|
-
when Operator::AMONG_VALUES.to_s
|
57
|
-
is_targeted = @value.scan(/"([^"]*)"/).flatten.include?(custom_data.value)
|
58
|
-
else
|
59
|
-
raise KameleoonError.new("Undefined operator #{@operator}"), "Undefined operator #{@operator}"
|
60
|
-
end
|
52
|
+
elsif @operator != Operator::UNDEFINED.to_s
|
53
|
+
raise KameleoonError.new("Undefined operator #{@operator}"), "Undefined operator #{@operator}" if @op.nil?
|
54
|
+
|
55
|
+
is_targeted = @op.call(custom_data.values)
|
61
56
|
end
|
62
57
|
is_targeted
|
63
58
|
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def op_match(values)
|
63
|
+
re = Regexp.new(@value.to_s)
|
64
|
+
values.any? { |v| re.match(v) }
|
65
|
+
end
|
66
|
+
|
67
|
+
def op_contains(values)
|
68
|
+
values.any? { |v| v.to_s.include? @value.to_s }
|
69
|
+
end
|
70
|
+
|
71
|
+
def op_exact(values)
|
72
|
+
values.include? @value.to_s
|
73
|
+
end
|
74
|
+
|
75
|
+
def op_equal(values)
|
76
|
+
values.any? { |v| v.to_f == @value.to_f }
|
77
|
+
end
|
78
|
+
|
79
|
+
def op_greater(values)
|
80
|
+
values.any? { |v| v.to_f > @value.to_f }
|
81
|
+
end
|
82
|
+
|
83
|
+
def op_lower(values)
|
84
|
+
values.any? { |v| v.to_f < @value.to_f }
|
85
|
+
end
|
86
|
+
|
87
|
+
def op_is_true(values)
|
88
|
+
values.any? { |v| v.to_s == 'true' }
|
89
|
+
end
|
90
|
+
|
91
|
+
def op_is_false(values)
|
92
|
+
values.any? { |v| v.to_s == 'false' }
|
93
|
+
end
|
94
|
+
|
95
|
+
def op_among_values(values)
|
96
|
+
all_matches = JSON.parse(@value.to_s).map(&:to_s).to_set
|
97
|
+
values.any? { |v| all_matches.include?(v) }
|
98
|
+
end
|
64
99
|
end
|
65
100
|
end
|
66
101
|
end
|
@@ -12,7 +12,7 @@ module Kameleoon
|
|
12
12
|
|
13
13
|
def initialize(json_condition)
|
14
14
|
if json_condition['targetingType'].nil?
|
15
|
-
raise Exception::
|
15
|
+
raise Exception::NotFound.new('targetingType'), 'targetingType missed'
|
16
16
|
end
|
17
17
|
|
18
18
|
@type = json_condition['targetingType']
|
@@ -14,13 +14,13 @@ module Kameleoon
|
|
14
14
|
super(json_condition)
|
15
15
|
|
16
16
|
if json_condition['experiment'].nil?
|
17
|
-
raise Exception::
|
17
|
+
raise Exception::NotFound.new('experiment'), 'experiment missed'
|
18
18
|
end
|
19
19
|
|
20
20
|
@experiment = json_condition['experiment']
|
21
21
|
|
22
22
|
if json_condition['variationMatchType'].nil?
|
23
|
-
raise Exception::
|
23
|
+
raise Exception::NotFound.new('variationMatchType'), 'variationMatchType missed'
|
24
24
|
end
|
25
25
|
|
26
26
|
@operator = json_condition['variationMatchType']
|
data/lib/kameleoon/version.rb
CHANGED
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.
|
4
|
+
version: 2.1.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-
|
11
|
+
date: 2023-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: em-http-request
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rest-client
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.1'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.1'
|
55
69
|
description: Kameleoon Client Ruby Software Development Kit
|
56
70
|
email:
|
57
71
|
- sdk@kameleoon.com
|
@@ -64,8 +78,8 @@ files:
|
|
64
78
|
- lib/kameleoon/client.rb
|
65
79
|
- lib/kameleoon/configuration/experiment.rb
|
66
80
|
- lib/kameleoon/configuration/feature_flag.rb
|
67
|
-
- lib/kameleoon/configuration/feature_flag_v2.rb
|
68
81
|
- lib/kameleoon/configuration/rule.rb
|
82
|
+
- lib/kameleoon/configuration/settings.rb
|
69
83
|
- lib/kameleoon/configuration/variable.rb
|
70
84
|
- lib/kameleoon/configuration/variation.rb
|
71
85
|
- lib/kameleoon/configuration/variation_exposition.rb
|
@@ -73,7 +87,15 @@ files:
|
|
73
87
|
- lib/kameleoon/data.rb
|
74
88
|
- lib/kameleoon/exceptions.rb
|
75
89
|
- lib/kameleoon/factory.rb
|
90
|
+
- lib/kameleoon/hybrid/manager.rb
|
91
|
+
- lib/kameleoon/real_time/real_time_configuration_service.rb
|
92
|
+
- lib/kameleoon/real_time/real_time_event.rb
|
93
|
+
- lib/kameleoon/real_time/sse_client.rb
|
94
|
+
- lib/kameleoon/real_time/sse_message.rb
|
95
|
+
- lib/kameleoon/real_time/sse_request.rb
|
76
96
|
- lib/kameleoon/request.rb
|
97
|
+
- lib/kameleoon/storage/cache.rb
|
98
|
+
- lib/kameleoon/storage/cache_factory.rb
|
77
99
|
- lib/kameleoon/storage/variation_storage.rb
|
78
100
|
- lib/kameleoon/storage/visitor_variation.rb
|
79
101
|
- lib/kameleoon/targeting/condition.rb
|
@@ -1,30 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'rule'
|
4
|
-
require_relative 'variation'
|
5
|
-
|
6
|
-
module Kameleoon
|
7
|
-
# Module which contains all internal data of SDK
|
8
|
-
module Configuration
|
9
|
-
# Class for manage all feature flags v2 with rules
|
10
|
-
class FeatureFlagV2
|
11
|
-
attr_accessor :id, :feature_key, :variations, :default_variation_key, :rules
|
12
|
-
|
13
|
-
def self.create_from_array(array)
|
14
|
-
array&.map { |it| FeatureFlagV2.new(it) }
|
15
|
-
end
|
16
|
-
|
17
|
-
def initialize(hash)
|
18
|
-
@id = hash['id']
|
19
|
-
@feature_key = hash['featureKey']
|
20
|
-
@default_variation_key = hash['defaultVariationKey']
|
21
|
-
@variations = Variation.create_from_array(hash['variations'])
|
22
|
-
@rules = Rule.create_from_array(hash['rules'])
|
23
|
-
end
|
24
|
-
|
25
|
-
def get_variation_key(key)
|
26
|
-
variations.select { |v| v.key == key }.first
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|