Class: AmplitudeAPI::Event

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

Overview

AmplitudeAPI::Event

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_id: '', event_type: '', event_properties: {}, user_properties: {}, time: nil) ⇒ Event

Create a new Event

Parameters:

  • user_id (String) (defaults to: '')

    a user_id to associate with the event

  • event_type (String) (defaults to: '')

    a name for the event

  • event_properties (Hash) (defaults to: {})

    various properties to attach to the event

  • Time (Time)

    that the event occurred (defaults to now)



26
27
28
29
30
31
32
# File 'lib/amplitude_api/event.rb', line 26

def initialize(user_id: '', event_type: '', event_properties: {}, user_properties: {}, time: nil)
  self.user_id = user_id
  self.event_type = event_type
  self.event_properties = event_properties
  self.user_properties = user_properties
  self.time = time
end

Instance Attribute Details

#event_propertiesString

Returns the event_properties to be attached to the Amplitude Event.

Returns:

  • (String)

    the event_properties to be attached to the Amplitude Event



12
13
14
# File 'lib/amplitude_api/event.rb', line 12

def event_properties
  @event_properties
end

#event_typeString

Returns the event_type to be sent to Amplitude.

Returns:

  • (String)

    the event_type to be sent to Amplitude



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

def event_type
  @event_type
end

#timeTime

Returns Time that the event occurred (defaults to now).

Returns:

  • (Time)

    Time that the event occurred (defaults to now)



18
19
20
# File 'lib/amplitude_api/event.rb', line 18

def time
  @time
end

#user_idString

Returns the user_id to be sent to Amplitude.

Returns:

  • (String)

    the user_id to be sent to Amplitude



6
7
8
# File 'lib/amplitude_api/event.rb', line 6

def user_id
  @user_id
end

#user_propertiesString

Returns the user_properties to be passed for the user.

Returns:

  • (String)

    the user_properties to be passed for the user



15
16
17
# File 'lib/amplitude_api/event.rb', line 15

def user_properties
  @user_properties
end

Instance Method Details

#==(other) ⇒ true, false

Compares +to_hash+ for equality

Returns:

  • (true, false)


59
60
61
62
63
64
65
# File 'lib/amplitude_api/event.rb', line 59

def ==(other)
  if other.respond_to?(:to_hash)
    to_hash == other.to_hash
  else
    false
  end
end

#to_hashHash

Used for serialization and comparison

Returns:

  • (Hash)

    A serialized Event



46
47
48
49
50
51
52
53
54
# File 'lib/amplitude_api/event.rb', line 46

def to_hash
  serialized_event = {}
  serialized_event[:event_type] = event_type
  serialized_event[:user_id] = user_id
  serialized_event[:event_properties] = event_properties
  serialized_event[:user_properties] = user_properties
  serialized_event[:time] = formatted_time if time
  serialized_event
end