Class: AmplitudeAPI::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/amplitude-api/event.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_id:, event_type:, event_properties: {}) ⇒ Event

Create a new Event

Parameters:

  • user_id (String)

    a user_id to associate with the event

  • event_type (String)

    a name for the event

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

    various properties to attach to the event



18
19
20
21
22
# File 'lib/amplitude-api/event.rb', line 18

def initialize(user_id: , event_type: , event_properties: {})
  self.user_id = user_id
  self.event_type = event_type
  self.event_properties = event_properties
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



11
12
13
# File 'lib/amplitude-api/event.rb', line 11

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



8
9
10
# File 'lib/amplitude-api/event.rb', line 8

def event_type
  @event_type
end

#user_idString

Returns the user_id to be sent to Amplitude.

Returns:

  • (String)

    the user_id to be sent to Amplitude



5
6
7
# File 'lib/amplitude-api/event.rb', line 5

def user_id
  @user_id
end

Instance Method Details

#==(other) ⇒ true, false

Compares to_hash for equality

Returns:

  • (true, false)


47
48
49
50
51
52
53
# File 'lib/amplitude-api/event.rb', line 47

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

#to_hashHash

Used for serialization and comparison

Returns:

  • (Hash)

    A serialized Event



36
37
38
39
40
41
42
# File 'lib/amplitude-api/event.rb', line 36

def to_hash
  {
    event_type: self.event_type,
    user_id: self.user_id,
    event_properties: self.event_properties
  }
end