kameleoon-client-ruby 1.0.4 → 1.0.5

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: 4b09a20582d3f5baec0e552fe725f308fc5731817a4dc2910f750d929f977f86
4
- data.tar.gz: b01b8e3b105369853763de7b6a470296604dbb6f5172c72b28eac3a78038dd88
3
+ metadata.gz: e0deee13cb73acd60d605f479ab0e2ebf374e38e7516d9bea0590b0adbdd7f53
4
+ data.tar.gz: 7c06c8d843f6f291d946375d495a3d573e31f932942c5b6edb2f86abf4d9183f
5
5
  SHA512:
6
- metadata.gz: 117d9b2a6b2079b20c544ed7c26238ffb5fe0b5a045402be2139415572a1afc82d771f00471d9898fb2331c4d3353dcf8dbb17160235fd0a16a65e20c95890b7
7
- data.tar.gz: 8a2467851b689b61c9bfec87c8de9a5a4a383930a1dcdb117403e0566343f127ba3890c5aaffba7a62970c0b3350f765c652950005c92af25073cf8c2426709f
6
+ metadata.gz: 8d14ce02c0a2577988a0161292683e9a455c9532dda0fd69e5428d0f0a2bd08bb38114cf8b161d4a123921e08429cf1db126f7b3033d43a0889c4f6eea2d064b
7
+ data.tar.gz: de09c74c6587cbd9f53f44a6673b1d3e2832d3aa135376405d0e7eaef9933bc0891243cc34cb039d2eb72b8b8fa5eeb5045b9e4c69b4a4979aabcae154e8361b
@@ -121,11 +121,11 @@ module Kameleoon
121
121
  experiment['deviations'].each do |key, value|
122
122
  threshold -= value
123
123
  if threshold < 0
124
- post_beacon("experimentTracking", visitor_code, experiment_id, key)
124
+ track_experiment(visitor_code, experiment_id, key)
125
125
  return key.to_s.to_i
126
126
  end
127
127
  end
128
- post_beacon("experimentTracking", visitor_code, experiment_id, REFERENCE, true)
128
+ track_experiment(visitor_code, experiment_id, REFERENCE, true)
129
129
  raise Exception::NotActivated.new(visitor_code)
130
130
  end
131
131
  raise Exception::NotTargeted.new(visitor_code)
@@ -182,7 +182,7 @@ module Kameleoon
182
182
  # @param [String] visitor_code Optional field - Visitor code, without visitor code it flush all of the data
183
183
  #
184
184
  def flush(visitor_code = nil)
185
- post_beacon("dataTracking", visitor_code)
185
+ track_data(visitor_code)
186
186
  end
187
187
 
188
188
  ##
@@ -231,7 +231,7 @@ module Kameleoon
231
231
  connexion_options = { :connect_timeout => (timeout.to_f / 1000.0) }
232
232
  request_options = {
233
233
  :path => get_experiment_register_url(visitor_code, id),
234
- :body => (select_data_to_sent(visitor_code).values.map { |data| data.obtain_full_post_text_line }.join("\n") || "").encode("UTF-8")
234
+ :body => (data_not_sent(visitor_code).values.map { |data| data.obtain_full_post_text_line }.join("\n") || "").encode("UTF-8")
235
235
  }
236
236
  log "Activate feature request: " + request_options.inspect
237
237
  log "Activate feature connexion:" + connexion_options.inspect
@@ -251,10 +251,10 @@ module Kameleoon
251
251
  if feature_flag['targetingSegment'].nil? || feature_flag['targetingSegment'].check_tree(visitor_data)
252
252
  threshold = obtain_hash_double(visitor_code, {}, id)
253
253
  if threshold <= feature_flag['expositionRate']
254
- post_beacon("experimentTracking", visitor_code, id, feature_flag["variationsId"].first)
254
+ track_experiment(visitor_code, id, feature_flag["variationsId"].first)
255
255
  return true
256
256
  else
257
- post_beacon("experimentTracking", visitor_code, id, REFERENCE, true)
257
+ track_experiment(visitor_code, id, REFERENCE, true)
258
258
  return false
259
259
  end
260
260
  else
@@ -472,6 +472,10 @@ module Kameleoon
472
472
  url
473
473
  end
474
474
 
475
+ def get_data_register_url(visitor_code)
476
+ "/dataTracking?" + URI.encode_www_form(get_common_ssx_parameters(visitor_code))
477
+ end
478
+
475
479
  def get_feature_flag(feature_key)
476
480
  if feature_key.is_a?(String)
477
481
  feature_flag = @feature_flags.select { |ff| ff['identificationKey'] == feature_key}.first
@@ -486,21 +490,48 @@ module Kameleoon
486
490
  feature_flag
487
491
  end
488
492
 
