Class: Samsara::Types::WebhookEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/samsara_api/types/webhook_event.rb

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event_id:, event_ms:, event_type:, event:, additional_properties: nil) ⇒ Samsara::Types::WebhookEvent

Parameters:

  • event_id (String) —

    Unique identifier for the event

  • event_ms (Long) —

    Timestamp when the event was sent (Unix epoch in milliseconds)

  • event_type (String) —

    Type of the event

  • event (Samsara::Types::AlertEvent)
  • additional_properties (OpenStruct) (defaults to: nil) —

    Additional properties unmapped to the current class definition



31
32
33
34
35
36
37
38
# File 'lib/samsara_api/types/webhook_event.rb', line 31

def initialize(event_id:, event_ms:, event_type:, event:, additional_properties: nil)
  @event_id = event_id
  @event_ms = event_ms
  @event_type = event_type
  @event = event
  @additional_properties = additional_properties
  @_field_set = { "eventId": event_id, "eventMs": event_ms, "eventType": event_type, "event": event }
end

Instance Attribute Details

#additional_properties ⇒ OpenStruct (readonly)

Returns Additional properties unmapped to the current class definition.

Returns:

  • (OpenStruct) —

    Additional properties unmapped to the current class definition



18
19
20
# File 'lib/samsara_api/types/webhook_event.rb', line 18

def additional_properties
  @additional_properties
end

#event ⇒ Samsara::Types::AlertEvent (readonly)



16
17
18
# File 'lib/samsara_api/types/webhook_event.rb', line 16

def event
  @event
end

#event_id ⇒ String (readonly)

Returns Unique identifier for the event.

Returns:

  • (String) —

    Unique identifier for the event



10
11
12
# File 'lib/samsara_api/types/webhook_event.rb', line 10

def event_id
  @event_id
end

#event_ms ⇒ Long (readonly)

Returns Timestamp when the event was sent (Unix epoch in milliseconds).

Returns:

  • (Long) —

    Timestamp when the event was sent (Unix epoch in milliseconds)



12
13
14
# File 'lib/samsara_api/types/webhook_event.rb', line 12

def event_ms
  @event_ms
end

#event_type ⇒ String (readonly)

Returns Type of the event.

Returns:

  • (String) —

    Type of the event



14
15
16
# File 'lib/samsara_api/types/webhook_event.rb', line 14

def event_type
  @event_type
end

Class Method Details

.from_json(json_object:) ⇒ Samsara::Types::WebhookEvent

Parameters:

  • json_object (String)

Returns:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/samsara_api/types/webhook_event.rb', line 43

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  event_id = parsed_json["eventId"]
  event_ms = parsed_json["eventMs"]
  event_type = parsed_json["eventType"]
  unless parsed_json["event"].nil?
    event = parsed_json["event"].to_json
    event = Samsara::Types::AlertEvent.from_json(json_object: event)
  else
    event = nil
  end
  new(
    event_id: event_id,
    event_ms: event_ms,
    event_type: event_type,
    event: event,
    additional_properties: struct
  )
end

.validate_raw(obj:) ⇒ Void

Parameters:

  • obj (Object)

Returns:

  • (Void)


75
76
77
78
79
80
# File 'lib/samsara_api/types/webhook_event.rb', line 75

def self.validate_raw(obj:)
  obj.event_id.is_a?(String) != false || raise("Passed value for field obj.event_id is not the expected type, validation failed.")
  obj.event_ms.is_a?(Long) != false || raise("Passed value for field obj.event_ms is not the expected type, validation failed.")
  obj.event_type.is_a?(String) != false || raise("Passed value for field obj.event_type is not the expected type, validation failed.")
  Samsara::Types::AlertEvent.validate_raw(obj: obj.event)
end

Instance Method Details

#to_json ⇒ String

Returns:

  • (String)


66
67
68
# File 'lib/samsara_api/types/webhook_event.rb', line 66

def to_json
  @_field_set&.to_json
end