Class: Whatsapp::Messages::Contacts::Phone

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
lib/ruby/whatsapp/messages/contacts/phone.rb

Overview

Represents a phone number entry in a contact message.

Defined Under Namespace

Modules: Types

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(phone:, type: nil, wa_id: nil) ⇒ Phone

Returns a new instance of Phone.

Parameters:

  • phone (String)

    The phone number, including country code.

  • type (String, nil) (defaults to: nil)

    Phone type. One of CELL, MAIN, IPHONE, HOME, WORK, OTHER.

  • wa_id (String, nil) (defaults to: nil)

    The WhatsApp ID for this phone number. @raise [ActiveModel::ValidationError] if validation fails.



40
41
42
43
44
45
46
# File 'lib/ruby/whatsapp/messages/contacts/phone.rb', line 40

def initialize(phone:, type: nil, wa_id: nil)
  @phone = phone
  @type = type
  @wa_id = wa_id

  validate!
end

Instance Attribute Details

#phoneString

Returns:

  • (String)


23
24
25
# File 'lib/ruby/whatsapp/messages/contacts/phone.rb', line 23

def phone
  @phone
end

#typeString?

Returns:

  • (String, nil)


27
28
29
# File 'lib/ruby/whatsapp/messages/contacts/phone.rb', line 27

def type
  @type
end

#wa_idString?

Returns:

  • (String, nil)


31
32
33
# File 'lib/ruby/whatsapp/messages/contacts/phone.rb', line 31

def wa_id
  @wa_id
end

Instance Method Details

#serializeHash

Returns The serialized phone payload.

Returns:

  • (Hash)

    The serialized phone payload.



49
50
51
52
53
54
55
# File 'lib/ruby/whatsapp/messages/contacts/phone.rb', line 49

def serialize
  {
    phone:,
    type:,
    wa_id:,
  }.compact
end