Sha256: d2968a04b603d11439f30dd6abc26af6381bc5a1035765518152fa606790a766
Contents?: true
Size: 1.97 KB
Versions: 28
Compression:
Stored size: 1.97 KB
Contents
# frozen_string_literal: true module SplitIoClient module Api # Retrieves split definitions from the Split Backend class Splits < Client METRICS_PREFIX = 'splitChangeFetcher' def initialize(api_key, metrics) @api_key = api_key @metrics = metrics end def since(since) start = Time.now response = get_api("#{SplitIoClient.configuration.base_uri}/splitChanges", @api_key, since: since) if response.success? result = splits_with_segment_names(response.body) @metrics.count(METRICS_PREFIX + '.status.' + response.status.to_s, 1) unless result[:splits].empty? SplitLogger.log_if_debug("#{result[:splits].length} splits retrieved. since=#{since}") end SplitLogger.log_if_transport(result.to_s) latency = (Time.now - start) * 1000.0 @metrics.time(METRICS_PREFIX + '.time', latency) result else @metrics.count(METRICS_PREFIX + '.status.' + response.status.to_s, 1) SplitLogger.log_error("Unexpected status code while fetching splits: #{response.status}. " \ 'Check your API key and base URI') raise 'Split SDK failed to connect to backend to fetch split definitions' end end private def splits_with_segment_names(splits_json) parsed_splits = JSON.parse(splits_json, symbolize_names: true) parsed_splits[:segment_names] = parsed_splits[:splits].each_with_object(Set.new) do |split, splits| splits << segment_names(split) end.flatten parsed_splits end def segment_names(split) split[:conditions].each_with_object(Set.new) do |condition, names| condition[:matcherGroup][:matchers].each do |matcher| next if matcher[:userDefinedSegmentMatcherData].nil? names << matcher[:userDefinedSegmentMatcherData][:segmentName] end end end end end end
Version data entries
28 entries across 28 versions & 1 rubygems