Sha256: 1ea5cfffbe2187102e068882699f047bba52e240e354ac79b4862fc6b37c1959

Contents?: true

Size: 1.3 KB

Versions: 146

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

module SplitIoClient
  module Api
    class Events < Client
      def initialize(api_key, config)
        super(config)
        @api_key = api_key
      end

      def post(events)
        if events.empty?
          @config.split_logger.log_if_debug('No events to report')
          return
        end

        events.each_slice(@config.events_queue_size) do |events_slice|
          response = post_api(
            "#{@config.events_uri}/events/bulk",
            @api_key,
            events_slice.map { |event| formatted_event(event[:e]) }
          )

          if response.success?
            @config.split_logger.log_if_debug("Events reported: #{events_slice.size}")
          else
            @config.logger.error("Unexpected status code while posting events: #{response.status}." \
            ' - Check your API key and base URI')
            raise 'Split SDK failed to connect to backend to post events'
          end
        end
      end

      private

      def formatted_event(event)
        {
          key: event[:key],
          trafficTypeName: event[:trafficTypeName],
          eventTypeId: event[:eventTypeId],
          value: event[:value].to_f,
          timestamp: event[:timestamp].to_i,
          properties: event[:properties]
        }
      end
    end
  end
end

Version data entries

146 entries across 146 versions & 1 rubygems

Version Path
splitclient-rb-7.1.4.pre.rc18-java lib/splitclient-rb/engine/api/events.rb
splitclient-rb-7.1.4.pre.rc18 lib/splitclient-rb/engine/api/events.rb
splitclient-rb-7.1.4.pre.rc17-java lib/splitclient-rb/engine/api/events.rb
splitclient-rb-7.1.4.pre.rc17 lib/splitclient-rb/engine/api/events.rb
splitclient-rb-7.1.4.pre.rc16-java lib/splitclient-rb/engine/api/events.rb
splitclient-rb-7.1.4.pre.rc16 lib/splitclient-rb/engine/api/events.rb
splitclient-rb-7.1.4.pre.rc15-java lib/splitclient-rb/engine/api/events.rb
splitclient-rb-7.1.4.pre.rc15 lib/splitclient-rb/engine/api/events.rb
splitclient-rb-7.1.4.pre.rc14-java lib/splitclient-rb/engine/api/events.rb
splitclient-rb-7.1.4.pre.rc14 lib/splitclient-rb/engine/api/events.rb
splitclient-rb-7.1.4.pre.rc13-java lib/splitclient-rb/engine/api/events.rb
splitclient-rb-7.1.4.pre.rc13 lib/splitclient-rb/engine/api/events.rb
splitclient-rb-7.1.4.pre.rc12-java lib/splitclient-rb/engine/api/events.rb
splitclient-rb-7.1.4.pre.rc12 lib/splitclient-rb/engine/api/events.rb
splitclient-rb-7.1.4.pre.rc11-java lib/splitclient-rb/engine/api/events.rb
splitclient-rb-7.1.4.pre.rc11 lib/splitclient-rb/engine/api/events.rb
splitclient-rb-7.1.4.pre.rc10-java lib/splitclient-rb/engine/api/events.rb
splitclient-rb-7.1.4.pre.rc10 lib/splitclient-rb/engine/api/events.rb
splitclient-rb-7.1.4.pre.rc9-java lib/splitclient-rb/engine/api/events.rb
splitclient-rb-7.1.4.pre.rc9 lib/splitclient-rb/engine/api/events.rb