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(options = {}) ⇒ Event

Create a new Event



30
31
32
33
34
35
36
37
# File 'lib/amplitude_api/event.rb', line 30

def initialize(options = {})
  self.user_id = options.fetch(:user_id, '')
  self.event_type = options.fetch(:event_type, '')
  self.event_properties = options.fetch(:event_properties, {})
  self.user_properties = options.fetch(:user_properties, {})
  self.time = options[:time]
  self.ip = options.fetch(:ip, '')
end

Instance Attribute Details

#event_propertiesString



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

def event_properties
  @event_properties
end

#event_typeString



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

def event_type
  @event_type
end

#ipString



21
22
23
# File 'lib/amplitude_api/event.rb', line 21

def ip
  @ip
end

#timeTime



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

def time
  @time
end

#user_idString



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

def user_id
  @user_id
end

#user_propertiesString



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



65
66
67
68
69
70
71
# File 'lib/amplitude_api/event.rb', line 65

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

#to_hashHash

Used for serialization and comparison



51
52
53
54
55
56
57
58
59
60
# File 'lib/amplitude_api/event.rb', line 51

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[:ip] = ip if ip
  serialized_event
end