class Projector::Event

Internally represents an event being sent to the Projector API. @api private

Public Class Methods

new(params) click to toggle source

@param [Hash] params a hash of properties to send with the event @option params [String] id (SecureRandom.uuid) the unique identifier for this event in your system @option params [Number] event_time ((Time.now.to_f * 1000).to_i) the ms since epoch for this event @option params [Hash] event_context data providing context for the event. Used in delivery rules, templates, and more at Projector. @option params [Hash] target containing either an end_users or tags key and a corresponding hash of values.

# File lib/projector/event.rb, line 13
def initialize(params)
  @params = params.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
end

Public Instance Methods

to_hash() click to toggle source

Serializes the Event object to the correct Projector-defined hash format. @return [Hash]

# File lib/projector/event.rb, line 19
def to_hash
  overrides = {
    id: @params[:id] ? @params[:id].to_s : SecureRandom.uuid,
    event_time: ((@params[:event_time].instance_of?(Time) ? @params[:event_time] : Time.now).to_f * 1000).to_i
  }
  @params.merge overrides
end