kameleoon-client-ruby 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kameleoon/client.rb +43 -53
- data/lib/kameleoon/request.rb +14 -2
- data/lib/kameleoon/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a985a05999f2b8caeba131919f70ae77a1e6df7d125b82bf040a1056b300c1e5
|
4
|
+
data.tar.gz: d603f64d8801a3945236de7891ccde5c9a2c6747f18cb704954591a43abc5a99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89a04fd8440e3d2f3c17a6878df42088f6258979d1ec384ea8e2eaf7a3bd60c8e99624bb424bf925f86177ea9d58a98df2ddbf5adcc60871833140df600fc3d1
|
7
|
+
data.tar.gz: a61ec90742b861ce596e8526d32bef2186f722e0d2524250c470fcb5bc8de3a90711c391edbf9e8f64d4bad6b5fccb00cc3f8dd4d874cfd6f45268775defecf8
|
data/lib/kameleoon/client.rb
CHANGED
@@ -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 =
|
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
|
-
|
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).
|
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 => (
|
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
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
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
|
-
|
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
|
-
|
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
|
684
|
+
def track_data(visitor_code)
|
686
685
|
Thread.new do
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
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
|
-
|
713
|
-
|
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
|
726
|
-
|
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)
|
data/lib/kameleoon/request.rb
CHANGED
@@ -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
|
data/lib/kameleoon/version.rb
CHANGED
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.
|
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-
|
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
|