Class: AmplitudeExperiment::LocalEvaluationFetcher
- Inherits:
-
Object
- Object
- AmplitudeExperiment::LocalEvaluationFetcher
- Defined in:
- lib/experiment/local/fetcher.rb
Overview
LocalEvaluationFetcher Fetch local evaluation mode flag configs from the Experiment API server. These flag configs can be used to perform local evaluation.
Constant Summary collapse
- FLAG_CONFIG_TIMEOUT =
5000
Instance Method Summary collapse
-
#fetch ⇒ Hash
Fetch local evaluation mode flag configs from the Experiment API server.
-
#initialize(api_key, debug, server_url = 'https://api.lab.amplitude.com') ⇒ LocalEvaluationFetcher
constructor
A new instance of LocalEvaluationFetcher.
Constructor Details
#initialize(api_key, debug, server_url = 'https://api.lab.amplitude.com') ⇒ LocalEvaluationFetcher
Returns a new instance of LocalEvaluationFetcher.
8 9 10 11 12 13 |
# File 'lib/experiment/local/fetcher.rb', line 8 def initialize(api_key, debug, server_url = 'https://api.lab.amplitude.com') @api_key = api_key @uri = "#{server_url}/sdk/rules?eval_mode=local" @debug = debug @http = PersistentHttpClient.get(@uri, { read_timeout: FLAG_CONFIG_TIMEOUT }) end |
Instance Method Details
#fetch ⇒ Hash
Fetch local evaluation mode flag configs from the Experiment API server. These flag configs can be used to perform local evaluation.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/experiment/local/fetcher.rb', line 19 def fetch # fetch flag_configs headers = { 'Authorization' => "Api-Key #{@api_key}", 'Content-Type' => 'application/json;charset=utf-8' } request = Net::HTTP::Get.new(@uri, headers) response = @http.request(request) raise `flagConfigs - received error response: #{response.code}: #{response.body}` unless response.is_a?(Net::HTTPOK) flag_configs = parse(response.body) @logger.debug("[Experiment] Fetch flag configs: #{request.body}") if @debug flag_configs end |