ldclient-rb 0.0.9 → 0.0.10
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/config.rb +30 -2
- data/lib/ldclient-rb/ldclient.rb +37 -4
- data/lib/ldclient-rb/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 587e55c3ef0efd34923cf2ad2bf2dec7e0246288
|
4
|
+
data.tar.gz: 1157e0acbe4b364ff1f6948945c72929b951068d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0498d182b82a3ddf9943d33407797c03eb7e95dcdfe1a2d8a6009de9e48a60b8e0e755921d5fc10655e0e918f463395469291dc33c25d83dbe2309a1662d7a0
|
7
|
+
data.tar.gz: e4520dcc50c5999fff9f35a99678f0311b2b9ffe3cc60f7e97d56fd1ccf52eff92024ac53b484c71270c1cef6a3ef4734aaea15f1663d2f5d4d0124f7e2c1bc7
|
data/lib/ldclient-rb/config.rb
CHANGED
@@ -15,7 +15,9 @@ module LaunchDarkly
|
|
15
15
|
# @option opts [Logger] :logger A logger to use for messages from the LaunchDarkly client. Defaults to the Rails logger in a Rails environment, or stdout otherwise.
|
16
16
|
# @option opts [String] :base_uri ("https://app.launchdarkly.com") The base URL for the LaunchDarkly server. Most users should use the default value.
|
17
17
|
# @option opts [Integer] :capacity (10000) The capacity of the events buffer. The client buffers up to this many events in memory before flushing. If the capacity is exceeded before the buffer is flushed, events will be discarded.
|
18
|
-
# @option opts [
|
18
|
+
# @option opts [Float] :flush_interval (30) The number of seconds between flushes of the event buffer.
|
19
|
+
# @option opts [Float] :read_timeout (10) The read timeout for network connections in seconds.
|
20
|
+
# @option opts [Float] :connect_timeout (2) The connect timeout for network connections in seconds.
|
19
21
|
# @option opts [Object] :store A cache store for the Faraday HTTP caching library. Defaults to the Rails cache in a Rails environment, or a thread-safe in-memory store otherwise.
|
20
22
|
#
|
21
23
|
# @return [type] [description]
|
@@ -25,6 +27,8 @@ module LaunchDarkly
|
|
25
27
|
@logger = opts[:logger] || Config.default_logger
|
26
28
|
@store = opts[:store] || Config.default_store
|
27
29
|
@flush_interval = opts[:flush_interval] || Config.default_flush_interval
|
30
|
+
@connect_timeout = opts[:connect_timeout] || Config.default_connect_timeout
|
31
|
+
@read_timeout = opts[:read_timeout] || Config.default_read_timeout
|
28
32
|
end
|
29
33
|
|
30
34
|
#
|
@@ -39,7 +43,7 @@ module LaunchDarkly
|
|
39
43
|
# The number of seconds between flushes of the event buffer. Decreasing the flush interval means
|
40
44
|
# that the event buffer is less likely to reach capacity.
|
41
45
|
#
|
42
|
-
# @return [
|
46
|
+
# @return [Float] The configured number of seconds between flushes of the event buffer.
|
43
47
|
def flush_interval
|
44
48
|
@flush_interval
|
45
49
|
end
|
@@ -70,6 +74,22 @@ module LaunchDarkly
|
|
70
74
|
@store
|
71
75
|
end
|
72
76
|
|
77
|
+
#
|
78
|
+
# The read timeout for network connections in seconds.
|
79
|
+
#
|
80
|
+
# @return [Float] The read timeout in seconds.
|
81
|
+
def read_timeout
|
82
|
+
@read_timeout
|
83
|
+
end
|
84
|
+
|
85
|
+
#
|
86
|
+
# The connect timeout for network connections in seconds.
|
87
|
+
#
|
88
|
+
# @return [Float] The connect timeout in seconds.
|
89
|
+
def connect_timeout
|
90
|
+
@connect_timeout
|
91
|
+
end
|
92
|
+
|
73
93
|
#
|
74
94
|
# The default LaunchDarkly client configuration. This configuration sets reasonable defaults for most users.
|
75
95
|
#
|
@@ -94,6 +114,14 @@ module LaunchDarkly
|
|
94
114
|
10
|
95
115
|
end
|
96
116
|
|
117
|
+
def self.default_read_timeout
|
118
|
+
10
|
119
|
+
end
|
120
|
+
|
121
|
+
def self.default_connect_timeout
|
122
|
+
2
|
123
|
+
end
|
124
|
+
|
97
125
|
def self.default_logger
|
98
126
|
defined?(Rails) && Rails.respond_to?(:logger) ? Rails.logger : ::Logger.new($stdout)
|
99
127
|
end
|
data/lib/ldclient-rb/ldclient.rb
CHANGED
@@ -31,6 +31,7 @@ module LaunchDarkly
|
|
31
31
|
|
32
32
|
builder.adapter Faraday.default_adapter
|
33
33
|
end
|
34
|
+
@offline = false
|
34
35
|
|
35
36
|
@worker = create_worker()
|
36
37
|
end
|
@@ -52,6 +53,8 @@ module LaunchDarkly
|
|
52
53
|
req.headers['User-Agent'] = 'RubyClient/' + LaunchDarkly::VERSION
|
53
54
|
req.headers['Content-Type'] = 'application/json'
|
54
55
|
req.body = events.to_json
|
56
|
+
req.options.timeout = @config.read_timeout
|
57
|
+
req.options.open_timeout = @config.connect_timeout
|
55
58
|
end
|
56
59
|
if res.status != 200
|
57
60
|
@config.logger.error("[LDClient] Unexpected status code while processing events: #{res.status}")
|
@@ -98,6 +101,10 @@ module LaunchDarkly
|
|
98
101
|
# @return [Boolean] whether or not the flag should be enabled, or the default value if the flag is disabled on the LaunchDarkly control panel
|
99
102
|
def get_flag?(key, user, default=false)
|
100
103
|
begin
|
104
|
+
if @offline
|
105
|
+
return default
|
106
|
+
end
|
107
|
+
|
101
108
|
value = get_flag_int(key, user, default)
|
102
109
|
add_event({:kind => 'feature', :key => key, :user => user, :value => value})
|
103
110
|
return value
|
@@ -108,6 +115,9 @@ module LaunchDarkly
|
|
108
115
|
end
|
109
116
|
|
110
117
|
def add_event(event)
|
118
|
+
if @offline
|
119
|
+
return
|
120
|
+
end
|
111
121
|
if @queue.length() < @config.capacity
|
112
122
|
event[:creationDate] = (Time.now.to_f * 1000).to_i
|
113
123
|
@queue.push(event)
|
@@ -120,6 +130,27 @@ module LaunchDarkly
|
|
120
130
|
end
|
121
131
|
end
|
122
132
|
|
133
|
+
#
|
134
|
+
# Registers the user
|
135
|
+
#
|
136
|
+
# @param [Hash] The user to register
|
137
|
+
#
|
138
|
+
def identify(user)
|
139
|
+
add_event({:kind => 'identify', :key => user.key, :user => user})
|
140
|
+
end
|
141
|
+
|
142
|
+
def set_offline()
|
143
|
+
@offline = true
|
144
|
+
end
|
145
|
+
|
146
|
+
def set_online()
|
147
|
+
@offline = false
|
148
|
+
end
|
149
|
+
|
150
|
+
def is_offline?()
|
151
|
+
return @offline
|
152
|
+
end
|
153
|
+
|
123
154
|
#
|
124
155
|
# Tracks that a user performed an event
|
125
156
|
#
|
@@ -128,7 +159,7 @@ module LaunchDarkly
|
|
128
159
|
# @param data [Hash] A hash containing any additional data associated with the event
|
129
160
|
#
|
130
161
|
# @return [void]
|
131
|
-
def
|
162
|
+
def track(event_name, user, data)
|
132
163
|
add_event({:kind => 'custom', :key => event_name, :user => user, :data => data })
|
133
164
|
end
|
134
165
|
|
@@ -143,6 +174,8 @@ module LaunchDarkly
|
|
143
174
|
@client.get (@config.base_uri + '/api/eval/features/' + key) do |req|
|
144
175
|
req.headers['Authorization'] = 'api_key ' + @api_key
|
145
176
|
req.headers['User-Agent'] = 'RubyClient/' + LaunchDarkly::VERSION
|
177
|
+
req.options.timeout = @config.read_timeout
|
178
|
+
req.options.open_timeout = @config.connect_timeout
|
146
179
|
end
|
147
180
|
|
148
181
|
if res.status == 401
|
@@ -203,10 +236,10 @@ module LaunchDarkly
|
|
203
236
|
return false
|
204
237
|
end
|
205
238
|
u_value = user[:custom][attrib]
|
206
|
-
if u_value.is_a?
|
239
|
+
if u_value.is_a? Array
|
240
|
+
return ! ((target[:values] & u_value).empty?)
|
241
|
+
else
|
207
242
|
return target[:values].include? u_value
|
208
|
-
elsif u_value.is_a? Array
|
209
|
-
return ! ((target[:values] & u_value).empty?)
|
210
243
|
end
|
211
244
|
|
212
245
|
return false
|
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.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Catamorphic Co
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|