Class: Aptabase::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/aptabase/event.rb

Overview

An analytics event queued for delivery to Aptabase.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, timestamp: nil, session_id: nil, props: nil) ⇒ Event

Returns a new instance of Event.



11
12
13
14
15
16
# File 'lib/aptabase/event.rb', line 11

def initialize(name:, timestamp: nil, session_id: nil, props: nil)
  @name = name
  @timestamp = (timestamp || Time.now).utc
  @session_id = session_id || SecureRandom.uuid
  @props = props || {}
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/aptabase/event.rb', line 9

def name
  @name
end

#propsObject (readonly)

Returns the value of attribute props.



9
10
11
# File 'lib/aptabase/event.rb', line 9

def props
  @props
end

#session_idObject (readonly)

Returns the value of attribute session_id.



9
10
11
# File 'lib/aptabase/event.rb', line 9

def session_id
  @session_id
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



9
10
11
# File 'lib/aptabase/event.rb', line 9

def timestamp
  @timestamp
end

Instance Method Details

#to_h(system_props) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/aptabase/event.rb', line 18

def to_h(system_props)
  {
    "timestamp" => timestamp.iso8601(3),
    "sessionId" => session_id,
    "eventName" => name,
    "systemProps" => system_props.to_h,
    "props" => props
  }
end