diff --git a/lib/ldclient-rb/config.rb b/lib/ldclient-rb/config.rb index 764b5ecb..edcde25d 100644 --- a/lib/ldclient-rb/config.rb +++ b/lib/ldclient-rb/config.rb @@ -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, @@ -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 @@ -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. @@ -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 diff --git a/lib/ldclient-rb/ldclient.rb b/lib/ldclient-rb/ldclient.rb index 9bb21697..ff280d44 100644 --- a/lib/ldclient-rb/ldclient.rb +++ b/lib/ldclient-rb/ldclient.rb @@ -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" diff --git a/spec/config_spec.rb b/spec/config_spec.rb index da630638..fda9f23c 100644 --- a/spec/config_spec.rb +++ b/spec/config_spec.rb @@ -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) diff --git a/spec/ldclient_spec.rb b/spec/ldclient_spec.rb index 7dd28b60..71c149e6 100644 --- a/spec/ldclient_spec.rb +++ b/spec/ldclient_spec.rb @@ -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