pioneer_ruby_sdk 1.0.2 → 1.1.0
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/pioneer_ruby_sdk.rb +11 -9
- data/lib/ruby_sdk/analytics_collector.rb +25 -0
- data/lib/ruby_sdk/client_with_context.rb +29 -0
- data/lib/{context.rb → ruby_sdk/context.rb} +0 -0
- data/lib/{event_source_client.rb → ruby_sdk/event_source_client.rb} +16 -2
- data/lib/{feature_state.rb → ruby_sdk/feature_state.rb} +0 -0
- data/lib/ruby_sdk/mod/handle_undefined_feature.rb +9 -0
- data/lib/{strategy.rb → ruby_sdk/strategy.rb} +2 -2
- metadata +9 -8
- data/lib/client_with_context.rb +0 -18
- data/lib/mod/handle_undefined_feature.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f04719f85f42f76f879aba2f375dcb436c02792f585e7f9a3b9105a9b15582d
|
4
|
+
data.tar.gz: 293839fdfe2eabdcf69d307e990e69c1b6a890b976b5c8f49b0e596fed1f640f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25dfae0e844f5b1ef31324094ea977eede067ef6e314500195212fc5e040ef36b8a8c9977cfea90530b66f1b4a6550aef3ab9493845be8d83046749f08e3fd76
|
7
|
+
data.tar.gz: 96cdd692ba161959aec50ce8b4d454c2f1f7143e6b497c65bba070a5f28366338f8cea1aeb943d13a96c852b03bfc8055dbe5e21500d5dc2c3682c898a378ed3
|
data/lib/pioneer_ruby_sdk.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require_relative 'event_source_client'
|
2
|
-
require_relative 'context'
|
3
|
-
require_relative 'client_with_context'
|
1
|
+
require_relative 'ruby_sdk/event_source_client'
|
2
|
+
require_relative 'ruby_sdk/context'
|
3
|
+
require_relative 'ruby_sdk/client_with_context'
|
4
4
|
|
5
5
|
# wrapper for event source client
|
6
6
|
class PioneerRubySdk
|
@@ -14,42 +14,44 @@ class PioneerRubySdk
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def connect()
|
17
|
-
@client =
|
17
|
+
@client = EventSourceClient.new(@configs)
|
18
18
|
@client.start
|
19
19
|
self
|
20
20
|
end
|
21
21
|
|
22
|
-
def with_wait_for_data(
|
22
|
+
def with_wait_for_data()
|
23
|
+
time_out = 1
|
24
|
+
polling_attempts = 10
|
23
25
|
attempts = 0
|
24
26
|
|
25
27
|
until @client.has_data() do
|
26
28
|
attempts += 1
|
27
29
|
if attempts > polling_attempts
|
28
30
|
puts "Cannot connect to Scout, connection timed out"
|
31
|
+
@client.close()
|
29
32
|
break
|
30
33
|
end
|
31
34
|
|
32
|
-
|
35
|
+
puts 'Attempting to connect to scout daemon...'
|
33
36
|
end
|
34
37
|
return self
|
35
38
|
end
|
36
39
|
|
37
40
|
def with_context(user_key)
|
38
|
-
user_key = user_key
|
39
41
|
context_obj = {
|
40
42
|
context: Context.new(user_key),
|
41
43
|
client: @client,
|
42
44
|
config: @configs
|
43
45
|
}
|
44
46
|
|
45
|
-
return
|
47
|
+
return ClientWithContext.new(context_obj)
|
46
48
|
end
|
47
49
|
|
48
50
|
def get_server_address()
|
49
51
|
return @server_address
|
50
52
|
end
|
51
53
|
|
52
|
-
def get_feature(key, default_value)
|
54
|
+
def get_feature(key, default_value = nil)
|
53
55
|
@client.get_feature(key, default_value)
|
54
56
|
end
|
55
57
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
# class to handle connections to Google Analytics account
|
4
|
+
class AnalyticsCollector
|
5
|
+
def initialize(config_object)
|
6
|
+
@tracking_id = config_object[:tracking_id]
|
7
|
+
@client_id = config_object[:client_id]
|
8
|
+
end
|
9
|
+
|
10
|
+
def log_event(event_object)
|
11
|
+
client_id = event_object[:client_id]
|
12
|
+
|
13
|
+
Net::HTTP.post_form(
|
14
|
+
URI("https://www.google-analytics.com/collect"),
|
15
|
+
v: "1", # API Version
|
16
|
+
tid: @tracking_id, # Tracking ID / Property ID
|
17
|
+
cid: @client_id, # Client ID
|
18
|
+
t: "event", # Event hit type
|
19
|
+
ec: event_object[:category], # Event category
|
20
|
+
ea: event_object[:action], # Event action
|
21
|
+
el: event_object[:label], # Event label
|
22
|
+
ev: event_object[:value] # Event value
|
23
|
+
)
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'mod/handle_undefined_feature.rb'
|
2
|
+
|
3
|
+
class ClientWithContext
|
4
|
+
def initialize(context_obj)
|
5
|
+
@context = context_obj[:context]
|
6
|
+
@client = context_obj[:client]
|
7
|
+
@config = context_obj[:config]
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_feature(key, default_value = nil)
|
11
|
+
feature_state = @client.get_feature_state(key)
|
12
|
+
return HandleUndefinedFeature.handle(key, default_value) if !feature_state
|
13
|
+
|
14
|
+
# if value of flag is true, use rollout
|
15
|
+
if feature_state.value
|
16
|
+
return feature_state.strategy.calculate(@context)
|
17
|
+
else
|
18
|
+
return feature_state.value
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def add_google_analytics_collector(config_object)
|
23
|
+
@client.add_google_analytics_collector(config_object)
|
24
|
+
end
|
25
|
+
|
26
|
+
def log_event(event_object)
|
27
|
+
@client.log_event(event_object)
|
28
|
+
end
|
29
|
+
end
|
File without changes
|
@@ -1,15 +1,17 @@
|
|
1
1
|
require 'ld-eventsource'
|
2
2
|
require 'json'
|
3
3
|
require_relative 'feature_state'
|
4
|
+
require_relative 'analytics_collector'
|
4
5
|
require_relative 'mod/handle_undefined_feature'
|
5
6
|
|
6
7
|
# class for event source client instance
|
7
|
-
class
|
8
|
+
class EventSourceClient
|
8
9
|
attr_reader :has_data
|
9
10
|
|
10
11
|
def initialize(config)
|
11
12
|
@config = config
|
12
13
|
@features = {}
|
14
|
+
@analytics_collectors = []
|
13
15
|
@has_data = false
|
14
16
|
options = {
|
15
17
|
headers: { Authorization: @config[:sdk_key]}
|
@@ -61,7 +63,7 @@ class Event_Source_Client
|
|
61
63
|
@has_data = true
|
62
64
|
end
|
63
65
|
|
64
|
-
def get_feature(key, default_value)
|
66
|
+
def get_feature(key, default_value = nil)
|
65
67
|
feature_state = get_feature_state(key)
|
66
68
|
if feature_state.nil?
|
67
69
|
HandleUndefinedFeature.handle(key, default_value)
|
@@ -75,4 +77,16 @@ class Event_Source_Client
|
|
75
77
|
def get_feature_state(key)
|
76
78
|
return @features[key]
|
77
79
|
end
|
80
|
+
|
81
|
+
def add_google_analytics_collector(config_object)
|
82
|
+
analytics_collector = AnalyticsCollector.new(config_object)
|
83
|
+
@analytics_collectors.push(analytics_collector)
|
84
|
+
return analytics_collector
|
85
|
+
end
|
86
|
+
|
87
|
+
def log_event(event_object)
|
88
|
+
@analytics_collectors.each do |analytics_collector|
|
89
|
+
analytics_collector.log_event(event_object)
|
90
|
+
end
|
91
|
+
end
|
78
92
|
end
|
File without changes
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module HandleUndefinedFeature
|
2
|
+
def self.handle(key, default_value)
|
3
|
+
unless default_value.nil?
|
4
|
+
puts("Warning: Could not get '#{key}' from features, using provided default value!")
|
5
|
+
return default_value
|
6
|
+
end
|
7
|
+
raise StandardError.new("Error: flag with title '#{key}' does not exist, cannot get get feature!");
|
8
|
+
end
|
9
|
+
end
|
@@ -2,13 +2,13 @@
|
|
2
2
|
|
3
3
|
# handles the calculation of rollout for a given context
|
4
4
|
class Strategy
|
5
|
-
|
5
|
+
def initialize(percentage)
|
6
6
|
@percentage = percentage
|
7
7
|
@modulus = 100
|
8
8
|
end
|
9
9
|
|
10
10
|
def calculate(context)
|
11
|
-
key = context.get_key
|
11
|
+
key = context.get_key
|
12
12
|
hashed_percentage = get_hash_based_percentage(key)
|
13
13
|
return hashed_percentage <= @percentage
|
14
14
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pioneer_ruby_sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jimmy Zheng
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2021-
|
14
|
+
date: 2021-08-25 00:00:00.000000000 Z
|
15
15
|
dependencies: []
|
16
16
|
description:
|
17
17
|
email:
|
@@ -19,13 +19,14 @@ executables: []
|
|
19
19
|
extensions: []
|
20
20
|
extra_rdoc_files: []
|
21
21
|
files:
|
22
|
-
- lib/client_with_context.rb
|
23
|
-
- lib/context.rb
|
24
|
-
- lib/event_source_client.rb
|
25
|
-
- lib/feature_state.rb
|
26
|
-
- lib/mod/handle_undefined_feature.rb
|
27
22
|
- lib/pioneer_ruby_sdk.rb
|
28
|
-
- lib/
|
23
|
+
- lib/ruby_sdk/analytics_collector.rb
|
24
|
+
- lib/ruby_sdk/client_with_context.rb
|
25
|
+
- lib/ruby_sdk/context.rb
|
26
|
+
- lib/ruby_sdk/event_source_client.rb
|
27
|
+
- lib/ruby_sdk/feature_state.rb
|
28
|
+
- lib/ruby_sdk/mod/handle_undefined_feature.rb
|
29
|
+
- lib/ruby_sdk/strategy.rb
|
29
30
|
homepage:
|
30
31
|
licenses:
|
31
32
|
- MIT
|
data/lib/client_with_context.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require_relative 'mod/handle_undefined_feature.rb'
|
2
|
-
|
3
|
-
class Client_With_Context
|
4
|
-
def initialize(context_obj)
|
5
|
-
@context = context_obj[:context]
|
6
|
-
@client = context_obj[:client]
|
7
|
-
@config = context_obj[:config]
|
8
|
-
end
|
9
|
-
|
10
|
-
def get_feature(key, default_value)
|
11
|
-
feature_state = @client.get_feature_state(key)
|
12
|
-
if !feature_state
|
13
|
-
return HandleUndefinedFeature.handle(key, default_value)
|
14
|
-
end
|
15
|
-
|
16
|
-
return feature_state.strategy.calculate(@context)
|
17
|
-
end
|
18
|
-
end
|
@@ -1,9 +0,0 @@
|
|
1
|
-
module HandleUndefinedFeature
|
2
|
-
def self.handle(key, default_value)
|
3
|
-
unless default_value.nil?
|
4
|
-
puts("Warning: Could not get #{key} from features, using provided default value!")
|
5
|
-
return default_value
|
6
|
-
end
|
7
|
-
raise("Error: #{key} does not exist, cannot get get feature!");
|
8
|
-
end
|
9
|
-
end
|