Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/ldclient-rb/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class Config
# environment, or stdout otherwise.
# @option opts [String] :base_uri ("https://app.launchdarkly.com") The base
# URL for the LaunchDarkly server. Most users should use the default value.
# @option opts [String] :stream_uri ("https://stream.launchdarkly.com") The
# URL for the LaunchDarkly streaming events server. Most users should use the default value.
# @option opts [String] :events_uri ("https://events.launchdarkly.com") The
# URL for the LaunchDarkly events server. Most users should use the default value.
# @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,
Expand All @@ -35,6 +39,7 @@ class Config
def initialize(opts = {})
@base_uri = (opts[:base_uri] || Config.default_base_uri).chomp("/")
@stream_uri = (opts[:stream_uri] || Config.default_stream_uri).chomp("/")
@events_uri = (opts[:events_uri] || Config.default_events_uri).chomp("/")
@capacity = opts[:capacity] || Config.default_capacity
@logger = opts[:logger] || Config.default_logger
@store = opts[:store] || Config.default_store
Expand All @@ -59,6 +64,12 @@ def initialize(opts = {})
# @return [String] The configured base URL for the LaunchDarkly streaming server.
attr_reader :stream_uri

#
# The base URL for the LaunchDarkly events server.
#
# @return [String] The configured base URL for the LaunchDarkly events server.
attr_reader :events_uri

#
# Whether streaming mode should be enabled. Streaming mode asynchronously updates
# feature flags in real-time using server-sent events.
Expand Down Expand Up @@ -155,6 +166,10 @@ def self.default_stream_uri
"https://stream.launchdarkly.com"
end

def self.default_events_uri
"https://events.launchdarkly.com"
end

def self.default_store
defined?(Rails) && Rails.respond_to?(:cache) ? Rails.cache : ThreadSafeMemoryStore.new
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ldclient-rb/ldclient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def flush

def post_flushed_events(events)
res = log_timings("Flush events") do
next @client.post (@config.base_uri + "/api/events/bulk") do |req|
next @client.post (@config.events_uri + "/bulk") do |req|
req.headers["Authorization"] = "api_key " + @api_key
req.headers["User-Agent"] = "RubyClient/" + LaunchDarkly::VERSION
req.headers["Content-Type"] = "application/json"
Expand Down
10 changes: 10 additions & 0 deletions spec/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@
expect(subject.new.base_uri).to eq subject.default_base_uri
end
end
describe "@events_uri" do
it "can be read" do
expect(subject.new.events_uri).to eq subject.default_events_uri
end
end
describe "@stream_uri" do
it "can be read" do
expect(subject.new.stream_uri).to eq subject.default_stream_uri
end
end
describe ".default_store" do
it "uses Rails cache if it is available" do
rails = instance_double("Rails", cache: :cache)
Expand Down
2 changes: 1 addition & 1 deletion spec/ldclient_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
let(:events) { ["event"] }
it "will flush and post all events" do
result = double("result", status: 200)
expect(client.instance_variable_get(:@client)).to receive(:post).and_return result
expect(client.instance_variable_get(:@client)).to receive(:post).with(LaunchDarkly::Config.default_events_uri + "/bulk").and_return result
expect(client.instance_variable_get(:@config).logger).to_not receive :error
client.send(:post_flushed_events, events)
expect(client.instance_variable_get(:@queue).length).to eq 0
Expand Down