Class: Intrinsic::EventTypeObject

Inherits:
Object
  • Object
show all
Defined in:
lib/intrinsic/types/event_type_object.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, name:, fields:, object:, additional_properties: nil) ⇒ EventTypeObject

Parameters:

  • id (String)

    ID of the event type

  • name (String)

    Name of the event type. Must be unique, and can only contain alphanumeric characters and underscores, and be up to 255 characters

  • fields (Array<EventTypeField>)

    Fields of the event type

  • object (String)
  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/intrinsic/types/event_type_object.rb', line 16

def initialize(id:, name:, fields:, object:, additional_properties: nil)
  # @type [String] ID of the event type
  @id = id
  # @type [String] Name of the event type. Must be unique, and can only contain alphanumeric characters and underscores, and be up to 255 characters
  @name = name
  # @type [Array<EventTypeField>] Fields of the event type
  @fields = fields
  # @type [String]
  @object = object
  # @type [OpenStruct] Additional properties unmapped to the current class definition
  @additional_properties = additional_properties
end

Instance Attribute Details

#additional_propertiesObject (readonly)

Returns the value of attribute additional_properties.



8
9
10
# File 'lib/intrinsic/types/event_type_object.rb', line 8

def additional_properties
  @additional_properties
end

#fieldsObject (readonly)

Returns the value of attribute fields.



8
9
10
# File 'lib/intrinsic/types/event_type_object.rb', line 8

def fields
  @fields
end

#idObject (readonly)

Returns the value of attribute id.



8
9
10
# File 'lib/intrinsic/types/event_type_object.rb', line 8

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/intrinsic/types/event_type_object.rb', line 8

def name
  @name
end

#objectObject (readonly)

Returns the value of attribute object.



8
9
10
# File 'lib/intrinsic/types/event_type_object.rb', line 8

def object
  @object
end

Class Method Details

.from_json(json_object:) ⇒ EventTypeObject

Deserialize a JSON object to an instance of EventTypeObject

Parameters:

  • json_object (JSON)

Returns:



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/intrinsic/types/event_type_object.rb', line 33

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  id = struct.id
  name = struct.name
  fields = parsed_json["fields"]&.map do |v|
    v = v.to_json
    EventTypeField.from_json(json_object: v)
  end
  object = struct.object
  new(id: id, name: name, fields: fields, object: object, 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)


57
58
59
60
61
62
# File 'lib/intrinsic/types/event_type_object.rb', line 57

def self.validate_raw(obj:)
  obj.id.is_a?(String) != false || raise("Passed value for field obj.id is not the expected type, validation failed.")
  obj.name.is_a?(String) != false || raise("Passed value for field obj.name is not the expected type, validation failed.")
  obj.fields.is_a?(Array) != false || raise("Passed value for field obj.fields is not the expected type, validation failed.")
  obj.object.is_a?(String) != false || raise("Passed value for field obj.object is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ JSON

Serialize an instance of EventTypeObject to a JSON object

Returns:

  • (JSON)


49
50
51
# File 'lib/intrinsic/types/event_type_object.rb', line 49

def to_json(*_args)
  { "id": @id, "name": @name, "fields": @fields, "object": @object }.to_json
end