ldclient-rb 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ldclient-rb/ldclient.rb +34 -10
- data/lib/ldclient-rb/stream.rb +8 -1
- data/lib/ldclient-rb/version.rb +1 -1
- data/spec/fixtures/numeric_key_user.json +9 -0
- data/spec/fixtures/sanitized_numeric_key_user.json +9 -0
- data/spec/ldclient_spec.rb +41 -7
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33eb7dda18b6978902b85844e4eeb2a6aeb78cbd
|
4
|
+
data.tar.gz: a14cdb94a462d9ba7892dbaac4b98eb29977fca3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9ffd77abc85bd1275ed2a626a074d057a96648f29cd59c98ba59485dad33b552a9e1da1f7699f7c0ec909dca0447b6ac4098e48512e62ee955c2b0754fd5234
|
7
|
+
data.tar.gz: 3c8f4cbdc179df8803da79cf76c0205af931908b79d9c043bc2115c77249e4a6816665f1d997a8fa148ea8d1f52b70d683cbff349a16b28489f91520999c03a6
|
data/lib/ldclient-rb/ldclient.rb
CHANGED
@@ -134,6 +134,7 @@ module LaunchDarkly
|
|
134
134
|
@config.logger.error("[LDClient] Must specify user")
|
135
135
|
return default
|
136
136
|
end
|
137
|
+
sanitize_user(user)
|
137
138
|
|
138
139
|
if @config.stream? && !@stream_processor.started?
|
139
140
|
@stream_processor.start
|
@@ -176,6 +177,7 @@ module LaunchDarkly
|
|
176
177
|
# @param [Hash] The user to register
|
177
178
|
#
|
178
179
|
def identify(user)
|
180
|
+
sanitize_user(user)
|
179
181
|
add_event(kind: "identify", key: user[:key], user: user)
|
180
182
|
end
|
181
183
|
|
@@ -200,29 +202,45 @@ module LaunchDarkly
|
|
200
202
|
#
|
201
203
|
# @return [void]
|
202
204
|
def track(event_name, user, data)
|
205
|
+
sanitize_user(user)
|
203
206
|
add_event(kind: "custom", key: event_name, user: user, data: data)
|
204
207
|
end
|
205
208
|
|
206
209
|
#
|
207
|
-
# Returns the key of every feature
|
210
|
+
# Returns the key of every feature flag
|
208
211
|
#
|
209
|
-
def
|
210
|
-
|
212
|
+
def all_keys
|
213
|
+
all_flags.keys
|
211
214
|
end
|
212
215
|
|
213
216
|
#
|
214
|
-
# Returns all
|
217
|
+
# Returns all feature flags
|
215
218
|
#
|
216
|
-
def
|
217
|
-
|
219
|
+
def all_flags
|
220
|
+
return Hash.new if @offline
|
218
221
|
|
219
|
-
if
|
220
|
-
|
222
|
+
if @config.stream? && !@stream_processor.started?
|
223
|
+
@stream_processor.start
|
224
|
+
end
|
225
|
+
|
226
|
+
if @config.stream? && @stream_processor.initialized?
|
227
|
+
@stream_processor.get_all_features
|
221
228
|
else
|
222
|
-
|
229
|
+
res = make_request "/api/eval/features"
|
230
|
+
|
231
|
+
if res.status / 100 == 2
|
232
|
+
JSON.parse(res.body, symbolize_names: true)
|
233
|
+
else
|
234
|
+
@config.logger.error("[LDClient] Unexpected status code #{res.status}")
|
235
|
+
Hash.new
|
236
|
+
end
|
223
237
|
end
|
224
238
|
end
|
225
239
|
|
240
|
+
def get_user_settings(user)
|
241
|
+
Hash[all_flags.map { |key, feature| [key, evaluate(feature, user)]}]
|
242
|
+
end
|
243
|
+
|
226
244
|
def get_streamed_flag(key)
|
227
245
|
feature = get_flag_stream(key)
|
228
246
|
if @config.debug_stream?
|
@@ -391,9 +409,15 @@ module LaunchDarkly
|
|
391
409
|
@config.logger.error(error)
|
392
410
|
end
|
393
411
|
|
412
|
+
def sanitize_user(user)
|
413
|
+
if user[:key]
|
414
|
+
user[:key] = user[:key].to_s
|
415
|
+
end
|
416
|
+
end
|
417
|
+
|
394
418
|
private :post_flushed_events, :add_event, :get_streamed_flag,
|
395
419
|
:get_flag_stream, :get_flag_int, :make_request, :param_for_user,
|
396
420
|
:match_target?, :match_user?, :match_variation?, :evaluate,
|
397
|
-
:create_worker, :log_timings, :log_exception
|
421
|
+
:create_worker, :log_timings, :log_exception, :sanitize_user
|
398
422
|
end
|
399
423
|
end
|
data/lib/ldclient-rb/stream.rb
CHANGED
@@ -80,6 +80,13 @@ module LaunchDarkly
|
|
80
80
|
@started.value
|
81
81
|
end
|
82
82
|
|
83
|
+
def get_all_features
|
84
|
+
if not initialized?
|
85
|
+
throw :uninitialized
|
86
|
+
end
|
87
|
+
@store.all
|
88
|
+
end
|
89
|
+
|
83
90
|
def get_feature(key)
|
84
91
|
if not initialized?
|
85
92
|
throw :uninitialized
|
@@ -125,7 +132,7 @@ module LaunchDarkly
|
|
125
132
|
source.on(PATCH) { |message| process_message(message, PATCH) }
|
126
133
|
source.on(DELETE) { |message| process_message(message, DELETE) }
|
127
134
|
source.error do |error|
|
128
|
-
@config.logger.info("[LDClient]
|
135
|
+
@config.logger.info("[LDClient] Stream connection: #{error}")
|
129
136
|
set_disconnected
|
130
137
|
end
|
131
138
|
source.inactivity_timeout = 0
|
data/lib/ldclient-rb/version.rb
CHANGED
data/spec/ldclient_spec.rb
CHANGED
@@ -14,6 +14,14 @@ describe LaunchDarkly::LDClient do
|
|
14
14
|
data = File.read(File.join("spec", "fixtures", "user.json"))
|
15
15
|
JSON.parse(data, symbolize_names: true)
|
16
16
|
end
|
17
|
+
let(:numeric_key_user) do
|
18
|
+
data = File.read(File.join("spec", "fixtures", "numeric_key_user.json"))
|
19
|
+
JSON.parse(data, symbolize_names: true)
|
20
|
+
end
|
21
|
+
let(:sanitized_numeric_key_user) do
|
22
|
+
data = File.read(File.join("spec", "fixtures", "sanitized_numeric_key_user.json"))
|
23
|
+
JSON.parse(data, symbolize_names: true)
|
24
|
+
end
|
17
25
|
|
18
26
|
context 'user flag settings' do
|
19
27
|
describe '#update_user_flag_setting' do
|
@@ -85,6 +93,10 @@ describe LaunchDarkly::LDClient do
|
|
85
93
|
result = client.toggle?(feature[:key], nil, "default")
|
86
94
|
expect(result).to eq "default"
|
87
95
|
end
|
96
|
+
it "sanitizes the user in the event" do
|
97
|
+
expect(client).to receive(:add_event).with(hash_including(user: sanitized_numeric_key_user))
|
98
|
+
client.toggle?(feature[:key], numeric_key_user, "default")
|
99
|
+
end
|
88
100
|
it "returns value from streamed flag if available" do
|
89
101
|
expect(client.instance_variable_get(:@config)).to receive(:stream?).and_return(true).twice
|
90
102
|
expect(client.instance_variable_get(:@stream_processor)).to receive(:started?).and_return true
|
@@ -103,6 +115,28 @@ describe LaunchDarkly::LDClient do
|
|
103
115
|
end
|
104
116
|
end
|
105
117
|
|
118
|
+
describe '#identify' do
|
119
|
+
it "queues up an identify event" do
|
120
|
+
expect(client).to receive(:add_event).with(hash_including(kind: "identify", key: user[:key], user: user))
|
121
|
+
client.identify(user)
|
122
|
+
end
|
123
|
+
it "sanitizes the user in the event" do
|
124
|
+
expect(client).to receive(:add_event).with(hash_including(user: sanitized_numeric_key_user))
|
125
|
+
client.identify(numeric_key_user)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe '#track' do
|
130
|
+
it "queues up an custom event" do
|
131
|
+
expect(client).to receive(:add_event).with(hash_including(kind: "custom", key: "custom_event_name", user: user, data: 42))
|
132
|
+
client.track("custom_event_name", user, 42)
|
133
|
+
end
|
134
|
+
it "sanitizes the user in the event" do
|
135
|
+
expect(client).to receive(:add_event).with(hash_including(user: sanitized_numeric_key_user))
|
136
|
+
client.track("custom_event_name", numeric_key_user, nil)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
106
140
|
describe '#get_streamed_flag' do
|
107
141
|
it "will not check the polled flag normally" do
|
108
142
|
expect(client).to receive(:get_flag_stream).and_return true
|
@@ -120,18 +154,18 @@ describe LaunchDarkly::LDClient do
|
|
120
154
|
end
|
121
155
|
end
|
122
156
|
|
123
|
-
describe '#
|
157
|
+
describe '#all_flags' do
|
124
158
|
it "will parse and return the features list" do
|
125
|
-
result = double("Faraday::Response", status: 200, body: '{"
|
126
|
-
expect(client).to receive(:make_request).with("/api/features").and_return(result)
|
127
|
-
data = client.send(:
|
128
|
-
expect(data).to eq
|
159
|
+
result = double("Faraday::Response", status: 200, body: '{"asdf":"qwer"}')
|
160
|
+
expect(client).to receive(:make_request).with("/api/eval/features").and_return(result)
|
161
|
+
data = client.send(:all_flags)
|
162
|
+
expect(data).to eq(asdf: "qwer")
|
129
163
|
end
|
130
164
|
it "will log errors" do
|
131
165
|
result = double("Faraday::Response", status: 418)
|
132
|
-
expect(client).to receive(:make_request).with("/api/features").and_return(result)
|
166
|
+
expect(client).to receive(:make_request).with("/api/eval/features").and_return(result)
|
133
167
|
expect(client.instance_variable_get(:@config).logger).to receive(:error)
|
134
|
-
client.send(:
|
168
|
+
client.send(:all_flags)
|
135
169
|
end
|
136
170
|
end
|
137
171
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ldclient-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- LaunchDarkly
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -207,6 +207,8 @@ files:
|
|
207
207
|
- lib/ldclient-rb/version.rb
|
208
208
|
- spec/config_spec.rb
|
209
209
|
- spec/fixtures/feature.json
|
210
|
+
- spec/fixtures/numeric_key_user.json
|
211
|
+
- spec/fixtures/sanitized_numeric_key_user.json
|
210
212
|
- spec/fixtures/user.json
|
211
213
|
- spec/ldclient_spec.rb
|
212
214
|
- spec/newrelic_spec.rb
|
@@ -241,6 +243,8 @@ summary: LaunchDarkly SDK for Ruby
|
|
241
243
|
test_files:
|
242
244
|
- spec/config_spec.rb
|
243
245
|
- spec/fixtures/feature.json
|
246
|
+
- spec/fixtures/numeric_key_user.json
|
247
|
+
- spec/fixtures/sanitized_numeric_key_user.json
|
244
248
|
- spec/fixtures/user.json
|
245
249
|
- spec/ldclient_spec.rb
|
246
250
|
- spec/newrelic_spec.rb
|