Class: Courier::Messages::RenderedMessageContent

Inherits:
Object
  • Object
show all
Defined in:
lib/trycourier/messages/types/rendered_message_content.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(html:, title:, body:, subject:, text:, blocks:, additional_properties: nil) ⇒ Messages::RenderedMessageContent

Parameters:

  • html (String)

    The html content of the rendered message.

  • title (String)

    The title of the rendered message.

  • body (String)

    The body of the rendered message.

  • subject (String)

    The subject of the rendered message.

  • text (String)

    The text of the rendered message.

  • blocks (Array<Messages::RenderedMessageBlock>)

    The blocks of the rendered message.

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



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

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

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

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

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

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

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

Parameters:

  • json_object (JSON)

Returns:



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.

Parameters:

  • obj (Object)

Returns:

  • (Void)


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

Returns:

  • (JSON)


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