vwo-sdk 1.30.0 → 1.37.1

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: a8bf50eeb65a850a9a49fb00628208670c6bd7a167c591d8d649573fa0a67bc7
4
- data.tar.gz: cfc520d123444c23f36683a1d89bef145e466ea21a9044543641226614e076df
3
+ metadata.gz: ea72e150de33227c3e911fd61478a8815fb8f42f788df4a65a6751a1da7c25fb
4
+ data.tar.gz: c88b275817a6ef0ca80efc03287e57fd1488be9390e7a028a4dc812cca93abc0
5
5
  SHA512:
6
- metadata.gz: 1e79a2e33a718e0379724b39d115f59e4ef0925f9dcc682f6c553166af90d444f7a74c5551a9474051fcee1213104a8b6fe8c9842a51da1be90f76020c38a3da
7
- data.tar.gz: 553e1b3553f5c3b49d3d1dae6fdd176706129d892439b04517d5e670f1945b91246c69ec0a2ceb95b14ad7334fb4b9b580cbbc26be1cbfd10495f77fae13673c
6
+ metadata.gz: 294fab2cbb559b6869e547dd0f55b9bb5ac54910ba61d497f9d205fd37c405bc206b6264912bc0600306dd0986d875c034be0e4342260f3d0aa8a647ad0a67e3
7
+ data.tar.gz: d25b2e2642a1e178eeeba2b0f7f7e82188040df6116a6a14bb13abfba7cf8e0b2ee28c5161936cc9773663f55cdca9d371b72deea94393ac1c9d6a20cf9f383b
data/lib/vwo/constants.rb CHANGED
@@ -19,7 +19,7 @@ class VWO
19
19
  SEED_VALUE = 1
20
20
  MAX_TRAFFIC_PERCENT = 100
21
21
  MAX_TRAFFIC_VALUE = 10_000
22
- MAX_RANGE = 10000
22
+ MAX_RANGE = 10_000
23
23
  STATUS_RUNNING = 'RUNNING'
24
24
  # rubocop:disable Style/ExpandPathArguments
25
25
  LIBRARY_PATH = File.expand_path('../..', __FILE__)
@@ -27,7 +27,7 @@ class VWO
27
27
  HTTP_PROTOCOL = 'http://'
28
28
  HTTPS_PROTOCOL = 'https://'
29
29
  URL_NAMESPACE = '6ba7b811-9dad-11d1-80b4-00c04fd430c8'
30
- SDK_VERSION = '1.30.0'
30
+ SDK_VERSION = '1.37.1'
31
31
  SDK_NAME = 'ruby'
32
32
  VWO_DELIMITER = '_vwo_'
33
33
  MAX_EVENTS_PER_REQUEST = 5000
@@ -94,6 +94,7 @@ class VWO
94
94
  }
95
95
 
96
96
  module ApiMethods
97
+ LAUNCH = 'launch'
97
98
  ACTIVATE = 'activate'
98
99
  GET_VARIATION_NAME = 'get_variation_name'
99
100
  TRACK = 'track'
@@ -13,9 +13,9 @@
13
13
  # limitations under the License.
14
14
 
15
15
  require 'murmurhash3'
16
- require_relative '../logger'
17
16
  require_relative '../enums'
18
17
  require_relative '../utils/validations'
18
+ require_relative '../utils/log_message'
19
19
  require_relative '../constants'
20
20
 
21
21
  class VWO
@@ -31,40 +31,46 @@ class VWO
31
31
  # Source - https://stackoverflow.com/a/20766900/2494535
32
32
  U_MAX_32_BIT = 0xFFFFFFFF
33
33
  MAX_HASH_VALUE = 2**32
34
- FILE = FileNameEnum::Bucketer
34
+ FILE = FileNameEnum::BUCKETER
35
35
 
36
36
  def initialize
37
- @logger = VWO::Logger.get_instance
37
+ @logger = VWO::Utils::Logger
38
38
  end
