Class: Courier::Send::ElementalImageNode

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

Overview

Used to embed an image into the notification.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(src:, href: nil, align: nil, alt_text: nil, width: nil, channels: nil, ref: nil, if_: nil, loop: nil, additional_properties: nil) ⇒ Send::ElementalImageNode

Parameters:

  • src (String)

    The source of the image.

  • href (String) (defaults to: nil)

    A URL to link to when the image is clicked.

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

    The alignment of the image.

  • alt_text (String) (defaults to: nil)

    Alternate text for the image.

  • width (String) (defaults to: nil)

    CSS width properties to apply to the image. For example, 50px

  • 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



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/trycourier/send/types/elemental_image_node.rb', line 23

def initialize(src:, href: nil, align: nil, alt_text: nil, width: nil, channels: nil, ref: nil, if_: nil,
               loop: nil, additional_properties: nil)
  # @type [String] The source of the image.
  @src = src
  # @type [String] A URL to link to when the image is clicked.
  @href = href
  # @type [Send::IAlignment] The alignment of the image.
  @align = align
  # @type [String] Alternate text for the image.
  @alt_text = alt_text
  # @type [String] CSS width properties to apply to the image. For example, 50px
  @width = width
  # @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.



10
11
12
# File 'lib/trycourier/send/types/elemental_image_node.rb', line 10

def additional_properties
  @additional_properties
end

#alignObject (readonly)

Returns the value of attribute align.



10
11
12
# File 'lib/trycourier/send/types/elemental_image_node.rb', line 10

def align
  @align
end

#alt_textObject (readonly)

Returns the value of attribute alt_text.



10
11
12
# File 'lib/trycourier/send/types/elemental_image_node.rb', line 10

def alt_text
  @alt_text
end

#channelsObject (readonly)

Returns the value of attribute channels.



10
11
12
# File 'lib/trycourier/send/types/elemental_image_node.rb', line 10

def channels
  @channels
end

#hrefObject (readonly)

Returns the value of attribute href.



10
11
12
# File 'lib/trycourier/send/types/elemental_image_node.rb', line 10

def href
  @href
end

#if_Object (readonly)

Returns the value of attribute if_.



10
11
12
# File 'lib/trycourier/send/types/elemental_image_node.rb', line 10

def if_
  @if_
end

#loopObject (readonly)

Returns the value of attribute loop.



10
11
12
# File 'lib/trycourier/send/types/elemental_image_node.rb', line 10

def loop
  @loop
end

#refObject (readonly)

Returns the value of attribute ref.



10
11
12
# File 'lib/trycourier/send/types/elemental_image_node.rb', line 10

def ref
  @ref
end

#srcObject (readonly)

Returns the value of attribute src.



10
11
12
# File 'lib/trycourier/send/types/elemental_image_node.rb', line 10

def src
  @src
end

#widthObject (readonly)

Returns the value of attribute width.



10
11
12
# File 'lib/trycourier/send/types/elemental_image_node.rb', line 10

def width
  @width
end

Class Method Details

.from_json(json_object:) ⇒ Send::ElementalImageNode

Deserialize a JSON object to an instance of ElementalImageNode

Parameters:

  • json_object (JSON)

Returns:



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/trycourier/send/types/elemental_image_node.rb', line 51

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  JSON.parse(json_object)
  src = struct.src
  href = struct.href
  align = struct.align
  alt_text = struct.altText
  width = struct.width
  channels = struct.channels
  ref = struct.ref
  if_ = struct.if
  loop = struct.loop
  new(src: src, href: href, align: align, alt_text: alt_text, width: width, 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)


88
89
90
91
92
93
94
95
96
97
98
# File 'lib/trycourier/send/types/elemental_image_node.rb', line 88

def self.validate_raw(obj:)
  obj.src.is_a?(String) != false || raise("Passed value for field obj.src 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.align&.is_a?(Send::IAlignment) != false || raise("Passed value for field obj.align is not the expected type, validation failed.")
  obj.alt_text&.is_a?(String) != false || raise("Passed value for field obj.alt_text is not the expected type, validation failed.")
  obj.width&.is_a?(String) != false || raise("Passed value for field obj.width 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 ElementalImageNode to a JSON object

Returns:

  • (JSON)


70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/trycourier/send/types/elemental_image_node.rb', line 70

def to_json(*_args)
  {
    "src": @src,
    "href": @href,
    "align": @align,
    "altText": @alt_text,
    "width": @width,
    "channels": @channels,
    "ref": @ref,
    "if": @if_,
    "loop": @loop
  }.to_json
end