kameleoon-client-ruby 2.0.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/lib/kameleoon/client.rb +277 -260
  3. data/lib/kameleoon/configuration/feature_flag.rb +13 -24
  4. data/lib/kameleoon/configuration/rule.rb +17 -5
  5. data/lib/kameleoon/configuration/settings.rb +20 -0
  6. data/lib/kameleoon/cookie.rb +3 -3
  7. data/lib/kameleoon/data/browser.rb +33 -0
  8. data/lib/kameleoon/data/conversion.rb +26 -0
  9. data/lib/kameleoon/data/custom_data.rb +53 -0
  10. data/lib/kameleoon/data/data.rb +35 -0
  11. data/lib/kameleoon/data/device.rb +26 -0
  12. data/lib/kameleoon/data/page_view.rb +31 -0
  13. data/lib/kameleoon/data/user_agent.rb +14 -0
  14. data/lib/kameleoon/hybrid/manager.rb +60 -0
  15. data/lib/kameleoon/network/activity_event.rb +31 -0
  16. data/lib/kameleoon/network/experiment_event.rb +35 -0
  17. data/lib/kameleoon/network/uri_helper.rb +36 -0
  18. data/lib/kameleoon/network/url_provider.rb +71 -0
  19. data/lib/kameleoon/real_time/real_time_configuration_service.rb +98 -0
  20. data/lib/kameleoon/real_time/real_time_event.rb +22 -0
  21. data/lib/kameleoon/real_time/sse_client.rb +111 -0
  22. data/lib/kameleoon/real_time/sse_message.rb +23 -0
  23. data/lib/kameleoon/real_time/sse_request.rb +59 -0
  24. data/lib/kameleoon/request.rb +5 -19
  25. data/lib/kameleoon/storage/cache.rb +84 -0
  26. data/lib/kameleoon/storage/cache_factory.rb +23 -0
  27. data/lib/kameleoon/targeting/condition.rb +41 -12
  28. data/lib/kameleoon/targeting/condition_factory.rb +35 -12
  29. data/lib/kameleoon/targeting/conditions/browser_condition.rb +71 -0
  30. data/lib/kameleoon/targeting/conditions/conversion_condition.rb +21 -0
  31. data/lib/kameleoon/targeting/conditions/custom_datum.rb +64 -34
  32. data/lib/kameleoon/targeting/conditions/device_condition.rb +21 -0
  33. data/lib/kameleoon/targeting/conditions/exclusive_experiment.rb +0 -12
  34. data/lib/kameleoon/targeting/conditions/page_title_condition.rb +21 -0
  35. data/lib/kameleoon/targeting/conditions/page_url_condition.rb +21 -0
  36. data/lib/kameleoon/targeting/conditions/sdk_language_condition.rb +65 -0
  37. data/lib/kameleoon/targeting/conditions/string_value_condition.rb +40 -0
  38. data/lib/kameleoon/targeting/conditions/target_experiment.rb +5 -9
  39. data/lib/kameleoon/targeting/conditions/unknown_condition.rb +15 -0
  40. data/lib/kameleoon/targeting/conditions/visitor_code_condition.rb +16 -0
  41. data/lib/kameleoon/targeting/models.rb +0 -24
  42. data/lib/kameleoon/utils.rb +1 -1
  43. data/lib/kameleoon/version.rb +28 -1
  44. metadata +45 -4
  45. data/lib/kameleoon/configuration/feature_flag_v2.rb +0 -30
  46. data/lib/kameleoon/data.rb +0 -169