39
39
 
40
40
  # Calculate if this user should become part of the campaign or not
41
41
  # @param[String] :user_id The unique ID assigned to a user
42
42
  # @param[Dict] :campaign For getting traffic allotted to the campaign
43
+ # @param[Boolean] :disable_logs if true, do not log log-message
43
44
  # @return[Boolean] If User is a part of Campaign or not
44
45
 
45
- def user_part_of_campaign?(user_id, campaign)
46
+ def user_part_of_campaign?(user_id, campaign, disable_logs = false)
46
47
  unless valid_value?(user_id)
47
48
  @logger.log(
48
49
  LogLevelEnum::ERROR,
49
- format(LogMessageEnum::ErrorMessages::INVALID_USER_ID, file: FILE, user_id: user_id, method: 'is_user_part_of_campaign')
50
+ 'USER_ID_INVALID',
51
+ {
52
+ '{file}' => FILE,
53
+ '{userId}' => user_id
54
+ }
50
55
  )
51
56
  return false
52
57
  end
53
58
 
54
- if campaign.nil?
55
- @logger.log(
56
- LogLevelEnum::ERROR,
57
- format(LogMessageEnum::ErrorMessages::INVALID_CAMPAIGN, file: FILE, method: 'is_user_part_of_campaign')
58
- )
59
- return false
60
- end
59
+ return false if campaign.nil?
61
60
 
62
61
  traffic_allocation = campaign['percentTraffic']
63
- value_assigned_to_user = get_bucket_value_for_user(user_id, campaign)
62
+ value_assigned_to_user = get_bucket_value_for_user(user_id, campaign, nil, disable_logs)
64
63
  is_user_part = (value_assigned_to_user != 0) && value_assigned_to_user <= traffic_allocation
65
64
  @logger.log(
66
65
  LogLevelEnum::INFO,
67
- format(LogMessageEnum::InfoMessages::USER_ELIGIBILITY_FOR_CAMPAIGN, file: FILE, user_id: user_id, is_user_part: is_user_part)
66
+ 'USER_CAMPAIGN_ELIGIBILITY',
67
+ {
68
+ '{file}' => FILE,
69
+ '{userId}' => user_id,
70
+ '{status}' => is_user_part ? 'eligible' : 'not eligible',
71
+ '{campaignKey}' => campaign['key']
72
+ },
73
+ disable_logs
68
74
  )
69
75
  is_user_part
70
76
  end
@@ -74,30 +80,27 @@ class VWO
74
80
  #
75
81
  # @param[String] :user_id The unique ID assigned to User
76
82
  # @param[Hash] :campaign The Campaign of which User is a part of
83
+ # @param[Boolean] :disable_logs if true, do not log log-message
77
84
  #
78
85
  # @return[Hash|nil} Variation data into which user is bucketed to
79
86
  # or nil if not
80
- def bucket_user_to_variation(user_id, campaign)
87
+ def bucket_user_to_variation(user_id, campaign, disable_logs = false)
81
88
  unless valid_value?(user_id)
82
89
  @logger.log(
83
90
  LogLevelEnum::ERROR,
84
- format(LogMessageEnum::ErrorMessages::INVALID_USER_ID, file: FILE, user_id: user_id, method: 'bucket_user_to_variation')
91
+ 'USER_ID_INVALID',
92
+ {
93
+ '{file}' => FILE,
94
+ '{userId}' => user_id
95
+ }
85
96
  )
86
97
  return
87
98
  end
88
99
 
89
- unless campaign
90
- @logger.log(
91
- LogLevelEnum::ERROR,
92
- format(LogMessageEnum::ErrorMessages::INVALID_CAMPAIGN, file: FILE, method: 'is_user_part_of_campaign')
93
- )
94
- return
95
- end
100
+ return unless campaign
96
101
 
97
102
  user_id_for_hash_value = user_id
