ldclient-rb 0.0.10 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 587e55c3ef0efd34923cf2ad2bf2dec7e0246288
4
- data.tar.gz: 1157e0acbe4b364ff1f6948945c72929b951068d
3
+ metadata.gz: 80585fb99df9069ece05ebb56d7bb8368daba554
4
+ data.tar.gz: 4e159d25726a447551f0b40dd53796b4a919027b
5
5
  SHA512:
6
- metadata.gz: f0498d182b82a3ddf9943d33407797c03eb7e95dcdfe1a2d8a6009de9e48a60b8e0e755921d5fc10655e0e918f463395469291dc33c25d83dbe2309a1662d7a0
7
- data.tar.gz: e4520dcc50c5999fff9f35a99678f0311b2b9ffe3cc60f7e97d56fd1ccf52eff92024ac53b484c71270c1cef6a3ef4734aaea15f1663d2f5d4d0124f7e2c1bc7
6
+ metadata.gz: 2664a3dc182dea123051ab19f34ef094c189c9f07bed2793de3681c5d11d229b4e86d5d3a7c276406023250b69293024432085f2cc03425770ee5fcc4c514ff2
7
+ data.tar.gz: 92711ce5b40245a1b4c153c069f0075e2ddde2a89e3769b8f00677c0c253de4b51c91f944af665b877d978aa72dd8d1db79a194fd9c4fbf88212c5a89c17457b
@@ -5,6 +5,9 @@ require 'thread'
5
5
  require 'logger'
6
6
 
7
7
  module LaunchDarkly
8
+
9
+ BUILTINS = [:key, :ip, :country, :email, :firstName, :lastName, :avatar, :name]
10
+
8
11
  #
9
12
  # A client for the LaunchDarkly API. Client instances are thread-safe. Users
10
13
  # should create a single client instance for the lifetime of the application.
@@ -36,30 +39,39 @@ module LaunchDarkly
36
39
  @worker = create_worker()
37
40
  end
38
41
 
42
+ def flush()
43
+ events = []
44
+ num_events = @queue.length()
45
+ begin
46
+ num_events.times do
47
+ events << @queue.pop(true)
48
+ end
49
+ rescue
50
+ end
51
+
52
+
53
+ if !events.empty?()
54
+ res =
55
+ @client.post (@config.base_uri + "/api/events/bulk") do |req|
56
+ req.headers['Authorization'] = 'api_key ' + @api_key
57
+ req.headers['User-Agent'] = 'RubyClient/' + LaunchDarkly::VERSION
58
+ req.headers['Content-Type'] = 'application/json'
59
+ req.body = events.to_json
60
+ req.options.timeout = @config.read_timeout
61
+ req.options.open_timeout = @config.connect_timeout
62
+ end
63
+ if res.status != 200
64
+ @config.logger.error("[LDClient] Unexpected status code while processing events: #{res.status}")
65
+ end
66
+ end
67
+ end
68
+
69
+
39
70
  def create_worker()
40
71
  Thread.new do
41
72
  while true do
42
73
  begin
43
- events = []
44
- num_events = @queue.length()
45
- num_events.times do
46
- events << @queue.pop()
47
- end
48
-
49
- if !events.empty?()
50
- res =
51
- @client.post (@config.base_uri + "/api/events/bulk") do |req|
52
- req.headers['Authorization'] = 'api_key ' + @api_key
53
- req.headers['User-Agent'] = 'RubyClient/' + LaunchDarkly::VERSION
54
- req.headers['Content-Type'] = 'application/json'
55
- req.body = events.to_json
56
- req.options.timeout = @config.read_timeout
57
- req.options.open_timeout = @config.connect_timeout
58
- end
59
- if res.status != 200
60
- @config.logger.error("[LDClient] Unexpected status code while processing events: #{res.status}")
61
- end
62
- end
74
+ flush()
63
75
 
64
76
  sleep(@config.flush_interval)
65
77
  rescue Exception => exn
@@ -136,7 +148,7 @@ module LaunchDarkly
136
148
  # @param [Hash] The user to register
137
149
  #
138
150
  def identify(user)
139
- add_event({:kind => 'identify', :key => user.key, :user => user})
151
+ add_event({:kind => 'identify', :key => user[:key], :user => user})
140
152
  end
141
153
 
142
154
  def set_offline()
@@ -221,7 +233,7 @@ module LaunchDarkly
221
233
  def match_target?(target, user)
222
234
  attrib = target[:attribute].to_sym
223
235
 
224
- if attrib == :key or attrib == :ip or attrib == :country
236
+ if BUILTINS.include?(attrib)
225
237
  if user[attrib]
226
238
  u_value = user[attrib]
227
239
  return target[:values].include? u_value
@@ -247,8 +259,19 @@ module LaunchDarkly
247
259
 
248
260
  end
249
261
 
262
+ def match_user?(variation, user)
263
+ if !!variation[:userTarget]
264
+ return match_target?(variation[:userTarget], user)
265
+ end
266
+ return false
267
+ end
268
+
250
269
  def match_variation?(variation, user)
251
270
  variation[:targets].each do |target|
271
+ if !!variation[:userTarget] and target[:attribute].to_sym == :key
272
+ next
273
+ end
274
+
252
275
  if match_target?(target, user)
253
276
  return true
254
277
  end
@@ -267,6 +290,12 @@ module LaunchDarkly
267
290
  return nil
268
291
  end
269
292
 
293
+ feature[:variations].each do |variation|
294
+ if match_user?(variation, user)
295
+ return variation[:value]
296
+ end
297
+ end
298
+
270
299
  feature[:variations].each do |variation|
271
300
  if match_variation?(variation, user)
272
301
  return variation[:value]
@@ -286,7 +315,7 @@ module LaunchDarkly
286
315
 
287
316
  end
288
317
 
289
- private :add_event, :get_flag_int, :param_for_user, :match_target?, :match_variation?, :evaluate, :create_worker
318
+ private :add_event, :get_flag_int, :param_for_user, :match_target?, :match_user?, :match_variation?, :evaluate, :create_worker
290
319
 
291
320
 
292
321
  end
@@ -1,3 +1,3 @@
1
1
  module LaunchDarkly
2
- VERSION = "0.0.10"
2
+ VERSION = "0.1.0"
3
3
  end
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.0.10
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Catamorphic Co
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-26 00:00:00.000000000 Z
11
+ date: 2015-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler