ldclient-rb 0.5.0 → 0.6.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: fc6641c4985b42abedd6da85f32ed76818b06cec
4
- data.tar.gz: 9fe5a3fe32f171e31c5adc07dca2f7ef929a5e11
3
+ metadata.gz: f00287e6e246a9644375d4945034f25ee7ff7df2
4
+ data.tar.gz: 6899db722f33a0ca552998a0fd4a738576e353f2
5
5
  SHA512:
6
- metadata.gz: 788de2316e42990ae14abc3e7e681ce95f27862b450c571cc4dc63c503ffea9e0592795adedbd7e01186107274512514ca9c3fde4824d2dc16b595218b9d8c7f
7
- data.tar.gz: b0a5ddca1665c94a7bffd6467eac2cecde7777172db079ed2be16feeeadbdc3d86b748a6a1c44bb6b3b7c1e3b83c4c7428705f6c1ac4f2a3d166ac289b5c69b6
6
+ metadata.gz: 9642d199535a1805364241d7bfdef403355583ac0bedf9cee0df09b472baf67c8724a5f7c4293152ace3d7b970319e2bccd9b32761ebbbc230c9528bc0afd149
7
+ data.tar.gz: f6730d8bddbe1eda1cb271ecb4ba39e4d47050fc3d5119d1a7c037bdd4f3fd50a58b3031f6cb1de61cd7de2817def0ecd99baee1e8ef1e1a42289d76d677e18e
@@ -17,6 +17,10 @@ module LaunchDarkly
17
17
  # environment, or stdout otherwise.
18
18
  # @option opts [String] :base_uri ("https://app.launchdarkly.com") The base
19
19
  # URL for the LaunchDarkly server. Most users should use the default value.
20
+ # @option opts [String] :stream_uri ("https://stream.launchdarkly.com") The
21
+ # URL for the LaunchDarkly streaming events server. Most users should use the default value.
22
+ # @option opts [String] :events_uri ("https://events.launchdarkly.com") The
23
+ # URL for the LaunchDarkly events server. Most users should use the default value.
20
24
  # @option opts [Integer] :capacity (10000) The capacity of the events
21
25
  # buffer. The client buffers up to this many events in memory before
22
26
  # flushing. If the capacity is exceeded before the buffer is flushed,
@@ -35,6 +39,7 @@ module LaunchDarkly
35
39
  def initialize(opts = {})
36
40
  @base_uri = (opts[:base_uri] || Config.default_base_uri).chomp("/")
37
41
  @stream_uri = (opts[:stream_uri] || Config.default_stream_uri).chomp("/")
42
+ @events_uri = (opts[:events_uri] || Config.default_events_uri).chomp("/")
38
43
  @capacity = opts[:capacity] || Config.default_capacity
39
44
  @logger = opts[:logger] || Config.default_logger
40
45
  @store = opts[:store] || Config.default_store
@@ -59,6 +64,12 @@ module LaunchDarkly
59
64
  # @return [String] The configured base URL for the LaunchDarkly streaming server.
60
65
  attr_reader :stream_uri
61
66
 
67
+ #
68
+ # The base URL for the LaunchDarkly events server.
69
+ #
70
+ # @return [String] The configured base URL for the LaunchDarkly events server.
71
+ attr_reader :events_uri
72
+
62
73
  #
63
74
  # Whether streaming mode should be enabled. Streaming mode asynchronously updates
64
75
  # feature flags in real-time using server-sent events.
@@ -155,6 +166,10 @@ module LaunchDarkly
155
166
  "https://stream.launchdarkly.com"
156
167
  end
157
168
 
169
+ def self.default_events_uri
170
+ "https://events.launchdarkly.com"
171
+ end
172
+
158
173
  def self.default_store
159
174
  defined?(Rails) && Rails.respond_to?(:cache) ? Rails.cache : ThreadSafeMemoryStore.new
160
175
  end
@@ -16,6 +16,7 @@ module LaunchDarkly
16
16
  #
17
17
  #
18
18
  class LDClient
19
+ include Settings
19
20
  #
20
21
  # Creates a new client instance that connects to LaunchDarkly. A custom
21
22
  # configuration parameter can also supplied to specify advanced options,
@@ -60,7 +61,7 @@ module LaunchDarkly
60
61
 
61
62
  def post_flushed_events(events)
62
63
  res = log_timings("Flush events") do
63
- next @client.post (@config.base_uri + "/api/events/bulk") do |req|
64
+ next @client.post (@config.events_uri + "/bulk") do |req|
64
65
  req.headers["Authorization"] = "api_key " + @api_key
65
66
  req.headers["User-Agent"] = "RubyClient/" + LaunchDarkly::VERSION
66
67
  req.headers["Content-Type"] = "application/json"
@@ -146,7 +147,7 @@ module LaunchDarkly
146
147
  value = evaluate(feature, user)
147
148
  value = value.nil? ? default : value
148
149
 
149
- add_event(kind: "feature", key: key, user: user, value: value)
150
+ add_event(kind: "feature", key: key, user: user, value: value, default: default)
150
151
  LDNewRelic.annotate_transaction(key, value)
151
152
  return value
152
153
  rescue StandardError => error
