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 synchronously.
-
#fetch_async(user) {|User, Hash| ... } ⇒ Object
Fetch all variants for a user asynchronously.
-
#fetch_async_v2(user) {|User, Hash| ... } ⇒ Object
Fetch all variants for a user asynchronously.
-
#fetch_v2(user) ⇒ Hash
Fetch all variants for a user synchronously.
-
#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 |
# File 'lib/experiment/remote/client.rb', line 13 def initialize(api_key, config = nil) @api_key = api_key @config = config || RemoteEvaluationConfig.new @logger = @config.logger endpoint = "#{@config.server_url}/sdk/v2/vardata?v=0" @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 synchronously.
This method will automatically retry if configured (default).
27 28 29 30 31 32 |
# File 'lib/experiment/remote/client.rb', line 27 def fetch(user) AmplitudeExperiment.filter_default_variants(fetch_internal(user)) rescue StandardError => e @logger.error("[Experiment] Failed to fetch variants: #{e.message}") {} end |
#fetch_async(user) {|User, Hash| ... } ⇒ Object
Fetch all variants for a user asynchronously.
This method will automatically retry if configured (default).
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/experiment/remote/client.rb', line 52 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.message}") yield(user, {}) unless callback.nil? {} end end |
#fetch_async_v2(user) {|User, Hash| ... } ⇒ Object
Fetch all variants for a user asynchronously. This function differs from fetch as it will return a default variant object if the flag was evaluated but the user was not assigned (i.e. off).
This method will automatically retry if configured (default).
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/experiment/remote/client.rb', line 70 def fetch_async_v2(user, &callback) Thread.new do variants = fetch_internal(user) yield(user, filter_default_variants(variants)) unless callback.nil? variants rescue StandardError => e @logger.error("[Experiment] Failed to fetch variants: #{e.message}") yield(user, {}) unless callback.nil? {} end end |
#fetch_v2(user) ⇒ Hash
Fetch all variants for a user synchronously.
This method will automatically retry if configured (default). This function differs from fetch as it will return a default variant object if the flag was evaluated but the user was not assigned (i.e. off).
40 41 42 43 44 45 |
# File 'lib/experiment/remote/client.rb', line 40 def fetch_v2(user) fetch_internal(user) rescue StandardError => e @logger.error("[Experiment] Failed to fetch variants: #{e.message}") {} end |