Class: AmplitudeExperiment::RemoteEvaluationClient
- Inherits:
-
Object
- Object
- AmplitudeExperiment::RemoteEvaluationClient
- Defined in:
- lib/experiment/remote/client.rb
Overview
Main client for fetching variant data.
Instance Method Summary collapse
-
#fetch(user) ⇒ Hash
Fetch all variants for a user synchronous.
-
#fetch_async(user) {|User, Hash| ... } ⇒ Object
Fetch all variants for a user asynchronous.
-
#initialize(api_key, config = nil) ⇒ RemoteEvaluationClient
constructor
Creates a new Experiment Client instance.
Constructor Details
#initialize(api_key, config = nil) ⇒ RemoteEvaluationClient
Creates a new Experiment Client instance.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/experiment/remote/client.rb', line 13 def initialize(api_key, config = nil) @api_key = api_key @config = config || RemoteEvaluationConfig.new @logger = Logger.new($stdout) @logger.level = if @config.debug Logger::DEBUG else Logger::INFO end endpoint = "#{@config.server_url}/sdk/vardata" @uri = URI(endpoint) raise ArgumentError, 'Experiment API key is empty' if @api_key.nil? || @api_key.empty? end |
Instance Method Details
#fetch(user) ⇒ Hash
Fetch all variants for a user synchronous.
This method will automatically retry if configured (default).
32 33 34 35 36 37 |
# File 'lib/experiment/remote/client.rb', line 32 def fetch(user) fetch_internal(user) rescue StandardError => e @logger.error("[Experiment] Failed to fetch variants: #{e.}") {} end |
#fetch_async(user) {|User, Hash| ... } ⇒ Object
Fetch all variants for a user asynchronous.
This method will automatically retry if configured (default).
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/experiment/remote/client.rb', line 44 def fetch_async(user, &callback) Thread.new do variants = fetch_internal(user) yield(user, variants) unless callback.nil? variants rescue StandardError => e @logger.error("[Experiment] Failed to fetch variants: #{e.}") yield(user, {}) unless callback.nil? {} end end |