Class: Freshworks::Event

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

Constant Summary collapse

BASE_URI =
'https://events-us.freshsuccess.com'
VERSION_URI =
'/v1'
REQUIRED_PARAMS =
%w{
  account_id
  user_id
  created_at
  session_id
}

Instance Attribute Summary

Attributes inherited from Base

#raw_response

Class Method Summary collapse

Methods inherited from Base

#initialize, json_data, json_headers, request_helper, #to_json

Methods included from Serializable

#serialize, #to_h, #unserialize

Constructor Details

This class inherits a constructor from Freshworks::Base

Class Method Details

.create(event, action, optional_fields = {}) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/freshworks/event.rb', line 32

def self.create(event, action, optional_fields={})
  body = event.to_h
  body.merge!({ action: action })
  body.merge!(optional_fields)

  post([], json_data(body))
end

.endpoint(*params) ⇒ Object



44
45
46
47
# File 'lib/freshworks/event.rb', line 44

def self.endpoint(*params)
  params = [endpoint_path, params].flatten.compact.map(&:to_s)
  Freshworks.full_endpoint_uri(BASE_URI, VERSION_URI, params)
end

.endpoint_pathObject



40
41
42
# File 'lib/freshworks/event.rb', line 40

def self.endpoint_path
  [Freshworks.configuration.event_auth_key, Freshworks.configuration.event_api_key]
end

.feature(event, feature, module_name, total) ⇒ Object



28
29
30
# File 'lib/freshworks/event.rb', line 28

def self.feature(event, feature, module_name, total)
  create(event, 'feature', { feature: feature, module: module_name, total: total })
end

.identify_account(event, details) ⇒ Object



16
17
18
# File 'lib/freshworks/event.rb', line 16

def self.(event, details)
  create(event, 'identifyAccount', { details: details })
end

.identify_user(event, details) ⇒ Object



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

def self.identify_user(event, details)
  create(event, 'identifyUser', { details: details })
end

.module_end(event, module_name, time_spent) ⇒ Object



24
25
26
# File 'lib/freshworks/event.rb', line 24

def self.module_end(event, module_name, time_spent)
  create(event, 'moduleEnd', { module: module_name, time_spent: time_spent })
end

.session_sync(event, active_duration) ⇒ Object



20
21
22
# File 'lib/freshworks/event.rb', line 20

def self.session_sync(event, active_duration)
  create(event, 'sessionSync', { active_duration: active_duration })
end