489
- def post_beacon(type = "dataTracking", visitor_code = nil, experiment_id = nil, variation_id = nil, none_variation = false)
493
+ def track_experiment(visitor_code, experiment_id, variation_id = nil, none_variation = false)
494
+ data_not_sent = data_not_sent(visitor_code)
495
+ options = {
496
+ :path => get_experiment_register_url(visitor_code, experiment_id, variation_id, none_variation),
497
+ :body => ((data_not_sent.values[0] || []).map{ |it| it.obtain_full_post_text_line }.join("\n") || "").encode("UTF-8"),
498
+ :head => { "Content-Type" => "text/plain"}
499
+ }
500
+ trial = 0
501
+ log "Start post tracking experiment: " + data_not_sent.inspect
502
+ Thread.new do
503
+ EM.synchrony do
504
+ while trial < 10
505
+ request = EM::Synchrony.sync post(options, @tracking_url)
506
+ log "Request " + request.inspect
507
+ if is_successful(request)
508
+ (data_not_sent.values[0] || []).each { |it| it.sent = true }
509
+ EM.stop
510
+ end
511
+ trial += 1
512
+ end
513
+ EM.stop
514
+ end
515
+ log "Post to experiment tracking is done after " + trial.to_s + " trials"
516
+ Thread.exit
517
+ end
518
+ end
519
+
520
+ def track_data(visitor_code = nil)
490
521
  Thread.new do
491
522
  EM.synchrony do
492
- entries = select_data_to_sent(visitor_code)
493
- log "Start post to tracking: " + entries.inspect
494
523
  trials = 10
495
524
  concurrency = 1
496
- while !entries.empty? && trials > 0
497
- log "Trials amount left: " + trials.to_s
498
- EM::Synchrony::Iterator.new(entries, concurrency).map do |entry, iter|
525
+ data_not_sent = data_not_sent(visitor_code)
526
+ log "Start post tracking data: " + data_not_sent.inspect
527
+ while trials > 0 && !data_not_sent.empty?
528
+ EM::Synchrony::Iterator.new(data_not_sent, concurrency).map do |entry, iter|
499
529
  options = {
500
- :path => build_beacon_path(type, entry.first || visitor_code, experiment_id, variation_id, none_variation),
530
+ :path => get_data_register_url(entry.first),
501
531
  :body => (entry.last.map { |data| data.obtain_full_post_text_line }.join("\n") || "").encode("UTF-8"),
502
532
  :head => { "Content-Type" => "text/plain" }
503
533
  }
534
+ log "Post tracking data for visitor_code: " + entry.first + " with options: " + options.inspect
504
535
  request = post(options, @tracking_url)
505
536
  request.callback {
506
537
  if is_successful(request)
@@ -510,17 +541,17 @@ module Kameleoon
510
541
  }
511
542
  request.errback { iter.return(request) }
512
543
  end
513
- entries = select_data_to_sent(visitor_code)
544
+ data_not_sent = data_not_sent(visitor_code)
514
545
  trials -= 1
515
546
  end
516
- log "Post to tracking done"
547
+ log "Post to data tracking is done."
517
548
  EM.stop
518
549
  end
519
550
  Thread.exit
520
551
  end
521
552
  end
522
553
 
523
- def select_data_to_sent(visitor_code)
554
+ def data_not_sent(visitor_code = nil)
524
555
  if visitor_code.nil?
525
556
  @data.select {|key, values| values.any? {|data| !data.sent}}
526
557
  else
@@ -528,16 +559,6 @@ module Kameleoon
528
559
  end
529
560
  end
530
561
 
531
- def build_beacon_path(type, visitor_code, experiment_id = nil, variation_id = nil, none_variation = nil)
532
- if type == "dataTracking"
533
- return "/dataTracking?" + URI.encode_www_form(get_common_ssx_parameters(visitor_code))
534
- elsif type == "experimentTracking"
535
- return get_experiment_register_url(visitor_code, experiment_id, variation_id, none_variation)
536
- else
537
- raise TypeError("Unknown type for post_beacon: " + type.to_s)
538
- end
539
- end
540
-
541
562
  def log(text)
542
563
  if @verbose_mode
543
564
  print "Kameleoon Log: " + text.to_s + "\n"
@@ -42,9 +42,9 @@ module Kameleoon
42
42
 
43
43
  def add_user_agent(request_options)
44
44
  if request_options[:head].nil?
45
- request_options[:head] = {'User-Agent' => 'kameleoon-client-ruby/' + Kameleoon::VERSION}
45
+ request_options[:head] = {'Kameleoon-Client' => 'sdk/ruby/' + Kameleoon::VERSION}
46
46
  else
47
- request_options[:head].store('User-Agent', 'kameleoon-client-ruby/' + Kameleoon::VERSION)
47
+ request_options[:head].store('Kameleoon-Client', 'sdk/ruby/' + Kameleoon::VERSION)
48
48
  end
49
49
  end
50
50
  end
@@ -1,3 +1,3 @@
1
1
  module Kameleoon
2
- VERSION = '1.0.4'
2
+ VERSION = '1.0.5'
3
3
  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: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kameleoon - Guillaume Grandjean
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-13 00:00:00.000000000 Z
11
+ date: 2021-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: em-http-request