Class: AmplitudeAPI::Event
- Inherits:
-
Object
- Object
- AmplitudeAPI::Event
- Defined in:
- lib/amplitude_api/event.rb
Overview
AmplitudeAPI::Event
Instance Method Summary collapse
-
#==(other) ⇒ true, false
Compares +to_hash+ for equality.
-
#initialize(attributes = {}) ⇒ Event
constructor
Create a new Event.
-
#optional_properties ⇒ Hash
Optional properties.
-
#reserved_event?(type) ⇒ true, false
Returns true if the event type matches one reserved by Amplitude API.
-
#to_hash ⇒ Hash
(also: #to_h)
Used for serialization and comparison.
- #user_id=(value) ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Event
Create a new Event
See (Amplitude HTTP API Documentation)[https://amplitude.zendesk.com/hc/en-us/articles/204771828-HTTP-API] for a list of valid parameters and their types.
12 13 14 15 16 17 |
# File 'lib/amplitude_api/event.rb', line 12 def initialize(attributes = {}) attributes.each do |k, v| send("#{k}=", v) if respond_to?("#{k}=") end validate_arguments end |
Instance Method Details
#==(other) ⇒ true, false
Compares +to_hash+ for equality
66 67 68 69 70 |
# File 'lib/amplitude_api/event.rb', line 66 def ==(other) return false unless other.respond_to?(:to_h) to_h == other.to_h end |
#optional_properties ⇒ Hash
Returns Optional properties.
44 45 46 47 48 49 |
# File 'lib/amplitude_api/event.rb', line 44 def optional_properties i[device_id time ip platform country insert_id].map do |prop| val = prop == :time ? formatted_time : send(prop) val ? [prop, val] : nil end.compact.to_h end |
#reserved_event?(type) ⇒ true, false
Returns true if the event type matches one reserved by Amplitude API.
54 55 56 57 58 59 60 61 |
# File 'lib/amplitude_api/event.rb', line 54 def reserved_event?(type) ['[Amplitude] Start Session', '[Amplitude] End Session', '[Amplitude] Revenue', '[Amplitude] Revenue (Verified)', '[Amplitude] Revenue (Unverified)', '[Amplitude] Merged User'].include?(type) end |
#to_hash ⇒ Hash Also known as: to_h
Used for serialization and comparison
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/amplitude_api/event.rb', line 31 def to_hash event = { event_type: event_type, event_properties: formatted_event_properties, user_properties: formatted_user_properties } event[:user_id] = user_id if user_id event[:device_id] = device_id if device_id event.merge(optional_properties).merge(revenue_hash) end |
#user_id=(value) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/amplitude_api/event.rb', line 19 def user_id=(value) @user_id = if value.respond_to?(:id) value.id else value || AmplitudeAPI::USER_WITH_NO_ACCOUNT end end |