Class: Courier::Send::ElementalTextNode

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

Overview

Represents a body of text to be rendered inside of the notification.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content:, align:, text_style: nil, color: nil, bold: nil, italic: nil, strikethrough: nil, underline: nil, locales: nil, format: nil, channels: nil, ref: nil, if_: nil, loop: nil, additional_properties: nil) ⇒ Send::ElementalTextNode

Parameters:

  • content (String)

    The text content displayed in the notification. Either this field must be specified, or the elements field

  • align (Send::TextAlign)

    Text alignment.

  • text_style (Send::TextStyle) (defaults to: nil)

    Allows the text to be rendered as a heading level.

  • color (String) (defaults to: nil)

    Specifies the color of text. Can be any valid css color value

  • bold (String) (defaults to: nil)

    Apply bold to the text

  • italic (String) (defaults to: nil)

    Apply italics to the text

  • strikethrough (String) (defaults to: nil)

    Apply a strike through the text

  • underline (String) (defaults to: nil)

    Apply an underline to the text

  • locales (Send::LOCALES) (defaults to: nil)

    Region specific content. See [locales docs](www.courier.com/docs/platform/content/elemental/locales/) for more details.

  • format (String) (defaults to: nil)
  • channels (Array<String>) (defaults to: nil)
  • ref (String) (defaults to: nil)
  • if_ (String) (defaults to: nil)
  • loop (String) (defaults to: nil)
  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/trycourier/send/types/elemental_text_node.rb', line 32

def initialize(content:, align:, text_style: nil, color: nil, bold: nil, italic: nil, strikethrough: nil,
               underline: nil, locales: nil, format: nil, channels: nil, ref: nil, if_: nil, loop: nil, additional_properties: nil)
  # @type [String] The text content displayed in the notification. Either this
  #   field must be specified, or the elements field
  @content = content
  # @type [Send::TextAlign] Text alignment.
  @align = align
  # @type [Send::TextStyle] Allows the text to be rendered as a heading level.
  @text_style = text_style
  # @type [String] Specifies the color of text. Can be any valid css color value
  @color = color
  # @type [String] Apply bold to the text
  @bold = bold
  # @type [String] Apply italics to the text
  @italic = italic
  # @type [String] Apply a strike through the text
  @strikethrough = strikethrough
  # @type [String] Apply an underline to the text
  @underline = underline
  # @type [Send::LOCALES] Region specific content. See [locales docs](https://www.courier.com/docs/platform/content/elemental/locales/) for more details.
  @locales = locales
  # @type [String]
  @format = format
  # @type [Array<String>]
  @channels = channels
  # @type [String]
  @ref = ref
  # @type [String]
  @if_ = if_
  # @type [String]
  @loop = loop
  # @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.



12
13
14
# File 'lib/trycourier/send/types/elemental_text_node.rb', line 12

def additional_properties
  @additional_properties
end

#alignObject (readonly)

Returns the value of attribute align.



12
13
14
# File 'lib/trycourier/send/types/elemental_text_node.rb', line 12

def align
  @align
end

#boldObject (readonly)

Returns the value of attribute bold.



12
13
14
# File 'lib/trycourier/send/types/elemental_text_node.rb', line 12

def bold
  @bold
end

#channelsObject (readonly)

Returns the value of attribute channels.



12
13
14
# File 'lib/trycourier/send/types/elemental_text_node.rb', line 12

def channels
  @channels
end

#colorObject (readonly)

Returns the value of attribute color.



12
13
14
# File 'lib/trycourier/send/types/elemental_text_node.rb', line 12

def color
  @color
end

#contentObject (readonly)

Returns the value of attribute content.



12
13
14
# File 'lib/trycourier/send/types/elemental_text_node.rb', line 12

def content
  @content
end

#formatObject (readonly)

Returns the value of attribute format.



12
13
14
# File 'lib/trycourier/send/types/elemental_text_node.rb', line 12

def format
  @format
end

#if_Object (readonly)

Returns the value of attribute if_.



12
13
14
# File 'lib/trycourier/send/types/elemental_text_node.rb', line 12

def if_
  @if_
end

#italicObject (readonly)

Returns the value of attribute italic.



12
13
14
# File 'lib/trycourier/send/types/elemental_text_node.rb', line 12

def italic
  @italic
end

#localesObject (readonly)

