kameleoon-client-ruby 1.1.1 → 1.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3e62c8e4dfa35f91706257ff5367a266736af7c03786803ad8f9fff06aa8c194
4
- data.tar.gz: 7773e082be938108b42c65cd0109392413bf938619cf04cc994617111c746f15
3
+ metadata.gz: a985a05999f2b8caeba131919f70ae77a1e6df7d125b82bf040a1056b300c1e5
4
+ data.tar.gz: d603f64d8801a3945236de7891ccde5c9a2c6747f18cb704954591a43abc5a99
5
5
  SHA512:
6
- metadata.gz: d74b03762402a1f4c6e7349bb085e3b185ee564f0a7f645a16f7bb8da0321b73689adad785d52bdce48e9a0646f6b10de6c3f2fc8016b9459b713eafbda77e6f
7
- data.tar.gz: a835f8b23265a2ae8241114fb2c5fe1f8965544fb348c2f6c16d714fe543fa6396b5bc6cbf7f68d8ac5e5391b8cbf594f55086e8c24290fda57a7b18ac5f57c4
6
+ metadata.gz: 89a04fd8440e3d2f3c17a6878df42088f6258979d1ec384ea8e2eaf7a3bd60c8e99624bb424bf925f86177ea9d58a98df2ddbf5adcc60871833140df600fc3d1
7
+ data.tar.gz: a61ec90742b861ce596e8526d32bef2186f722e0d2524250c470fcb5bc8de3a90711c391edbf9e8f64d4bad6b5fccb00cc3f8dd4d874cfd6f45268775defecf8
@@ -104,8 +104,7 @@ module Kameleoon
104
104
  variation_id = nil
105
105
  EM.synchrony do
106
106
  connexion_options = { :connect_timeout => (timeout.to_f / 1000.0) }
107
- body = @data.values.flatten.select { |data| !data.sent }.map { |data| data.obtain_full_post_text_line }
108
- .join("\n") || ""
107
+ body = (data_not_sent(visitor_code).map { |data| data.obtain_full_post_text_line }.join("\n") || "").encode("UTF-8")
109
108
  path = get_experiment_register_url(visitor_code, experiment_id)
110
109
  request_options = { :path => path, :body => body }
111
110
  log "Trigger experiment request: " + request_options.inspect
@@ -203,7 +202,11 @@ module Kameleoon
203
202
  #
204
203
  def flush(visitor_code = nil)
205
204
  check_visitor_code(visitor_code) unless visitor_code.nil?
206
- track_data(visitor_code)
205
+ if !visitor_code.nil?
206
+ track_data(visitor_code)
207
+ else
208
+ @data.select { |_, values| values.any? { |data| !data.sent } }.each_key { |key| flush(key) }
209
+ end
207
210
  end
208
211
 
209
212
  ##
@@ -254,7 +257,7 @@ module Kameleoon
254
257
  connexion_options = { :connect_timeout => (timeout.to_f / 1000.0) }
255
258
  request_options = {
256
259
  :path => get_experiment_register_url(visitor_code, id),
257
- :body => (data_not_sent(visitor_code).values.map { |data| data.obtain_full_post_text_line }.join("\n") || "").encode("UTF-8")
260
+ :body => (data_not_sent(visitor_code).map { |data| data.obtain_full_post_text_line }.join("\n") || "").encode("UTF-8")
258
261
  }
259
262
  log "Activate feature request: " + request_options.inspect
260
263
  log "Activate feature connexion:" + connexion_options.inspect
@@ -652,67 +655,58 @@ module Kameleoon
652
655
  data_not_sent = data_not_sent(visitor_code)
653
656
  options = {
654
657
  :path => get_experiment_register_url(visitor_code, experiment_id, variation_id, none_variation),
655
- :body => ((data_not_sent.values[0] || []).map{ |it| it.obtain_full_post_text_line }.join("\n") || "").encode("UTF-8"),
658
+ :body => (data_not_sent.map{ |it| it.obtain_full_post_text_line }.join("\n") || "").encode("UTF-8"),
656
659
  :head => { "Content-Type" => "text/plain"}
657
660
  }
658
661
  trial = 0
659
662
  success = false
660
663
  log "Start post tracking experiment: " + data_not_sent.inspect
661
664
  Thread.new do
662
- EM.synchrony do
663
- while trial < 10
664
- request = EM::Synchrony.sync post(options, @tracking_url)
665
- log "Request " + request.inspect
666
- if is_successful(request)
667
- (data_not_sent.values[0] || []).each { |it| it.sent = true }
668
- EM.stop
669
- success = true
670
- break
671
- end
672
- trial += 1
665
+ while trial < 10
666
+ log "Send Experiment Tracking " + options.inspect
667
+ response = post_sync(options, @tracking_url)
668
+ log "Response " + response.inspect
669
+ if is_successful_sync(response)
670
+ data_not_sent.each { |it| it.sent = true }
671
+ success = true
672
+ break
673
673
  end
674
- EM.stop
674
+ trial += 1
675
675
  end
676
676
  if success
