vwo-sdk 1.29.1 → 1.36.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: 91b2904a81712b0093c6406bbcc0a2db8669ad01e2c49489a7dbb54177319c9d
4
- data.tar.gz: 2e224423aad754c5b8c9ddf6952e768f2b3e34bc2ec7840ada65b0ea2c40421d
3
+ metadata.gz: 43fec6e51e5bb0377e3714ca0fa90bc1cd11c26c29c99af86e0b8fec858af4b1
4
+ data.tar.gz: 6b63f796cc23e812e65a731cfeefddfcee46c1bb1d24ece33b9bdecbc619bc62
5
5
  SHA512:
6
- metadata.gz: 80142e1852c8f81384df2df3125bd3eb1cbd53fa8851f984c58407535cf4409b0e121cdd7c0d86c05f2772295c43f955bca9145a831a3bde9c90f8f02c071cf7
7
- data.tar.gz: e0509cea3280a6efd33fb75cff9cf1ec2fa1491b7ca9da590101d05239e9f33b419c89de7444db2a7e7dd04af9d64de49c1c3772956aa954393310ae71450d99
6
+ metadata.gz: 0357c8d8c220348265463a1adaabd0480c9424cf8082d05541643c6ccdbdfbf2692e603a08acfd1b71d4762d31649ba1e5fd5469707f1e01251d96329509a6e2
7
+ data.tar.gz: e30bd9f514a53da482f5e7d38dda6a3ced309fa027afe4d9148cfb464fff6acf3da0e012574dbf38712390ab24daa0148a42ce76f83fb8d264ecfb88c8bfb84a
data/lib/vwo/constants.rb CHANGED
@@ -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.29.1'
30
+ SDK_VERSION = '1.36.0'
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
@@ -34,37 +34,45 @@ class VWO
34
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
59
  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
60
  return false
60
61
  end
61
62
 
62
63
  traffic_allocation = campaign['percentTraffic']
63
- value_assigned_to_user = get_bucket_value_for_user(user_id, campaign)
64
+ value_assigned_to_user = get_bucket_value_for_user(user_id, campaign, nil, disable_logs)
64
65
  is_user_part = (value_assigned_to_user != 0) && value_assigned_to_user <= traffic_allocation
65
66
  @logger.log(
66
67
  LogLevelEnum::INFO,
67
- format(LogMessageEnum::InfoMessages::USER_ELIGIBILITY_FOR_CAMPAIGN, file: FILE, user_id: user_id, is_user_part: is_user_part)
68
+ 'USER_CAMPAIGN_ELIGIBILITY',
69
+ {
70
+ '{file}' => FILE,
71
+ '{userId}' => user_id,
72
+ '{status}' => is_user_part ? 'eligible' : 'not eligible',
73
+ '{campaignKey}' => campaign['key']
74
+ },
75
+ disable_logs
68
76
  )
69
77
  is_user_part
70
78
  end
@@ -74,29 +82,30 @@ class VWO
74
82
  #
75
83
  # @param[String] :user_id The unique ID assigned to User
76
84
  # @param[Hash] :campaign The Campaign of which User is a part of
85
+ # @param[Boolean] :disable_logs if true, do not log log-message
77
86
  #
78
87
  # @return[Hash|nil} Variation data into which user is bucketed to
79
88
  # or nil if not
80
- def bucket_user_to_variation(user_id, campaign)
89
+ def bucket_user_to_variation(user_id, campaign, disable_logs = false)
81
90
  unless valid_value?(user_id)
82
91
  @logger.log(
83
92
  LogLevelEnum::ERROR,
84
- format(LogMessageEnum::ErrorMessages::INVALID_USER_ID, file: FILE, user_id: user_id, method: 'bucket_user_to_variation')
93
+ 'USER_ID_INVALID',
94
+ {
95
+ '{file}' => FILE,
96
+ '{userId}' => user_id
97
+ }
85
98
  )
86
99
  return
87
100
  end
88
101
 
89
102
  unless campaign
90
- @logger.log(
91
- LogLevelEnum::ERROR,
92
- format(LogMessageEnum::ErrorMessages::INVALID_CAMPAIGN, file: FILE, method: 'is_user_part_of_campaign')
93
- )
94
103
  return
95
104
  end
96
105
 
97
106
  user_id_for_hash_value = user_id
98
- if campaign[:isBucketingSeedEnabled]
99
- user_id_for_hash_value = campaign[:id].to_s + "_" + user_id
107
+ if campaign['isBucketingSeedEnabled']
108
+ user_id_for_hash_value = campaign['id'].to_s + "_" + user_id
100
109
  end
101
110
  hash_value = MurmurHash3::V32.str_hash(user_id_for_hash_value, SEED_VALUE) & U_MAX_32_BIT
102
111
  normalize = MAX_TRAFFIC_VALUE.to_f / campaign['percentTraffic']
@@ -109,15 +118,16 @@ class VWO
109
118
 
110
119
  @logger.log(
111
120
  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
- )
121
+ 'USER_CAMPAIGN_BUCKET_VALUES',
122
+ {
123
+ '{file}' => FILE,
124
+ '{campaignKey}' => campaign['key'],
125
+ '{userId}' => user_id,
126
+ '{percentTraffic}' => campaign['percentTraffic'],
127
+ '{hashValue}' => hash_value,
128
+ '{bucketValue}' => bucket_value,
129
+ },
130
+ disable_logs
121
131
  )
122
132
 
123
133
  get_variation(campaign['variations'], bucket_value)
@@ -147,21 +157,21 @@ class VWO
147
157
  user_id_for_hash_value = user_id
148
158
  if group_id
149
159
  user_id_for_hash_value = group_id.to_s + "_" + user_id
150
- elsif campaign[:isBucketingSeedEnabled]
151
- user_id_for_hash_value = campaign[:id].to_s + "_" + user_id
160
+ elsif campaign['isBucketingSeedEnabled']
161
+ user_id_for_hash_value = campaign['id'].to_s + "_" + user_id
152
162
  end
153
163
  hash_value = MurmurHash3::V32.str_hash(user_id_for_hash_value, SEED_VALUE) & U_MAX_32_BIT
154
164
  bucket_value = get_bucket_value(hash_value, MAX_TRAFFIC_PERCENT)
155
165
 
156
166
  @logger.log(
157
167
  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
- ),
168
+ 'USER_HASH_BUCKET_VALUE',
169
+ {
170
+ '{file}' => FILE,
171
+ '{hashValue}' => hash_value,
172
+ '{userId}' => user_id,
173
+ '{bucketValue}' => bucket_value
174
+ },
165
175
  disable_logs
166
176
  )
167
177
  bucket_value