Class: Whatsapp::Messages::Interactive::ReplyButtons::Button

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

Defined Under Namespace

Modules: Defaults

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, title:) ⇒ Button

Returns a new instance of Button.

Parameters:

  • id (String)

    The ID of the button.

  • title (String)

    The title of the button. @raise [ActiveModel::ValidationError] if validation fails.



30
31
32
33
34
35
# File 'lib/ruby/whatsapp/messages/interactive/reply_buttons/button.rb', line 30

def initialize(id:, title:)
  @id = id
  @title = title

  validate!
end

Instance Attribute Details

#idString

Returns:

  • (String)


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

def id
  @id
end

#titleString

Returns:

  • (String)


22
23
24
# File 'lib/ruby/whatsapp/messages/interactive/reply_buttons/button.rb', line 22

def title
  @title
end

Class Method Details

.serialize(id:, title:) ⇒ Hash

Returns Serialized representation of the Button. @raise [ActiveModel::ValidationError] if validation fails.

Returns:

  • (Hash)

    Serialized representation of the Button. @raise [ActiveModel::ValidationError] if validation fails.



40
41
42
# File 'lib/ruby/whatsapp/messages/interactive/reply_buttons/button.rb', line 40

def serialize(id:, title:)
  new(id:, title:).serialize
end

Instance Method Details

#serializeHash

Returns Serialized representation of the Button.

Returns:

  • (Hash)

    Serialized representation of the Button.



46
47
48
49
50
51
52
53
54
# File 'lib/ruby/whatsapp/messages/interactive/reply_buttons/button.rb', line 46

def serialize
  {
    type: Defaults::TYPE,
    reply: {
      id:,
      title:,
    },
  }
end