Class: SplitIoClient::Api::Events

Inherits:
Client
  • Object
show all
Defined in:
lib/splitclient-rb/engine/api/events.rb

Constant Summary

Constants inherited from Client

Client::RUBY_ENCODING

Instance Method Summary collapse

Methods inherited from Client

#get_api, #post_api

Constructor Details

#initialize(api_key, config) ⇒ Events

Returns a new instance of Events.



6
7
8
9
# File 'lib/splitclient-rb/engine/api/events.rb', line 6

def initialize(api_key, config)
  super(config)
  @api_key = api_key
end

Instance Method Details

#post(events) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/splitclient-rb/engine/api/events.rb', line 11

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