Class: Whatsapp::Messages::Interactive::Header

Inherits:
Base
  • Object
show all
Defined in:
lib/ruby/whatsapp/messages/interactive/header.rb

Defined Under Namespace

Modules: Types Classes: HeaderError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, **kwargs) ⇒ Header

Returns a new instance of Header.

Parameters:

  • type (String)

    The type of the header (e.g., "text", "image", "video", "document").

  • kwargs (Hash)

    Additional keyword arguments for the header content.



25
26
27
28
29
30
# File 'lib/ruby/whatsapp/messages/interactive/header.rb', line 25

def initialize(type:, **kwargs)
  @type = type
  @kwargs = kwargs

  validate!
end

Instance Attribute Details

#typeString

Returns:

  • (String)


18
19
20
# File 'lib/ruby/whatsapp/messages/interactive/header.rb', line 18

def type
  @type
end

Class Method Details

.serialize(type:) ⇒ Hash

Returns Serialized representation of the Header.

Returns:

  • (Hash)

    Serialized representation of the Header.



34
35
36
# File 'lib/ruby/whatsapp/messages/interactive/header.rb', line 34

def serialize(type:, **)
  new(type:, **).serialize
end

Instance Method Details

#serializeHash

Returns Serialized representation of the Header.

Returns:

  • (Hash)

    Serialized representation of the Header.



40
41
42
43
44
45
46
47
48
49
# File 'lib/ruby/whatsapp/messages/interactive/header.rb', line 40

def serialize
  case type
  when Types::TEXT then serialize_text
  when Types::IMAGE then serialize_image
  when Types::DOCUMENT then serialize_document
  when Types::VIDEO then serialize_video
  else
    raise HeaderError, "Unsupported header type: #{type.inspect}"
  end
end