ldclient-rb 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/Gemfile +1 -1
- data/Gemfile.lock +30 -0
- data/ldclient-rb.gemspec +1 -0
- data/lib/ldclient-rb/ldclient.rb +49 -22
- data/lib/ldclient-rb/version.rb +1 -1
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a73519d15b98bcb02f0fb8e111d301839fb8401
|
4
|
+
data.tar.gz: 3a6a476a10a497bc7695028f1a197c91069f07a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 451e8ea84cb0be1a56d2b7050fe92929d64d9cacf2e2396ca1e0f953dfcfeff3df8b9dc7e89c5e849bb36463a40b369b722e26a73fb8f1dc82be49dd73f04463
|
7
|
+
data.tar.gz: 09a5bc459d836a586c5996e61e80acc31475db8d35db2466c11f020570df00a7ab07cbc87651270a35087c569dc8b666e89326418fc121c28b2de96efe1017cd
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ldclient-rb (0.1.0)
|
5
|
+
faraday (~> 0.9)
|
6
|
+
faraday-http-cache (~> 0.4)
|
7
|
+
json (~> 1.8)
|
8
|
+
net-http-persistent (~> 2.9.4)
|
9
|
+
thread_safe (~> 0.3)
|
10
|
+
|
11
|
+
GEM
|
12
|
+
remote: https://rubygems.org/
|
13
|
+
specs:
|
14
|
+
faraday (0.9.1)
|
15
|
+
multipart-post (>= 1.2, < 3)
|
16
|
+
faraday-http-cache (0.4.2)
|
17
|
+
faraday (~> 0.8)
|
18
|
+
json (1.8.2)
|
19
|
+
multipart-post (2.0.0)
|
20
|
+
net-http-persistent (2.9.4)
|
21
|
+
rake (10.4.2)
|
22
|
+
thread_safe (0.3.4)
|
23
|
+
|
24
|
+
PLATFORMS
|
25
|
+
ruby
|
26
|
+
|
27
|
+
DEPENDENCIES
|
28
|
+
bundler (~> 1.7)
|
29
|
+
ldclient-rb!
|
30
|
+
rake (~> 10.0)
|
data/ldclient-rb.gemspec
CHANGED
@@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_runtime_dependency "faraday", "~> 0.9"
|
26
26
|
spec.add_runtime_dependency "faraday-http-cache", "~> 0.4"
|
27
27
|
spec.add_runtime_dependency "thread_safe", "~> 0.3"
|
28
|
+
spec.add_runtime_dependency "net-http-persistent", "~> 2.9.4"
|
28
29
|
end
|
data/lib/ldclient-rb/ldclient.rb
CHANGED
@@ -3,10 +3,12 @@ require 'json'
|
|
3
3
|
require 'digest/sha1'
|
4
4
|
require 'thread'
|
5
5
|
require 'logger'
|
6
|
+
require 'net/http/persistent'
|
7
|
+
require 'benchmark'
|
6
8
|
|
7
9
|
module LaunchDarkly
|
8
10
|
|
9
|
-
BUILTINS = [:key, :ip, :country, :email, :firstName, :lastName, :avatar, :name]
|
11
|
+
BUILTINS = [:key, :ip, :country, :email, :firstName, :lastName, :avatar, :name, :anonymous]
|
10
12
|
|
11
13
|
#
|
12
14
|
# A client for the LaunchDarkly API. Client instances are thread-safe. Users
|
@@ -32,7 +34,7 @@ module LaunchDarkly
|
|
32
34
|
@client = Faraday.new do |builder|
|
33
35
|
builder.use :http_cache, store: @config.store
|
34
36
|
|
35
|
-
builder.adapter
|
37
|
+
builder.adapter :net_http_persistent
|
36
38
|
end
|
37
39
|
@offline = false
|
38
40
|
|
@@ -51,15 +53,16 @@ module LaunchDarkly
|
|
51
53
|
|
52
54
|
|
53
55
|
if !events.empty?()
|
54
|
-
res =
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
56
|
+
res = log_timings("Flush events") {
|
57
|
+
next @client.post (@config.base_uri + "/api/events/bulk") do |req|
|
58
|
+
req.headers['Authorization'] = 'api_key ' + @api_key
|
59
|
+
req.headers['User-Agent'] = 'RubyClient/' + LaunchDarkly::VERSION
|
60
|
+
req.headers['Content-Type'] = 'application/json'
|
61
|
+
req.body = events.to_json
|
62
|
+
req.options.timeout = @config.read_timeout
|
63
|
+
req.options.open_timeout = @config.connect_timeout
|
64
|
+
end
|
65
|
+
}
|
63
66
|
if res.status != 200
|
64
67
|
@config.logger.error("[LDClient] Unexpected status code while processing events: #{res.status}")
|
65
68
|
end
|
@@ -75,12 +78,16 @@ module LaunchDarkly
|
|
75
78
|
|
76
79
|
sleep(@config.flush_interval)
|
77
80
|
rescue Exception => exn
|
78
|
-
@config.logger.error("[LDClient] Unexpected exception in create_worker: #{exn.
|
81
|
+
@config.logger.error("[LDClient] Unexpected exception in create_worker: #{exn.inspect} #{exn.to_s}\n\t#{exn.backtrace.join("\n\t")}")
|
79
82
|
end
|
80
83
|
end
|
81
84
|
end
|
82
85
|
end
|
83
86
|
|
87
|
+
def get_flag?(key, user, default=false)
|
88
|
+
toggle?(key, user, default)
|
89
|
+
end
|
90
|
+
|
84
91
|
#
|
85
92
|
# Calculates the value of a feature flag for a given user. At a minimum, the user hash
|
86
93
|
# should contain a +:key+ .
|
@@ -111,7 +118,7 @@ module LaunchDarkly
|
|
111
118
|
# @param default=false [Boolean] the default value of the flag
|
112
119
|
#
|
113
120
|
# @return [Boolean] whether or not the flag should be enabled, or the default value if the flag is disabled on the LaunchDarkly control panel
|
114
|
-
def
|
121
|
+
def toggle?(key, user, default=false)
|
115
122
|
begin
|
116
123
|
if @offline
|
117
124
|
return default
|
@@ -121,7 +128,7 @@ module LaunchDarkly
|
|
121
128
|
add_event({:kind => 'feature', :key => key, :user => user, :value => value})
|
122
129
|
return value
|
123
130
|
rescue StandardError => error
|
124
|
-
@config.logger.error("[LDClient] Unhandled exception in get_flag: #{error.
|
131
|
+
@config.logger.error("[LDClient] Unhandled exception in get_flag: (#{error.class.name}) #{error.to_s}\n\t#{error.backtrace.join("\n\t")}")
|
125
132
|
default
|
126
133
|
end
|
127
134
|
end
|
@@ -182,13 +189,14 @@ module LaunchDarkly
|
|
182
189
|
return default
|
183
190
|
end
|
184
191
|
|
185
|
-
res =
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
+
res = log_timings("Flush events") {
|
193
|
+
next @client.get (@config.base_uri + '/api/eval/features/' + key) do |req|
|
194
|
+
req.headers['Authorization'] = 'api_key ' + @api_key
|
195
|
+
req.headers['User-Agent'] = 'RubyClient/' + LaunchDarkly::VERSION
|
196
|
+
req.options.timeout = @config.read_timeout
|
197
|
+
req.options.open_timeout = @config.connect_timeout
|
198
|
+
end
|
199
|
+
}
|
192
200
|
|
193
201
|
if res.status == 401
|
194
202
|
@config.logger.error("[LDClient] Invalid API key")
|
@@ -315,8 +323,27 @@ module LaunchDarkly
|
|
315
323
|
|
316
324
|
end
|
317
325
|
|
318
|
-
|
326
|
+
def log_timings(label, &block)
|
327
|
+
if !@config.logger.debug?
|
328
|
+
return block.call
|
329
|
+
end
|
330
|
+
res = nil
|
331
|
+
exn = nil
|
332
|
+
bench = Benchmark.measure {
|
333
|
+
begin
|
334
|
+
res = block.call
|
335
|
+
rescue Exception => e
|
336
|
+
exn = e
|
337
|
+
end
|
338
|
+
}
|
339
|
+
@config.logger.debug { "[LDClient] #{label} timing: #{bench}".chomp }
|
340
|
+
if exn
|
341
|
+
raise exn
|
342
|
+
end
|
343
|
+
return res
|
344
|
+
end
|
319
345
|
|
346
|
+
private :add_event, :get_flag_int, :param_for_user, :match_target?, :match_user?, :match_variation?, :evaluate, :create_worker, :log_timings
|
320
347
|
|
321
348
|
end
|
322
349
|
end
|
data/lib/ldclient-rb/version.rb
CHANGED
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.1.
|
4
|
+
version: 0.1.1
|
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-
|
11
|
+
date: 2015-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0.3'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: net-http-persistent
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 2.9.4
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 2.9.4
|
97
111
|
description: Official LaunchDarkly SDK for Ruby
|
98
112
|
email:
|
99
113
|
- team@catamorphic.com
|
@@ -103,6 +117,7 @@ extra_rdoc_files: []
|
|
103
117
|
files:
|
104
118
|
- ".gitignore"
|
105
119
|
- Gemfile
|
120
|
+
- Gemfile.lock
|
106
121
|
- LICENSE.txt
|
107
122
|
- README.md
|
108
123
|
- Rakefile
|