Class: Courier::Send::ElementalContent

Inherits:
Object
  • Object
show all
Defined in:
lib/trycourier/send/types/elemental_content.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version:, elements:, brand: nil, additional_properties: nil) ⇒ Send::ElementalContent

Parameters:

  • version (String)

    For example, “2022-01-01”

  • brand (Object) (defaults to: nil)
  • elements (Array<Send::ElementalNode>)
  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



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_propertiesObject (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

#brandObject (readonly)

Returns the value of attribute brand.



9
10
11
# File 'lib/trycourier/send/types/elemental_content.rb', line 9

def brand
  @brand
end

#elementsObject (readonly)

Returns the value of attribute elements.



9
10
11
# File 'lib/trycourier/send/types/elemental_content.rb', line 9

def elements
  @elements
end

#versionObject (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

Parameters:

  • json_object (JSON)

Returns:



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.

Parameters:

  • obj (Object)

Returns:

  • (Void)


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

Returns:

  • (JSON)


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