Sha256: 2b8c8d9d0c82313d29a4d117c2a92bd1a9ab3c57d86f9419eb6206a15297d0b6
Contents?: true
Size: 1.44 KB
Versions: 18
Compression:
Stored size: 1.44 KB
Contents
module SplitIoClient module Api class Events < Client def initialize(api_key, events) @api_key = api_key @events = events end def post if @events.empty? SplitIoClient.configuration.logger.debug('No events to report') if SplitIoClient.configuration.debug_enabled return end @events.each_slice(SplitIoClient.configuration.events_queue_size) do |event_slice| result = post_api( "#{SplitIoClient.configuration.events_uri}/events/bulk", @api_key, event_slice.map { |event| formatted_event(event[:e]) }, 'SplitSDKMachineIP' => event_slice[0][:m][:i], 'SplitSDKMachineName' => event_slice[0][:m][:n], 'SplitSDKVersion' => event_slice[0][:m][:s] ) if (200..299).include? result.status SplitIoClient.configuration.logger.debug("Events reported: #{event_slice.size}") if SplitIoClient.configuration.debug_enabled else SplitIoClient.configuration.logger.error("Unexpected status code while posting events: #{result.status}") 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 } end end end end
Version data entries
18 entries across 18 versions & 1 rubygems