Class: LaunchDarkly::LDClient
- Inherits:
-
Object
- Object
- LaunchDarkly::LDClient
- Defined in:
- lib/ldclient-rb/ldclient.rb
Constant Summary collapse
- LONG_SCALE =
Float(0xFFFFFFFFFFFFFFF)
Instance Method Summary collapse
- #get_flag?(key, user, default = false) ⇒ Boolean
-
#initialize(api_key, config = Config.default) ⇒ LDClient
constructor
A new instance of LDClient.
Constructor Details
#initialize(api_key, config = Config.default) ⇒ LDClient
Returns a new instance of LDClient.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/ldclient-rb/ldclient.rb', line 10 def initialize(api_key, config = Config.default) store = ThreadSafeMemoryStore.new @api_key = api_key @config = config @client = Faraday.new do |builder| builder.use :http_cache, store: store builder.adapter Faraday.default_adapter end end |
Instance Method Details
#get_flag?(key, user, default = false) ⇒ Boolean
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ldclient-rb/ldclient.rb', line 21 def get_flag?(key, user, default=false) unless user return default end res = @client.get (@config.base_uri + '/api/eval/features/' + key) do |req| req.headers['Authorization'] = 'api_key ' + @api_key req.headers['User-Agent'] = 'RubyClient/' + LaunchDarkly::VERSION end feature = JSON.parse(res.body) val = evaluate(feature, user) val == nil ? default : val end |