Class: Courier::Send::ElementalActionNode

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

Overview

Allows the user to execute an action. Can be a button or a link.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content:, href:, locales:, action_id: nil, align: nil, background_color: nil, style: nil, channels: nil, ref: nil, if_: nil, loop: nil, additional_properties: nil) ⇒ Send::ElementalActionNode

Parameters:

  • content (String)

    The text content of the action shown to the user.

  • href (String)

    The target URL of the action.

  • action_id (String) (defaults to: nil)

    A unique id used to identify the action when it is executed.

  • align (Send::IAlignment) (defaults to: nil)

    The alignment of the action button. Defaults to “center”.

  • background_color (String) (defaults to: nil)

    The background color of the action button.

  • style (Send::IActionButtonStyle) (defaults to: nil)

    Defaults to ‘button`.

  • locales (Send::LOCALES)

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

  • 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



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/trycourier/send/types/elemental_action_node.rb', line 28

def initialize(content:, href:, locales:, action_id: nil, align: nil, background_color: nil, style: nil,
               channels: nil, ref: nil, if_: nil, loop: nil, additional_properties: nil)
  # @type [String] The text content of the action shown to the user.
  @content = content
  # @type [String] The target URL of the action.
  @href = href
  # @type [String] A unique id used to identify the action when it is executed.
  @action_id = action_id
  # @type [Send::IAlignment] The alignment of the action button. Defaults to "center".
  @align = align
  # @type [String] The background color of the action button.
  @background_color = background_color
  # @type [Send::IActionButtonStyle] Defaults to `button`.
  @style = style
  # @type [Send::LOCALES] Region specific content. See [locales docs](https://www.courier.com/docs/platform/content/elemental/locales/) for more details.
  @locales = locales
  # @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

#action_idObject (readonly)

Returns the value of attribute action_id.



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

def action_id
  @action_id
end

#additional_propertiesObject (readonly)

Returns the value of attribute additional_properties.



12
13
14
# File 'lib/trycourier/send/types/elemental_action_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_action_node.rb', line 12

def align
  @align
end

#background_colorObject (readonly)

Returns the value of attribute background_color.



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

def background_color
  @background_color
end

#channelsObject (readonly)

Returns the value of attribute channels.



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

def channels
  @channels
end

#contentObject (readonly)

Returns the value of attribute content.



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

def content
  @content
end

#hrefObject (readonly)

Returns the value of attribute href.



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

def href
  @href
end

#if_Object (readonly)

Returns the value of attribute if_.



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

def if_
  @if_
end

#localesObject (readonly)

Returns the value of attribute locales.



12
13
14
# File 'lib/trycourier/send/types/elemental_action_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_action_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_action_node.rb', line 12

def ref
  @ref
end

#styleObject (readonly)

Returns the value of attribute style.



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

def style
  @style
end

Class Method Details

.from_json(json_object:) ⇒ Send::ElementalActionNode

Deserialize a JSON object to an instance of ElementalActionNode

Parameters:

  • json_object (JSON)

Returns:



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/trycourier/send/types/elemental_action_node.rb', line 60

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  JSON.parse(json_object)
  content = struct.content
  href = struct.href
  action_id = struct.action_id
  align = struct.align
  background_color = struct.background_color
  style = struct.style
  locales = struct.locales
  channels = struct.channels
  ref = struct.ref
  if_ = struct.if
  loop = struct.loop
  new(content: content, href: href, action_id: action_id, align: align, background_color: background_color,
      style: style, locales: locales, 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)


101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/trycourier/send/types/elemental_action_node.rb', line 101

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.href.is_a?(String) != false || raise("Passed value for field obj.href is not the expected type, validation failed.")
  obj.action_id&.is_a?(String) != false || raise("Passed value for field obj.action_id is not the expected type, validation failed.")
  obj.align&.is_a?(Send::IAlignment) != false || raise("Passed value for field obj.align is not the expected type, validation failed.")
  obj.background_color&.is_a?(String) != false || raise("Passed value for field obj.background_color is not the expected type, validation failed.")
  obj.style&.is_a?(Send::IActionButtonStyle) != false || raise("Passed value for field obj.style 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.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 ElementalActionNode to a JSON object

Returns:

  • (JSON)


81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/trycourier/send/types/elemental_action_node.rb', line 81

def to_json(*_args)
  {
    "content": @content,
    "href": @href,
    "action_id": @action_id,
    "align": @align,
    "background_color": @background_color,
    "style": @style,
    "locales": @locales,
    "channels": @channels,
    "ref": @ref,
    "if": @if_,
    "loop": @loop
  }.to_json
end