677
677
  log "Post to experiment tracking is done after " + (trial + 1).to_s + " trials"
678
- elsif
678
+ else
679
679
  log "Post to experiment tracking is failed after " + trial.to_s + " trials"
680
680
  end
681
- Thread.exit
682
681
  end
683
682
  end
684
683
 
685
- def track_data(visitor_code = nil)
684
+ def track_data(visitor_code)
686
685
  Thread.new do
687
- EM.synchrony do
688
- trials = 10
689
- concurrency = 1
690
- data_not_sent = data_not_sent(visitor_code)
691
- log "Start post tracking data: " + data_not_sent.inspect
692
- while trials > 0 && !data_not_sent.empty?
693
- EM::Synchrony::Iterator.new(data_not_sent, concurrency).map do |entry, iter|
694
- options = {
695
- :path => get_data_register_url(entry.first),
696
- :body => (entry.last.map { |data| data.obtain_full_post_text_line }.join("\n") || "").encode("UTF-8"),
697
- :head => { "Content-Type" => "text/plain" }
698
- }
699
- log "Post tracking data for visitor_code: " + entry.first + " with options: " + options.inspect
700
- request = post(options, @tracking_url)
701
- request.callback {
702
- if is_successful(request)
703
- entry.last.each { |data| data.sent = true }
704
- end
705
- iter.return(request)
706
- }
707
- request.errback { iter.return(request) }
708
- end
709
- data_not_sent = data_not_sent(visitor_code)
710
- trials -= 1
686
+ trials = 0
687
+ data_not_sent = data_not_sent(visitor_code)
688
+ log "Start post tracking data: " + data_not_sent.inspect
689
+ while trials < 10 && !data_not_sent.empty?
690
+ options = {
691
+ :path => get_data_register_url(visitor_code),
692
+ :body => (data_not_sent.map{ |it| it.obtain_full_post_text_line }.join("\n") || "").encode("UTF-8"),
693
+ :head => { "Content-Type" => "text/plain" }
694
+ }
695
+ log "Post tracking data for visitor_code: " + visitor_code + " with options: " + options.inspect
696
+ response = post_sync(options, @tracking_url)
697
+ log "Response " + response.inspect
698
+ if is_successful_sync(response)
699
+ data_not_sent.each { |it| it.sent = true }
700
+ success = true
701
+ break
711
702
  end
712
- log "Post to data tracking is done."
713
- EM.stop
703
+ trials += 1
704
+ end
705
+ if success
706
+ log "Post to data tracking is done after " + (trials + 1).to_s + " trials"
707
+ else
708
+ log "Post to data tracking is failed after " + trials.to_s + " trials"
714
709
  end
715
- Thread.exit
716
710
  end
717
711
  end
718
712
 
@@ -722,12 +716,8 @@ module Kameleoon
722
716
  end
723
717
  end
724
718
 
725
- def data_not_sent(visitor_code = nil)
726
- if visitor_code.nil?
727
- @data.select {|key, values| values.any? {|data| !data.sent}}
728
- else
729
- @data.select { |key, values| key == visitor_code && values.any? {|data| !data.sent} }
730
- end
719
+ def data_not_sent(visitor_code)
720
+ @data.key?(visitor_code) ? @data[visitor_code].reject(&:sent) : []
731
721
  end
732
722
 
733
723
  def log(text)
@@ -22,7 +22,11 @@ module Kameleoon
22
22
  end
23
23
 
24
24
  def get_sync(url = API_URL, connexion_options = {})
25
- request_sync(Method::GET, url, connexion_options)
25
+ request_sync(Method::GET, url, connexion_options, {})
26
+ end
27
+
28
+ def post_sync(request_options, url = API_URL, connexion_options = {})
29
+ request_sync(Method::POST, url, connexion_options, request_options)
26
30
  end
27
31
 
28
32
  private
@@ -41,7 +45,7 @@ module Kameleoon
41
45
  end
42
46
  end
43
47
 
44
- def request_sync(method, url, connexion_options)
48
+ def request_sync(method, url, connexion_options, request_options)
45
49
  request_options = {} if request_options.nil?
46
50
  add_user_agent(request_options)
47
51
  case method
@@ -50,6 +54,14 @@ module Kameleoon
50
54
  request = Net::HTTP.new(url)
51
55
  response = Net::HTTP.get_response(uri)
52
56
  response
57
+ when Method::POST then
58
+ uri = URI.parse(url)
59
+ http = Net::HTTP.new(uri.host, uri.port)
60
+ http.use_ssl = true
61
+ request = Net::HTTP::Post.new(request_options[:path], initheader = request_options[:head])
62
+ request.body = request_options[:body]
63
+ response = http.request(request)
64
+ response
53
65
  else
54
66
  print "Unknown request type"
55
67
  return false
@@ -1,3 +1,3 @@
1
1
  module Kameleoon
2
- VERSION = '1.1.1'
2
+ VERSION = '1.1.2'
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.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kameleoon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-04 00:00:00.000000000 Z
11
+ date: 2022-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: em-http-request