Class: Courier::AuditEvents::AuditEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/trycourier/audit_events/types/audit_event.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(audit_event_id:, source:, timestamp:, type:, actor: nil, target: nil, additional_properties: nil) ⇒ AuditEvents::AuditEvent

Parameters:

  • actor (AuditEvents::Actor) (defaults to: nil)
  • target (AuditEvents::Target) (defaults to: nil)
  • audit_event_id (String)
  • source (String)
  • timestamp (String)
  • type (String)
  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/trycourier/audit_events/types/audit_event.rb', line 20

def initialize(audit_event_id:, source:, timestamp:, type:, actor: nil, target: nil, additional_properties: nil)
  # @type [AuditEvents::Actor]
  @actor = actor
  # @type [AuditEvents::Target]
  @target = target
  # @type [String]
  @audit_event_id = audit_event_id
  # @type [String]
  @source = source
  # @type [String]
  @timestamp = timestamp
  # @type [String]
  @type = type
  # @type [OpenStruct] Additional properties unmapped to the current class definition
  @additional_properties = additional_properties
end

Instance Attribute Details

#actorObject (readonly)

Returns the value of attribute actor.



10
11
12
# File 'lib/trycourier/audit_events/types/audit_event.rb', line 10

def actor
  @actor
end

#additional_propertiesObject (readonly)

Returns the value of attribute additional_properties.



10
11
12
# File 'lib/trycourier/audit_events/types/audit_event.rb', line 10

def additional_properties
  @additional_properties
end

#audit_event_idObject (readonly)

Returns the value of attribute audit_event_id.



10
11
12
# File 'lib/trycourier/audit_events/types/audit_event.rb', line 10

def audit_event_id
  @audit_event_id
end

#sourceObject (readonly)

Returns the value of attribute source.



10
11
12
# File 'lib/trycourier/audit_events/types/audit_event.rb', line 10

def source
  @source
end

#targetObject (readonly)

Returns the value of attribute target.



10
11
12
# File 'lib/trycourier/audit_events/types/audit_event.rb', line 10

def target
  @target
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



10
11
12
# File 'lib/trycourier/audit_events/types/audit_event.rb', line 10

def timestamp
  @timestamp
end

#typeObject (readonly)

Returns the value of attribute type.



10
11
12
# File 'lib/trycourier/audit_events/types/audit_event.rb', line 10

def type
  @type
end

Class Method Details

.from_json(json_object:) ⇒ AuditEvents::AuditEvent

Deserialize a JSON object to an instance of AuditEvent

Parameters:

  • json_object (JSON)

Returns:



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

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  if parsed_json["actor"].nil?
    actor = nil
  else
    actor = parsed_json["actor"].to_json
    actor = AuditEvents::Actor.from_json(json_object: actor)
  end
  if parsed_json["target"].nil?
    target = nil
  else
    target = parsed_json["target"].to_json
    target = AuditEvents::Target.from_json(json_object: target)
  end
  audit_event_id = struct.auditEventId
  source = struct.source
  timestamp = struct.timestamp
  type = struct.type
  new(actor: actor, target: target, audit_event_id: audit_event_id, source: source, timestamp: timestamp,
      type: type, additional_properties: struct)
end

.validate_raw(obj:) ⇒ Void

Leveraged for Union-type generation, validate_raw attempts to parse the given hash and check each fields type against the current object’s property definitions.

Parameters:

  • obj (Object)

Returns:

  • (Void)


82
83
84
85
86
87
88
89
# File 'lib/trycourier/audit_events/types/audit_event.rb', line 82

def self.validate_raw(obj:)
  obj.actor.nil? || AuditEvents::Actor.validate_raw(obj: obj.actor)
  obj.target.nil? || AuditEvents::Target.validate_raw(obj: obj.target)
  obj.audit_event_id.is_a?(String) != false || raise("Passed value for field obj.audit_event_id is not the expected type, validation failed.")
  obj.source.is_a?(String) != false || raise("Passed value for field obj.source is not the expected type, validation failed.")
  obj.timestamp.is_a?(String) != false || raise("Passed value for field obj.timestamp is not the expected type, validation failed.")
  obj.type.is_a?(String) != false || raise("Passed value for field obj.type is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ JSON

Serialize an instance of AuditEvent to a JSON object

Returns:

  • (JSON)


67
68
69
70
71
72
73
74
75
76
# File 'lib/trycourier/audit_events/types/audit_event.rb', line 67

def to_json(*_args)
  {
    "actor": @actor,
    "target": @target,
    "auditEventId": @audit_event_id,
    "source": @source,
    "timestamp": @timestamp,
    "type": @type
  }.to_json
end