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.2.3-java lib/splitclient-rb/engine/api/events.rb
splitclient-rb-7.2.3 lib/splitclient-rb/engine/api/events.rb
splitclient-rb-7.2.3.pre.rc2-java lib/splitclient-rb/engine/api/events.rb
splitclient-rb-7.2.3.pre.rc2 lib/splitclient-rb/engine/api/events.rb
splitclient-rb-7.2.3.pre.rc1-java lib/splitclient-rb/engine/api/events.rb
splitclient-rb-7.2.3.pre.rc1 lib/splitclient-rb/engine/api/events.rb
splitclient-rb-7.2.2-java lib/splitclient-rb/engine/api/events.rb
splitclient-rb-7.2.2 lib/splitclient-rb/engine/api/events.rb
splitclient-rb-7.2.2.pre.rc1-java lib/splitclient-rb/engine/api/events.rb
splitclient-rb-7.2.2.pre.rc1 lib/splitclient-rb/engine/api/events.rb
splitclient-rb-7.2.1-java lib/splitclient-rb/engine/api/events.rb
splitclient-rb-7.2.1 lib/splitclient-rb/engine/api/events.rb
splitclient-rb-7.2.1.pre.rc1-java lib/splitclient-rb/engine/api/events.rb
splitclient-rb-7.2.1.pre.rc1 lib/splitclient-rb/engine/api/events.rb
splitclient-rb-7.2.0.pre.rc1-java lib/splitclient-rb/engine/api/events.rb
splitclient-rb-7.2.0.pre.rc1 lib/splitclient-rb/engine/api/events.rb
splitclient-rb-7.2.0-java lib/splitclient-rb/engine/api/events.rb
splitclient-rb-7.2.0 lib/splitclient-rb/engine/api/events.rb
splitclient-rb-7.1.4.pre.rc19-java lib/splitclient-rb/engine/api/events.rb
splitclient-rb-7.1.4.pre.rc19 lib/splitclient-rb/engine/api/events.rb