Class: Talis::Analytics::Event

Inherits:
Resource show all
Defined in:
lib/talis/analytics/event.rb

Overview

Represents an event for analytical purposes.

Class Method Summary collapse

Methods inherited from Resource

handle_response, new_req_id

Class Method Details

.create(request_id: new_req_id, event:) ⇒ Object

Create a single analytics event. In order to send events, the client must be configured with a valid OAuth client that is allowed to search for users:

Talis::Authentication.client_id = 'client_id'
Talis::Authentication.client_secret = 'client_secret'

Parameters:

  • request_id (String) (defaults to: new_req_id)

    (‘uuid’) unique ID for the remote request.

  • event (Hash)

    The event to send. It must contain the minimum keys:

    {
      class: 'my.class.name',
      source: 'my.source.name'
    }
    

    Other valid keys include: timestamp, user and props. Props can contain any key-value pair of custom data. All other keys will be ignored.

Raises:



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/talis/analytics/event.rb', line 29

def create(request_id: new_req_id, event:)
  request_id = new_req_id unless request_id
  validate_event event
  payload = whitelist_event event
  begin
    response = post_event(request_id, payload)
    handle_response(response, 204)
  rescue SocketError
    raise Talis::ServerCommunicationError
  end
end