Sha256: 2cfc7c1bc440c168c2ca97998e4bc72c97503a742eb2d7ba24f013471f1cae0a

Contents?: true

Size: 1.67 KB

Versions: 48

Compression:

Stored size: 1.67 KB

Contents

module SplitIoClient
  module Cache
    module Repositories
      # Repository which forwards events interface to the selected adapter
      class EventsRepository < Repository
        extend Forwardable
        def_delegators :@repository, :add, :clear, :batch

        def initialize(config, api_key, telemetry_runtime_producer)
          super(config)
          @repository = case @config.events_adapter.class.to_s
          when 'SplitIoClient::Cache::Adapters::MemoryAdapter'
            Repositories::Events::MemoryRepository.new(@config, telemetry_runtime_producer)
          when 'SplitIoClient::Cache::Adapters::RedisAdapter'
            Repositories::Events::RedisRepository.new(@config)
          end

          @api_key = api_key
          @telemetry_runtime_producer = telemetry_runtime_producer
        end

        def post_events
          events_api.post(self.clear)
        rescue StandardError => e
          @config.log_found_exception(__method__.to_s, e)
        end

        protected

        def metadata
          {
            s: "#{@config.language}-#{@config.version}",
            i: @config.machine_ip,
            n: @config.machine_name
          }
        end

        def event(key, traffic_type, event_type, time, value, properties)
          {
            key: key,
            trafficTypeName: traffic_type,
            eventTypeId: event_type,
            value: value,
            timestamp: time,
            properties: properties
          }.reject { |_, v| v.nil? }
        end

        private

        def events_api
          @events_api ||= SplitIoClient::Api::Events.new(@api_key, @config, @telemetry_runtime_producer)
        end
      end
    end
  end
end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
splitclient-rb-8.3.2.pre.rc1-java lib/splitclient-rb/cache/repositories/events_repository.rb
splitclient-rb-8.3.2.pre.rc1 lib/splitclient-rb/cache/repositories/events_repository.rb
splitclient-rb-8.3.1-java lib/splitclient-rb/cache/repositories/events_repository.rb
splitclient-rb-8.3.1 lib/splitclient-rb/cache/repositories/events_repository.rb
splitclient-rb-8.3.1.pre.rc1-java lib/splitclient-rb/cache/repositories/events_repository.rb
splitclient-rb-8.3.1.pre.rc1 lib/splitclient-rb/cache/repositories/events_repository.rb
splitclient-rb-8.3.0-java lib/splitclient-rb/cache/repositories/events_repository.rb
splitclient-rb-8.3.0 lib/splitclient-rb/cache/repositories/events_repository.rb
splitclient-rb-8.3.0.pre.rc3-java lib/splitclient-rb/cache/repositories/events_repository.rb
splitclient-rb-8.3.0.pre.rc3 lib/splitclient-rb/cache/repositories/events_repository.rb
splitclient-rb-8.3.0.pre.rc2-java lib/splitclient-rb/cache/repositories/events_repository.rb
splitclient-rb-8.3.0.pre.rc2 lib/splitclient-rb/cache/repositories/events_repository.rb
splitclient-rb-8.3.0.pre.rc1-java lib/splitclient-rb/cache/repositories/events_repository.rb
splitclient-rb-8.3.0.pre.rc1 lib/splitclient-rb/cache/repositories/events_repository.rb
splitclient-rb-8.2.0-java lib/splitclient-rb/cache/repositories/events_repository.rb
splitclient-rb-8.2.0 lib/splitclient-rb/cache/repositories/events_repository.rb
splitclient-rb-8.1.3.pre.rc4-java lib/splitclient-rb/cache/repositories/events_repository.rb
splitclient-rb-8.1.3.pre.rc4 lib/splitclient-rb/cache/repositories/events_repository.rb
splitclient-rb-8.1.3.pre.rc3-java lib/splitclient-rb/cache/repositories/events_repository.rb
splitclient-rb-8.1.3.pre.rc3 lib/splitclient-rb/cache/repositories/events_repository.rb