@@ -0,0 +1,40 @@
1
+ module LaunchDarkly
2
+
3
+ #
4
+ # Module to manage user flag settings
5
+ #
6
+ module Settings
7
+ #
8
+ # Specifically enable or disable a feature flag for a user based
9
+ # on their key.
10
+ #
11
+ # @param user_key [String] the key of the user
12
+ # @param flag_key [String] the unique feature key for the feature flag, as shown
13
+ # on the LaunchDarkly dashboard
14
+ # @param setting [Boolean] the new setting, one of:
15
+ # true: the feature is always on
16
+ # false: the feature is never on
17
+ # nil: remove the setting (assign user per defined rules)
18
+ def update_user_flag_setting(user_key, flag_key, setting=nil)
19
+ unless user_key
20
+ @config.logger.error("[LDClient] Must specify user")
21
+ return
22
+ end
23
+
24
+ res = log_timings('update_user_flag_setting') do
25
+ @client.put("#{@config.base_uri}/api/users/#{user_key}/features/#{flag_key}") do |req|
26
+ req.headers['Authorization'] = "api_key #{@api_key}"
27
+ req.headers['User-Agent'] = "RubyClient/#{LaunchDarkly::VERSION}"
28
+ req.headers['Content-Type'] = 'application/json'
29
+ req.body = {setting: setting}.to_json
30
+ req.options.timeout = @config.read_timeout
31
+ req.options.open_timeout = @config.connect_timeout
32
+ end
33
+ end
34
+
35
+ unless res.success?
36
+ @config.logger.error("[LDClient] Failed to change setting, status: #{res.status}")
37
+ end
38
+ end
39
+ end
40
+ end
@@ -1,3 +1,3 @@
1
1
  module LaunchDarkly
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
data/lib/ldclient-rb.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "ldclient-rb/version"
2
+ require "ldclient-rb/settings"
2
3
  require "ldclient-rb/ldclient"
3
4
  require "ldclient-rb/store"
4
5
  require "ldclient-rb/config"
data/spec/config_spec.rb CHANGED
@@ -22,6 +22,16 @@ describe LaunchDarkly::Config do
22
22
  expect(subject.new.base_uri).to eq subject.default_base_uri
23
23
  end
24
24
  end
25
+ describe "@events_uri" do
26
+ it "can be read" do
27
+ expect(subject.new.events_uri).to eq subject.default_events_uri
28
+ end
29
+ end
30
+ describe "@stream_uri" do
31
+ it "can be read" do
32
+ expect(subject.new.stream_uri).to eq subject.default_stream_uri
33
+ end
34
+ end
25
35
  describe ".default_store" do
26
36
  it "uses Rails cache if it is available" do
27
37
  rails = instance_double("Rails", cache: :cache)
@@ -15,6 +15,21 @@ describe LaunchDarkly::LDClient do
15
15
  JSON.parse(data, symbolize_names: true)
16
16
  end
17
17
 
18
+ context 'user flag settings' do
19
+ describe '#update_user_flag_setting' do
20
+ it 'requires user' do
21
+ expect(client.instance_variable_get(:@config).logger).to receive(:error)
22
+ client.update_user_flag_setting(nil, feature[:key], true)
23
+ end
24
+
25
+ it 'puts the new setting' do
26
+ result = double('result', success?: true, status: 204)
27
+ expect(client.instance_variable_get(:@client)).to receive(:put).and_return(result)
28
+ client.update_user_flag_setting(user[:key], feature[:key], true)
29
+ end
30
+ end
31
+ end
32
+
18
33
  describe '#flush' do
19
34
  it "will flush and post all events" do
20
35
  client.instance_variable_get(:@queue).push "asdf"
@@ -34,7 +49,7 @@ describe LaunchDarkly::LDClient do
34
49
  let(:events) { ["event"] }
35
50
  it "will flush and post all events" do
36
51
  result = double("result", status: 200)
37
- expect(client.instance_variable_get(:@client)).to receive(:post).and_return result
52
+ expect(client.instance_variable_get(:@client)).to receive(:post).with(LaunchDarkly::Config.default_events_uri + "/bulk").and_return result
38
53
  expect(client.instance_variable_get(:@config).logger).to_not receive :error
39
54
  client.send(:post_flushed_events, events)
40
55
  expect(client.instance_variable_get(:@queue).length).to eq 0
@@ -61,6 +76,10 @@ describe LaunchDarkly::LDClient do
61
76
  result = client.toggle?(feature[:key], user, "default")
62
77
  expect(result).to eq "default"
63
78
  end
79
+ it "will specify the default value in the feature request event" do
80
+ expect(client).to receive(:add_event).with(hash_including(default: "default"))
81
+ result = client.toggle?(feature[:key], user, "default")
82
+ end
64
83
  it "requires user" do
65
84
  expect(client.instance_variable_get(:@config).logger).to receive(:error)
66
85
  result = client.toggle?(feature[:key], nil, "default")
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.5.0
4
+ version: 0.6.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-01-11 00:00:00.000000000 Z
11
+ date: 2016-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -201,6 +201,7 @@ files:
201
201
  - lib/ldclient-rb/config.rb
202
202
  - lib/ldclient-rb/ldclient.rb
203
203
  - lib/ldclient-rb/newrelic.rb
204
+ - lib/ldclient-rb/settings.rb
204
205
  - lib/ldclient-rb/store.rb
205
206
  - lib/ldclient-rb/stream.rb
206
207
  - lib/ldclient-rb/version.rb
@@ -233,7 +234,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
233
234
  version: '0'
234
235
  requirements: []
235
236
  rubyforge_project:
236
- rubygems_version: 2.5.0
237
+ rubygems_version: 2.0.14
237
238
  signing_key:
238
239
  specification_version: 4
239
240
  summary: LaunchDarkly SDK for Ruby