@@ -1,169 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Kameleoon
4
- NONCE_LENGTH = 16
5
-
6
- module DataType
7
- CUSTOM = 'CUSTOM'
8
- BROWSER = 'BROWSER'
9
- CONVERSION = 'CONVERSION'
10
- DEVICE = 'DEVICE'
11
- PAGE_VIEW = 'PAGE_VIEW'
12
- end
13
-
14
- module BrowserType
15
- CHROME = 0
16
- INTERNET_EXPLORER = 1
17
- FIREFOX = 2
18
- SAFARI = 3
19
- OPERA = 4
20
- OTHER = 5
21
- end
22
-
23
- module DeviceType
24
- PHONE = 'PHONE'
25
- TABLET = 'TABLET'
26
- DESKTOP = 'DESKTOP'
27
- end
28
-
29
- class Data
30
- attr_accessor :instance, :sent
31
-
32
- def initialize(*args)
33
- raise KameleoonError.new("Cannot initialise interface.")
34
- end
35
-
36
- def obtain_full_post_text_line
37
- raise KameleoonError.new("ToDo: implement this method.")
38
- end
39
-
40
- def encode(url)
41
- encoded_url = CGI.escape(url)
42
- encoded_url.gsub! "%27", "'"
43
- encoded_url.gsub! "%21", "!"
44
- encoded_url.gsub! "+", "%20"
45
- encoded_url.gsub! "%2A", "*"
46
- encoded_url.gsub! "%28", "("
47
- encoded_url.gsub! "%29", ")"
48
- encoded_url
49
- end
50
- end
51
-
52
- class CustomData < Data
53
- attr_accessor :id, :value
54
-
55
- # @param [Integer] id Id of the custom data
56
- # @param [String] value Value of the custom data
57
- #
58
- # @overload
59
- # @param [Hash] hash Json value encoded in a hash.
60
- def initialize(*args)
61
- @instance = DataType::CUSTOM
62
- @sent = false
63
- unless args.empty?
64
- if args.length == 1
65
- hash = args.first
66
- if hash["id"].nil?
67
- raise NotFoundError.new("id")
68
- end
69
- @id = hash["id"].to_s
70
- if hash["value"].nil?
71
- raise NotFoundError.new(hash["value"])
72
- end
73
- @value = hash["value"]
74
- elsif args.length == 2
75
- @id = args[0].to_s
76
- @value = args[1]
77
- end
78
- end
79
- end
80
-
81
- def obtain_full_post_text_line
82
- to_encode = "[[\"" + @value.to_s.gsub("\"", "\\\"") + "\",1]]"
83
- nonce = Kameleoon::Utils.generate_random_string(NONCE_LENGTH)
84
- "eventType=customData&index=" + @id.to_s + "&valueToCount=" + encode(to_encode) + "&overwrite=true&nonce=" + nonce
85
- end
86
- end
87
-
88
- class Browser < Data
89
- attr_accessor :browser
90
-
91
- # @param [BrowserType] browser_type Browser type, can be: CHROME, INTERNET_EXPLORER, FIREFOX, SAFARI, OPERA, OTHER
92
- def initialize(browser_type)
93
- @instance = DataType::BROWSER
94
- @sent = false
95
- @browser = browser_type
96
- end
97
-
98
- def obtain_full_post_text_line
99
- nonce = Kameleoon::Utils.generate_random_string(NONCE_LENGTH)
100
- "eventType=staticData&browserIndex=" + @browser.to_s + "&nonce=" + nonce
101
- end
102
- end
103
-
104
- class PageView < Data
105
- attr_accessor :url, :title, :referrer
106
-
107
- # @param [String] url Url of the page
108
- # @param [String] title Title of the page
109
- # @param [Array] referrers Optional field - Referrer ids
110
- def initialize(url, title, referrers = nil)
111
- @instance = DataType::PAGE_VIEW
112
- @sent = false
113
- @url = url
114
- @title = title
115
- @referrers = referrers
116
- end
117
-
118
- def obtain_full_post_text_line
119
- nonce = Kameleoon::Utils.generate_random_string(NONCE_LENGTH)
120
- referrer_text = ''
121
- unless @referrers.nil?
122
- referrer_text = "&referrersIndices=" + @referrers.to_s
123
- end
124
- "eventType=page&href=" + encode(@url) + "&title=" + @title + referrer_text + "&nonce=" + nonce
125
- end
126
- end
127
-
128
- class Conversion < Data
129
- attr_accessor :goal_id, :revenue, :negative
130
-
131
- # @param [Integer] goal_id Id of the goal associated to the conversion
132
- # @param [Float] revenue Optional field - Revenue associated to the conversion.
133
- # @param [Boolean] negative Optional field - If the revenue is negative. By default it's positive.
134
- def initialize(goal_id, revenue = 0.0, negative = false)
135
- @instance = DataType::CONVERSION
136
- @sent = false
137
- @goal_id = goal_id
138
- @revenue = revenue
139
- @negative = negative
140
- end
141
-
142
- def obtain_full_post_text_line
143
- nonce = Kameleoon::Utils.generate_random_string(NONCE_LENGTH)
144
- "eventType=conversion&goalId=" + @goal_id.to_s + "&revenue=" + @revenue.to_s + "&negative=" + @negative.to_s + "&nonce=" + nonce
145
- end
146
- end
147
-
148
- # Device uses for sending deviceType parameter for tracking calls
149
- class Device < Data
150
- def initialize(device_type)
151
- @instance = DataType::DEVICE
152
- @sent = false
153
- @device_type = device_type
154
- end
155
-
156
- def obtain_full_post_text_line
157
- nonce = Kameleoon::Utils.generate_random_string(NONCE_LENGTH)
158
- "eventType=staticData&deviceType=#{@device_type}&nonce=#{nonce}"
159
- end
160
- end
161
-
162
- # UserAgent uses for changing User-Agent header for tracking calls
163
- class UserAgent
164
- attr_accessor :value
165
- def initialize(value)
166
- @value = value
167
- end
168
- end
169
- end