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
6 changes: 4 additions & 2 deletions ldclient-rb.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency "faraday-http-cache", "~> 1.3.0"
spec.add_runtime_dependency "thread_safe", "~> 0.3"
spec.add_runtime_dependency "net-http-persistent", "~> 2.9"
spec.add_runtime_dependency "concurrent-ruby", "~> 1.0.0"
spec.add_runtime_dependency "concurrent-ruby", "~> 1.0.4"
spec.add_runtime_dependency "hashdiff", "~> 0.2"
spec.add_runtime_dependency "ld-celluloid-eventsource", "~> 0.5"
spec.add_runtime_dependency "ld-celluloid-eventsource", "~> 0.8.1"
spec.add_runtime_dependency "nio4r", "~> 1.1" # for maximum ruby version compatibility.

spec.add_runtime_dependency "waitutil", "0.2"
end
2 changes: 1 addition & 1 deletion lib/ldclient-rb/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Config
# @option opts [Boolean] :offline (false) Whether the client should be initialized in
# offline mode. In offline mode, default values are returned for all flags and no
# remote network requests are made.
# @option opts [Float] :poll_interval (30) The number of seconds between polls for flag updates
# @option opts [Float] :poll_interval (1) The number of seconds between polls for flag updates
# if streaming is off.
# @option opts [Boolean] :stream (true) Whether or not the streaming API should be used to receive flag updates.
#
Expand Down
5 changes: 4 additions & 1 deletion lib/ldclient-rb/requestor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ def request_flag(key)
end

def make_request(path)
res = @client.get (@config.base_uri + path) do |req|
uri = @config.base_uri + path
res = @client.get (uri) do |req|
req.headers["Authorization"] = @sdk_key
req.headers["User-Agent"] = "RubyClient/" + LaunchDarkly::VERSION
req.options.timeout = @config.read_timeout
req.options.open_timeout = @config.connect_timeout
end

@config.logger.debug("[LDClient] Got response from uri: #{uri}\n\tstatus code: #{res.status}\n\theaders: #{res.headers}\n\tbody: #{res.body}")

if res.status == 401
@config.logger.error("[LDClient] Invalid SDK key")
return nil
Expand Down
7 changes: 2 additions & 5 deletions lib/ldclient-rb/stream.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "concurrent/atomics"
require "json"
require "celluloid/eventsource"
require "ld_celluloid_eventsource/eventsource"

module LaunchDarkly
PUT = :put
Expand Down Expand Up @@ -40,14 +40,11 @@ def start
conn.on(DELETE) { |message| process_message(message, DELETE) }
conn.on(INDIRECT_PUT) { |message| process_message(message, INDIRECT_PUT) }
conn.on(INDIRECT_PATCH) { |message| process_message(message, INDIRECT_PATCH) }
conn.on_error do |message|
@config.logger.error("[LDClient] Error connecting to stream. Status code: #{message[:status_code]}")
end
end
end

def process_message(message, method)
@config.logger.debug("[LDClient] Stream received #{method} message")
@config.logger.debug("[LDClient] Stream received #{method} message: #{message.data}")
if method == PUT
message = JSON.parse(message.data, symbolize_names: true)
@store.init(message)
Expand Down