Class: SplitIoClient::Api::Splits
- Defined in:
- lib/splitclient-rb/engine/api/splits.rb
Overview
Retrieves split definitions from the Split Backend
Instance Method Summary collapse
-
#initialize(api_key, config, telemetry_runtime_producer) ⇒ Splits
constructor
A new instance of Splits.
- #since(since, fetch_options = { cache_control_headers: false, till: nil, sets: nil }) ⇒ Object
Methods inherited from Client
Constructor Details
#initialize(api_key, config, telemetry_runtime_producer) ⇒ Splits
Returns a new instance of Splits.
7 8 9 10 11 12 |
# File 'lib/splitclient-rb/engine/api/splits.rb', line 7 def initialize(api_key, config, telemetry_runtime_producer) super(config) @api_key = api_key @telemetry_runtime_producer = telemetry_runtime_producer @flag_sets_filter = @config.flag_sets_filter end |
Instance Method Details
#since(since, fetch_options = { cache_control_headers: false, till: nil, sets: nil }) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/splitclient-rb/engine/api/splits.rb', line 14 def since(since, = { cache_control_headers: false, till: nil, sets: nil }) start = Time.now params = { since: since } params[:till] = [:till] unless [:till].nil? params[:sets] = @flag_sets_filter.join(",") unless @flag_sets_filter.empty? @config.logger.debug("Fetching from splitChanges with #{params}: ") response = get_api("#{@config.base_uri}/splitChanges", @api_key, params, [:cache_control_headers]) if response.status == 414 @config.logger.error("Error fetching feature flags; the amount of flag sets provided are too big, causing uri length error.") raise ApiException.new response.body, 414 end if response.success? result = splits_with_segment_names(response.body) unless result[:splits].empty? @config.split_logger.log_if_debug("#{result[:splits].length} feature flags retrieved. since=#{since}") end @config.split_logger.log_if_transport("Feature flag changes response: #{result.to_s}") bucket = BinarySearchLatencyTracker.get_bucket((Time.now - start) * 1000.0) @telemetry_runtime_producer.record_sync_latency(Telemetry::Domain::Constants::SPLIT_SYNC, bucket) @telemetry_runtime_producer.record_successful_sync(Telemetry::Domain::Constants::SPLIT_SYNC, (Time.now.to_f * 1000.0).to_i) result else @telemetry_runtime_producer.record_sync_error(Telemetry::Domain::Constants::SPLIT_SYNC, response.status) @config.logger.error("Unexpected status code while fetching feature flags: #{response.status}. " \ 'Check your API key and base URI') raise 'Split SDK failed to connect to backend to fetch feature flags definitions' end end |