kameleoon-client-ruby 1.0.2 → 1.0.3
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 +4 -4
- data/lib/kameleoon/client.rb +37 -5
- data/lib/kameleoon/factory.rb +2 -0
- 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: 4d6757ccb01117c020dd6e555554cd7d02ee6649a107e309f2998e8abbca17ea
|
4
|
+
data.tar.gz: 331997c2f44f3024d9080aff075462c48a6c013d4f939b79975ea1a6717748fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ccba30fc711816db2aa401159c1b110f97dbd5dd36ca5108cfa88aa5a7aedd6beef39d912a2351cff3d98e6e6ffd8ee2d394bf6394b9b5d8d6a23c978cf09789
|
7
|
+
data.tar.gz: 3e1c47577cd4cc0889b26d9e5c38834f24c0bfc1b4c294b65ab57117a613204cc95f923caa4bafeb345245b860f37579cf0cbe51c4f034d0e79499f520449c2a
|
data/lib/kameleoon/client.rb
CHANGED
@@ -30,6 +30,7 @@ module Kameleoon
|
|
30
30
|
@client_id = client_id || config['client_id']
|
31
31
|
@client_secret = client_secret || config['client_secret']
|
32
32
|
@data_maximum_size = config['visitor_data_maximum_size'] || 500 # mb
|
33
|
+
@verbose_mode = config['verbose_mode'] || false
|
33
34
|
@experiments = []
|
34
35
|
@feature_flags = []
|
35
36
|
@data = {}
|
@@ -96,10 +97,13 @@ module Kameleoon
|
|
96
97
|
.join("\n") || ""
|
97
98
|
path = get_experiment_register_url(visitor_code, experiment_id)
|
98
99
|
request_options = { :path => path, :body => body }
|
100
|
+
log "Trigger experiment request: " + request_options.inspect
|
101
|
+
log "Trigger experiment connexion:" + connexion_options.inspect
|
99
102
|
request = EM::Synchrony.sync post(request_options, @tracking_url, connexion_options)
|
100
103
|
if is_successful(request)
|
101
104
|
variation_id = request.response
|
102
105
|
else
|
106
|
+
log "Failed to trigger experiment: " + request.inspect
|
103
107
|
raise Exception::ExperimentConfigurationNotFound.new(experiment_id) if variation_id.nil?
|
104
108
|
end
|
105
109
|
EM.stop
|
@@ -229,9 +233,13 @@ module Kameleoon
|
|
229
233
|
:path => get_experiment_register_url(visitor_code, id),
|
230
234
|
:body => (select_data_to_sent(visitor_code).values.map { |data| data.obtain_full_post_text_line }.join("\n") || "").encode("UTF-8")
|
231
235
|
}
|
236
|
+
log "Activate feature request: " + request_options.inspect
|
237
|
+
log "Activate feature connexion:" + connexion_options.inspect
|
232
238
|
request = EM::Synchrony.sync post(request_options, @tracking_url, connexion_options)
|
233
239
|
if is_successful(request)
|
234
240
|
result = request.response
|
241
|
+
else
|
242
|
+
log "Failed to get activation:" + result.inspect
|
235
243
|
end
|
236
244
|
EM.stop
|
237
245
|
end
|
@@ -290,15 +298,16 @@ module Kameleoon
|
|
290
298
|
API_SSX_URL = "https://api-ssx.kameleoon.com"
|
291
299
|
REFERENCE = 0
|
292
300
|
attr :site_code, :client_id, :client_secret, :access_token, :experiments, :feature_flags, :scheduler, :data,
|
293
|
-
:blocking, :tracking_url, :default_timeout, :interval, :memory_limit
|
301
|
+
:blocking, :tracking_url, :default_timeout, :interval, :memory_limit, :verbose_mode
|
294
302
|
|
295
303
|
def fetch_configuration
|
296
|
-
print "=> Starting Scheduler"
|
297
304
|
@scheduler = Rufus::Scheduler.singleton
|
298
305
|
@scheduler.every @interval do
|
306
|
+
log("Scheduled job to fetch configuration is starting.")
|
299
307
|
fetch_configuration_job
|
300
308
|
end
|
301
309
|
@scheduler.schedule '0s' do
|
310
|
+
log("Start-up, fetching is starting")
|
302
311
|
fetch_configuration_job
|
303
312
|
end
|
304
313
|
end
|
@@ -334,15 +343,19 @@ module Kameleoon
|
|
334
343
|
end
|
335
344
|
|
336
345
|
def obtain_site
|
346
|
+
log "Fetching site"
|
337
347
|
query_params = { 'perPage' => 1 }
|
338
348
|
filters = [hash_filter('code', 'EQUAL', [@site_code])]
|
339
349
|
request = fetch_one('sites', query_params, filters)
|
340
350
|
if request != false
|
341
|
-
JSON.parse(request.response)
|
351
|
+
sites = JSON.parse(request.response)
|
352
|
+
log "Sites are fetched: " + sites.inspect
|
353
|
+
sites
|
342
354
|
end
|
343
355
|
end
|
344
356
|
|
345
357
|
def obtain_access_token
|
358
|
+
log "Fetching bearer token"
|
346
359
|
body = {
|
347
360
|
'grant_type' => 'client_credentials',
|
348
361
|
'client_id' => @client_id,
|
@@ -353,6 +366,9 @@ module Kameleoon
|
|
353
366
|
request = EM::Synchrony.sync post({ :path => '/oauth/token', :body => body, :head => header })
|
354
367
|
if is_successful(request)
|
355
368
|
@access_token = JSON.parse(request.response)['access_token']
|
369
|
+
log "Bearer Token is fetched: " + @access_token.to_s
|
370
|
+
else
|
371
|
+
log "Failed to fetch bearer token: " + request.inspect
|
356
372
|
end
|
357
373
|
end
|
358
374
|
|
@@ -381,26 +397,32 @@ module Kameleoon
|
|
381
397
|
end
|
382
398
|
|
383
399
|
def obtain_tests(site_id, per_page = -1)
|
400
|
+
log "Fetching experiments"
|
384
401
|
query_values = { 'perPage' => per_page }
|
385
402
|
filters = [
|
386
403
|
hash_filter('siteId', 'EQUAL', [site_id]),
|
387
404
|
hash_filter('status', 'EQUAL', ['ACTIVE']),
|
388
405
|
hash_filter('type', 'IN', ['SERVER_SIDE', 'HYBRID'])
|
389
406
|
]
|
390
|
-
fetch_all('experiments', query_values, filters).map { |it| JSON.parse(it.response) }.flatten.map do |test|
|
407
|
+
experiments = fetch_all('experiments', query_values, filters).map { |it| JSON.parse(it.response) }.flatten.map do |test|
|
391
408
|
complete_experiment(test)
|
392
409
|
end
|
410
|
+
log "Experiment are fetched: " + experiments.inspect
|
411
|
+
experiments
|
393
412
|
end
|
394
413
|
|
395
414
|
def obtain_feature_flags(site_id, per_page = -1)
|
415
|
+
log "Fetching feature flags"
|
396
416
|
query_values = { 'perPage' => per_page }
|
397
417
|
filters = [
|
398
418
|
hash_filter('siteId', 'EQUAL', [site_id]),
|
399
419
|
hash_filter('status', 'EQUAL', ['ACTIVE'])
|
400
420
|
]
|
401
|
-
fetch_all('feature-flags', query_values, filters).map { |it| JSON.parse(it.response) }.flatten.map do |ff|
|
421
|
+
feature_flags = fetch_all('feature-flags', query_values, filters).map { |it| JSON.parse(it.response) }.flatten.map do |ff|
|
402
422
|
complete_experiment(ff)
|
403
423
|
end
|
424
|
+
log "Feature flags are fetched: " + feature_flags.inspect
|
425
|
+
feature_flags
|
404
426
|
end
|
405
427
|
|
406
428
|
def fetch_all(path, query_values = {}, filters = [])
|
@@ -423,6 +445,7 @@ module Kameleoon
|
|
423
445
|
end
|
424
446
|
request = EM::Synchrony.sync get({ :path => path, :query => query_values, :head => hash_headers })
|
425
447
|
unless is_successful(request)
|
448
|
+
log "Failed to fetch" + request.inspect
|
426
449
|
return false
|
427
450
|
end
|
428
451
|
request
|
@@ -467,9 +490,11 @@ module Kameleoon
|
|
467
490
|
Thread.new do
|
468
491
|
EM.synchrony do
|
469
492
|
entries = select_data_to_sent(visitor_code)
|
493
|
+
log "Start post to tracking: " + entries.inspect
|
470
494
|
trials = 10
|
471
495
|
concurrency = 1
|
472
496
|
while !entries.empty? && trials > 0
|
497
|
+
log "Trials amount left: " + trials.to_s
|
473
498
|
EM::Synchrony::Iterator.new(entries, concurrency).map do |entry, iter|
|
474
499
|
options = {
|
475
500
|
:path => build_beacon_path(type, entry.first || visitor_code, experiment_id, variation_id, none_variation),
|
@@ -488,6 +513,7 @@ module Kameleoon
|
|
488
513
|
entries = select_data_to_sent(visitor_code)
|
489
514
|
trials -= 1
|
490
515
|
end
|
516
|
+
log "Post to tracking done"
|
491
517
|
EM.stop
|
492
518
|
end
|
493
519
|
Thread.exit
|
@@ -511,5 +537,11 @@ module Kameleoon
|
|
511
537
|
raise TypeError("Unknown type for post_beacon: " + type.to_s)
|
512
538
|
end
|
513
539
|
end
|
540
|
+
|
541
|
+
def log(text)
|
542
|
+
if @verbose_mode
|
543
|
+
print "Kameleoon Log: " + text.to_s + "\n"
|
544
|
+
end
|
545
|
+
end
|
514
546
|
end
|
515
547
|
end
|
data/lib/kameleoon/factory.rb
CHANGED
@@ -17,6 +17,8 @@ module Kameleoon
|
|
17
17
|
#
|
18
18
|
def self.create(site_code, blocking = false, config_path = CONFIG_PATH, client_id = nil, client_secret = nil)
|
19
19
|
client = Client.new(site_code, config_path, blocking, CONFIGURATION_UPDATE_INTERVAL, DEFAULT_TIMEOUT, client_id, client_secret)
|
20
|
+
client.send(:log, "Warning: you are using the blocking mode") if blocking
|
21
|
+
client.send(:log, "Client created with site code: " + site_code.to_s)
|
20
22
|
client.send(:fetch_configuration)
|
21
23
|
client
|
22
24
|
end
|
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.0.
|
4
|
+
version: 1.0.3
|
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-04-
|
11
|
+
date: 2021-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: em-http-request
|