Returns the value of attribute locales.



12
13
14
# File 'lib/trycourier/send/types/elemental_text_node.rb', line 12

def locales
  @locales
end

#loopObject (readonly)

Returns the value of attribute loop.



12
13
14
# File 'lib/trycourier/send/types/elemental_text_node.rb', line 12

def loop
  @loop
end

#refObject (readonly)

Returns the value of attribute ref.



12
13
14
# File 'lib/trycourier/send/types/elemental_text_node.rb', line 12

def ref
  @ref
end

#strikethroughObject (readonly)

Returns the value of attribute strikethrough.



12
13
14
# File 'lib/trycourier/send/types/elemental_text_node.rb', line 12

def strikethrough
  @strikethrough
end

#text_styleObject (readonly)

Returns the value of attribute text_style.



12
13
14
# File 'lib/trycourier/send/types/elemental_text_node.rb', line 12

def text_style
  @text_style
end

#underlineObject (readonly)

Returns the value of attribute underline.



12
13
14
# File 'lib/trycourier/send/types/elemental_text_node.rb', line 12

def underline
  @underline
end

Class Method Details

.from_json(json_object:) ⇒ Send::ElementalTextNode

Deserialize a JSON object to an instance of ElementalTextNode

Parameters:

  • json_object (JSON)

Returns:



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/trycourier/send/types/elemental_text_node.rb', line 71

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  JSON.parse(json_object)
  content = struct.content
  align = struct.align
  text_style = struct.text_style
  color = struct.color
  bold = struct.bold
  italic = struct.italic
  strikethrough = struct.strikethrough
  underline = struct.underline
  locales = struct.locales
  format = struct.format
  channels = struct.channels
  ref = struct.ref
  if_ = struct.if
  loop = struct.loop
  new(content: content, align: align, text_style: text_style, color: color, bold: bold, italic: italic,
      strikethrough: strikethrough, underline: underline, locales: locales, format: format, channels: channels, ref: ref, if_: if_, loop: loop, 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)


118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/trycourier/send/types/elemental_text_node.rb', line 118

def self.validate_raw(obj:)
  obj.content.is_a?(String) != false || raise("Passed value for field obj.content is not the expected type, validation failed.")
  obj.align.is_a?(Send::TextAlign) != false || raise("Passed value for field obj.align is not the expected type, validation failed.")
  obj.text_style&.is_a?(Send::TextStyle) != false || raise("Passed value for field obj.text_style is not the expected type, validation failed.")
  obj.color&.is_a?(String) != false || raise("Passed value for field obj.color is not the expected type, validation failed.")
  obj.bold&.is_a?(String) != false || raise("Passed value for field obj.bold is not the expected type, validation failed.")
  obj.italic&.is_a?(String) != false || raise("Passed value for field obj.italic is not the expected type, validation failed.")
  obj.strikethrough&.is_a?(String) != false || raise("Passed value for field obj.strikethrough is not the expected type, validation failed.")
  obj.underline&.is_a?(String) != false || raise("Passed value for field obj.underline is not the expected type, validation failed.")
  obj.locales&.is_a?(Hash) != false || raise("Passed value for field obj.locales is not the expected type, validation failed.")
  obj.format&.is_a?(String) != false || raise("Passed value for field obj.format is not the expected type, validation failed.")
  obj.channels&.is_a?(Array) != false || raise("Passed value for field obj.channels is not the expected type, validation failed.")
  obj.ref&.is_a?(String) != false || raise("Passed value for field obj.ref is not the expected type, validation failed.")
  obj.if_&.is_a?(String) != false || raise("Passed value for field obj.if_ is not the expected type, validation failed.")
  obj.loop&.is_a?(String) != false || raise("Passed value for field obj.loop is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ JSON

Serialize an instance of ElementalTextNode to a JSON object

Returns:

  • (JSON)


95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/trycourier/send/types/elemental_text_node.rb', line 95

def to_json(*_args)
  {
    "content": @content,
    "align": @align,
    "text_style": @text_style,
    "color": @color,
    "bold": @bold,
    "italic": @italic,
    "strikethrough": @strikethrough,
    "underline": @underline,
    "locales": @locales,
    "format": @format,
    "channels": @channels,
    "ref": @ref,
    "if": @if_,
    "loop": @loop
  }.to_json
end