Class: SamsaraSDK::Event

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

Overview

Contains methods for event manipulation.

Class Method Summary collapse

Class Method Details

.enrich(event) ⇒ Hash

Enriches missing event properties with ones from config.

Parameters:

  • event (Hash)

    Event for Ingestion API.

Returns:

  • (Hash)

    Event for Ingestion API filled with missing properties.



34
35
36
37
38
# File 'lib/samsara_sdk/event.rb', line 34

def enrich(event)
  event[:sourceId] = event.fetch(:sourceId, Config.get[:sourceId])
  event[:timestamp] = event.fetch(:timestamp, Config.timestamp)
  event
end

.validate(event) ⇒ Hash

Validates event to conform Ingestion API requirements.

Parameters:

  • event (Hash)

    Event.

Returns:

  • (Hash)

    Passed back event.

Raises:



45
46
47
48
49
50
51
52
# File 'lib/samsara_sdk/event.rb', line 45

def validate(event)
  @schema.each do |schema_param, schema_value|
    schema_value.each do |rule_key, rule_value|
      @rules[rule_key].call(schema_param, event[schema_param], rule_value)
    end
  end
  event
end