Class: Courier::Send::ElementalContent
- Inherits:
-
Object
- Object
- Courier::Send::ElementalContent
- Defined in:
- lib/trycourier/send/types/elemental_content.rb
Instance Attribute Summary collapse
-
#additional_properties ⇒ Object
readonly
Returns the value of attribute additional_properties.
-
#brand ⇒ Object
readonly
Returns the value of attribute brand.
-
#elements ⇒ Object
readonly
Returns the value of attribute elements.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
-
.from_json(json_object:) ⇒ Send::ElementalContent
Deserialize a JSON object to an instance of ElementalContent.
-
.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.
Instance Method Summary collapse
- #initialize(version:, elements:, brand: nil, additional_properties: nil) ⇒ Send::ElementalContent constructor
-
#to_json(*_args) ⇒ JSON
Serialize an instance of ElementalContent to a JSON object.
Constructor Details
#initialize(version:, elements:, brand: nil, additional_properties: nil) ⇒ Send::ElementalContent
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/trycourier/send/types/elemental_content.rb', line 16 def initialize(version:, elements:, brand: nil, additional_properties: nil) # @type [String] For example, "2022-01-01" @version = version # @type [Object] @brand = brand # @type [Array<Send::ElementalNode>] @elements = elements # @type [OpenStruct] Additional properties unmapped to the current class definition @additional_properties = additional_properties end |
Instance Attribute Details
#additional_properties ⇒ Object (readonly)
Returns the value of attribute additional_properties.
9 10 11 |
# File 'lib/trycourier/send/types/elemental_content.rb', line 9 def additional_properties @additional_properties end |
#brand ⇒ Object (readonly)
Returns the value of attribute brand.
9 10 11 |
# File 'lib/trycourier/send/types/elemental_content.rb', line 9 def brand @brand end |
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
9 10 11 |
# File 'lib/trycourier/send/types/elemental_content.rb', line 9 def elements @elements end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
9 10 11 |
# File 'lib/trycourier/send/types/elemental_content.rb', line 9 def version @version end |
Class Method Details
.from_json(json_object:) ⇒ Send::ElementalContent
Deserialize a JSON object to an instance of ElementalContent
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/trycourier/send/types/elemental_content.rb', line 31 def self.from_json(json_object:) struct = JSON.parse(json_object, object_class: OpenStruct) parsed_json = JSON.parse(json_object) version = struct.version brand = struct.brand elements = parsed_json["elements"]&.map do |v| v = v.to_json Send::ElementalNode.from_json(json_object: v) end new(version: version, brand: brand, elements: elements, 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.
54 55 56 57 58 |
# File 'lib/trycourier/send/types/elemental_content.rb', line 54 def self.validate_raw(obj:) obj.version.is_a?(String) != false || raise("Passed value for field obj.version is not the expected type, validation failed.") obj.brand&.is_a?(Object) != false || raise("Passed value for field obj.brand is not the expected type, validation failed.") obj.elements.is_a?(Array) != false || raise("Passed value for field obj.elements is not the expected type, validation failed.") end |
Instance Method Details
#to_json(*_args) ⇒ JSON
Serialize an instance of ElementalContent to a JSON object
46 47 48 |
# File 'lib/trycourier/send/types/elemental_content.rb', line 46 def to_json(*_args) { "version": @version, "brand": @brand, "elements": @elements }.to_json end |