Class: Courier::Messages::RenderedMessageContent
- Inherits:
-
Object
- Object
- Courier::Messages::RenderedMessageContent
- Defined in:
- lib/trycourier/messages/types/rendered_message_content.rb
Instance Attribute Summary collapse
-
#additional_properties ⇒ Object
readonly
Returns the value of attribute additional_properties.
-
#blocks ⇒ Object
readonly
Returns the value of attribute blocks.
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#html ⇒ Object
readonly
Returns the value of attribute html.
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Class Method Summary collapse
-
.from_json(json_object:) ⇒ Messages::RenderedMessageContent
Deserialize a JSON object to an instance of RenderedMessageContent.
-
.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(html:, title:, body:, subject:, text:, blocks:, additional_properties: nil) ⇒ Messages::RenderedMessageContent constructor
-
#to_json(*_args) ⇒ JSON
Serialize an instance of RenderedMessageContent to a JSON object.
Constructor Details
#initialize(html:, title:, body:, subject:, text:, blocks:, additional_properties: nil) ⇒ Messages::RenderedMessageContent
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/trycourier/messages/types/rendered_message_content.rb', line 19 def initialize(html:, title:, body:, subject:, text:, blocks:, additional_properties: nil) # @type [String] The html content of the rendered message. @html = html # @type [String] The title of the rendered message. @title = title # @type [String] The body of the rendered message. @body = body # @type [String] The subject of the rendered message. @subject = subject # @type [String] The text of the rendered message. @text = text # @type [Array<Messages::RenderedMessageBlock>] The blocks of the rendered message. @blocks = blocks # @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/messages/types/rendered_message_content.rb', line 9 def additional_properties @additional_properties end |
#blocks ⇒ Object (readonly)
Returns the value of attribute blocks.
9 10 11 |
# File 'lib/trycourier/messages/types/rendered_message_content.rb', line 9 def blocks @blocks end |
#body ⇒ Object (readonly)
Returns the value of attribute body.
9 10 11 |
# File 'lib/trycourier/messages/types/rendered_message_content.rb', line 9 def body @body end |
#html ⇒ Object (readonly)
Returns the value of attribute html.
9 10 11 |
# File 'lib/trycourier/messages/types/rendered_message_content.rb', line 9 def html @html end |
#subject ⇒ Object (readonly)
Returns the value of attribute subject.
9 10 11 |
# File 'lib/trycourier/messages/types/rendered_message_content.rb', line 9 def subject @subject end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
9 10 11 |
# File 'lib/trycourier/messages/types/rendered_message_content.rb', line 9 def text @text end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
9 10 11 |
# File 'lib/trycourier/messages/types/rendered_message_content.rb', line 9 def title @title end |
Class Method Details
.from_json(json_object:) ⇒ Messages::RenderedMessageContent
Deserialize a JSON object to an instance of RenderedMessageContent
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/trycourier/messages/types/rendered_message_content.rb', line 40 def self.from_json(json_object:) struct = JSON.parse(json_object, object_class: OpenStruct) parsed_json = JSON.parse(json_object) html = struct.html title = struct.title body = struct.body subject = struct.subject text = struct.text blocks = parsed_json["blocks"]&.map do |v| v = v.to_json Messages::RenderedMessageBlock.from_json(json_object: v) end new(html: html, title: title, body: body, subject: subject, text: text, blocks: blocks, 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.
67 68 69 70 71 72 73 74 |
# File 'lib/trycourier/messages/types/rendered_message_content.rb', line 67 def self.validate_raw(obj:) obj.html.is_a?(String) != false || raise("Passed value for field obj.html is not the expected type, validation failed.") obj.title.is_a?(String) != false || raise("Passed value for field obj.title is not the expected type, validation failed.") obj.body.is_a?(String) != false || raise("Passed value for field obj.body is not the expected type, validation failed.") obj.subject.is_a?(String) != false || raise("Passed value for field obj.subject is not the expected type, validation failed.") obj.text.is_a?(String) != false || raise("Passed value for field obj.text is not the expected type, validation failed.") obj.blocks.is_a?(Array) != false || raise("Passed value for field obj.blocks is not the expected type, validation failed.") end |
Instance Method Details
#to_json(*_args) ⇒ JSON
Serialize an instance of RenderedMessageContent to a JSON object
59 60 61 |
# File 'lib/trycourier/messages/types/rendered_message_content.rb', line 59 def to_json(*_args) { "html": @html, "title": @title, "body": @body, "subject": @subject, "text": @text, "blocks": @blocks }.to_json end |