98
- if campaign['isBucketingSeedEnabled']
99
- user_id_for_hash_value = campaign['id'].to_s + "_" + user_id
100
- end
103
+ user_id_for_hash_value = "#{campaign['id']}_#{user_id}" if campaign['isBucketingSeedEnabled']
101
104
  hash_value = MurmurHash3::V32.str_hash(user_id_for_hash_value, SEED_VALUE) & U_MAX_32_BIT
102
105
  normalize = MAX_TRAFFIC_VALUE.to_f / campaign['percentTraffic']
103
106
  multiplier = normalize / 100
@@ -109,15 +112,16 @@ class VWO
109
112
 
110
113
  @logger.log(
111
114
  LogLevelEnum::DEBUG,
112
- format(
113
- LogMessageEnum::DebugMessages::VARIATION_HASH_BUCKET_VALUE,
114
- file: FILE,
115
- user_id: user_id,
116
- campaign_key: campaign['key'],
117
- percent_traffic: campaign['percentTraffic'],
118
- bucket_value: bucket_value,
119
- hash_value: hash_value
120
- )
115
+ 'USER_CAMPAIGN_BUCKET_VALUES',
116
+ {
117
+ '{file}' => FILE,
118
+ '{campaignKey}' => campaign['key'],
119
+ '{userId}' => user_id,
120
+ '{percentTraffic}' => campaign['percentTraffic'],
121
+ '{hashValue}' => hash_value,
122
+ '{bucketValue}' => bucket_value
123
+ },
124
+ disable_logs
121
125
  )
122
126
 
123
127
  get_variation(campaign['variations'], bucket_value)
@@ -146,22 +150,22 @@ class VWO
146
150
  def get_bucket_value_for_user(user_id, campaign = {}, group_id = nil, disable_logs = false)
147
151
  user_id_for_hash_value = user_id
148
152
  if group_id
149
- user_id_for_hash_value = group_id.to_s + "_" + user_id
153
+ user_id_for_hash_value = "#{group_id}_#{user_id}"
150
154
  elsif campaign['isBucketingSeedEnabled']
151
- user_id_for_hash_value = campaign['id'].to_s + "_" + user_id
155
+ user_id_for_hash_value = "#{campaign['id']}_#{user_id}"
152
156
  end
153
157
  hash_value = MurmurHash3::V32.str_hash(user_id_for_hash_value, SEED_VALUE) & U_MAX_32_BIT
154
158
  bucket_value = get_bucket_value(hash_value, MAX_TRAFFIC_PERCENT)
155
159
 
156
160
  @logger.log(
157
161
  LogLevelEnum::DEBUG,
158
- format(
159
- LogMessageEnum::DebugMessages::USER_HASH_BUCKET_VALUE,
160
- file: FILE,
161
- hash_value: hash_value,
162
- bucket_value: bucket_value,
163
- user_id: user_id
164
- ),
162
+ 'USER_HASH_BUCKET_VALUE',
163
+ {
164
+ '{file}' => FILE,
165
+ '{hashValue}' => hash_value,
166
+ '{userId}' => user_id,
167
+ '{bucketValue}' => bucket_value
168
+ },
165
169
  disable_logs
166
170
  )
167
171
  bucket_value
@@ -188,11 +192,9 @@ class VWO
188
192
  # @return[Hash|nil]
189
193
  #
190
194
  def get_campaign_using_range(range_for_campaigns, campaigns)
191
- range_for_campaigns = range_for_campaigns * 100
195
+ range_for_campaigns *= 100
192
196
  campaigns.each do |campaign|
193
- if campaign["max_range"] && campaign["max_range"] >= range_for_campaigns && campaign["min_range"] <= range_for_campaigns
194
- return campaign
195
- end
197
+ return campaign if campaign['max_range'] && campaign['max_range'] >= range_for_campaigns && campaign['min_range'] <= range_for_campaigns
196
198
  end
197
199
  nil
198
200
  end