Class: Whatsapp::Messages::Interactive::MediaCarousel::Card

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
lib/ruby/whatsapp/messages/interactive/media_carousel/card.rb,
lib/ruby/whatsapp/messages/interactive/media_carousel/card/button.rb,
lib/ruby/whatsapp/messages/interactive/media_carousel/card/button/quick_reply.rb

Defined Under Namespace

Modules: Defaults Classes: Button

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(card_index:, header:, body:, action:, buttons:) ⇒ Card

Returns a new instance of Card.

Parameters:

  • card_index (Integer)

    The index of the card.

  • header (Hash)

    The header content of the card.

  • body (String)

    The body content of the card.

  • action (Hash)

    The action content of the card.



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

def initialize(card_index:, header:, body:, action:, buttons:)
  @card_index = card_index
  @header = header
  @body = body
  @action = action
  @buttons = buttons

  validate!
end

Instance Attribute Details

#actionHash

Returns:

  • (Hash)


28
29
30
# File 'lib/ruby/whatsapp/messages/interactive/media_carousel/card.rb', line 28

def action
  @action
end

#bodyString

Returns:

  • (String)


24
25
26
# File 'lib/ruby/whatsapp/messages/interactive/media_carousel/card.rb', line 24

def body
  @body
end

#buttonsArray<Hash>

Returns:

  • (Array<Hash>)


32
33
34
# File 'lib/ruby/whatsapp/messages/interactive/media_carousel/card.rb', line 32

def buttons
  @buttons
end

#card_indexInteger

Returns:

  • (Integer)


16
17
18
# File 'lib/ruby/whatsapp/messages/interactive/media_carousel/card.rb', line 16

def card_index
  @card_index
end

#headerHash

Returns:

  • (Hash)


20
21
22
# File 'lib/ruby/whatsapp/messages/interactive/media_carousel/card.rb', line 20

def header
  @header
end

Class Method Details

.serialize(card_index:, header:, body:, action:, buttons:) ⇒ Hash

Returns Serialized representation of the Card.

Returns:

  • (Hash)

    Serialized representation of the Card.



52
53
54
# File 'lib/ruby/whatsapp/messages/interactive/media_carousel/card.rb', line 52

def serialize(card_index:, header:, body:, action:, buttons:)
  new(card_index:, header:, body:, action:, buttons:).serialize
end

Instance Method Details

#serializeHash

Returns Serialized representation of the Card.

Returns:

  • (Hash)

    Serialized representation of the Card.



58
59
60
61
62
63
64
65
66
67
# File 'lib/ruby/whatsapp/messages/interactive/media_carousel/card.rb', line 58

def serialize
  {
    card_index:,
    type: Defaults::TYPE,
    header: Whatsapp::Messages::Interactive::Header.serialize(**header),
    body: Whatsapp::Messages::Interactive::Body.serialize(body),
    action: Whatsapp::Messages::Interactive::UrlButton.serialize(**action),
    buttons: serialized_buttons,
  }
end