Skip to content

Commit

Permalink
Merge pull request #70 from launchdarkly/jko/extra-flag-request-data
Browse files Browse the repository at this point in the history
Send prereqOf and version in flag request events
  • Loading branch information
jkodumal authored Aug 5, 2016
2 parents 457bdd1 + 6840126 commit 42228eb
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 23 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ gem install ldclient-rb
require 'ldclient-rb'
```

2. Create a new LDClient with your API key:
2. Create a new LDClient with your SDK key:

```ruby
client = LaunchDarkly::LDClient.new("your_api_key")
client = LaunchDarkly::LDClient.new("your_sdk_key")
```

### Ruby on Rails
Expand All @@ -36,7 +36,7 @@ client = LaunchDarkly::LDClient.new("your_api_key")
1. Initialize the launchdarkly client in `config/initializers/launchdarkly.rb`:

```ruby
Rails.configuration.ld_client = LaunchDarkly::LDClient.new("your_api_key")
Rails.configuration.ld_client = LaunchDarkly::LDClient.new("your_sdk_key")
```

2. You may want to include a function in your ApplicationController
Expand Down
2 changes: 1 addition & 1 deletion lib/ldclient-rb/evaluation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def eval_internal(flag, user, store, events)
begin
prereq_res = eval_internal(prereq_flag, user, store, events)
variation = get_variation(prereq_flag, prerequisite[:variation])
events.push(kind: "feature", key: prereq_flag[:key], value: prereq_res)
events.push(kind: "feature", key: prereq_flag[:key], value: prereq_res, version: prereq_flag[:version], prereqOf: flag[:key])
if prereq_res.nil? || prereq_res!= variation
failed_prereq = true
end
Expand Down
42 changes: 24 additions & 18 deletions lib/ldclient-rb/ldclient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,26 +114,32 @@ def variation(key, user, default)
sanitize_user(user)
feature = @store.get(key)

begin
res = evaluate(feature, user, @store)
if !res[:events].nil?
res[:events].each do |event|
@event_processor.add_event(event)
end
end
if !res[:value].nil?
@event_processor.add_event(kind: "feature", key: key, user: user, value: res[:value], default: default)
return res[:value]
else
@config.logger.debug("[LDClient] Result value is null in toggle")
@event_processor.add_event(kind: "feature", key: key, user: user, value: default, default: default)
return default
if feature.nil?
@config.logger.error("[LDClient] Unknown feature flag #{key}. Returning default value")
@event_processor.add_event(kind: "feature", key: key, value: default, default: default)
return default
end

begin
res = evaluate(feature, user, @store)
if !res[:events].nil?
res[:events].each do |event|
@event_processor.add_event(event)
end
rescue => exn
@config.logger.warn("[LDClient] Error evaluating feature flag: #{exn.inspect}. \nTrace: #{exn.backtrace}")
@event_processor.add_event(kind: "feature", key: key, user: user, value: default, default: default)
return default
end
if !res[:value].nil?
@event_processor.add_event(kind: "feature", key: key, user: user, value: res[:value], default: default, version: feature[:version])
return res[:value]
else
@config.logger.debug("[LDClient] Result value is null in toggle")
@event_processor.add_event(kind: "feature", key: key, user: user, value: default, default: default, version: feature[:version])
return default
end
rescue => exn
@config.logger.warn("[LDClient] Error evaluating feature flag: #{exn.inspect}. \nTrace: #{exn.backtrace}")
@event_processor.add_event(kind: "feature", key: key, user: user, value: default, default: default, version: feature[:version])
return default
end
end

#
Expand Down
2 changes: 1 addition & 1 deletion lib/ldclient-rb/requestor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def make_request(path)
end

if res.status == 401
@config.logger.error("[LDClient] Invalid API key")
@config.logger.error("[LDClient] Invalid SDK key")
return nil
end

Expand Down

0 comments on commit 42228eb

Please sign in to comment.