Class: Whatsapp::Messages::Location

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

Overview

Location messages allow you to send a location's latitude and longitude coordinates to a WhatsApp user. Source: https://developers.facebook.com/documentation/business-messaging/whatsapp/messages/location-messages

Defined Under Namespace

Modules: Defaults

Instance Attribute Summary collapse

Attributes inherited from Base

#to

Instance Method Summary collapse

Constructor Details

#initialize(latitude:, longitude:, name: nil, address: nil) ⇒ Location

Returns a new instance of Location.

Parameters:

  • latitude (Float)

    The latitude of the location.

  • longitude (Float)

    The longitude of the location.

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

    The name of the location.

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

    The address of the location.

  • kwargs (Hash)

    Additional keyword arguments (e.g. :to). @raise [ActiveModel::ValidationError] if validation fails.



37
38
39
40
41
42
43
44
45
46
# File 'lib/ruby/whatsapp/messages/location.rb', line 37

def initialize(latitude:, longitude:, name: nil, address: nil, **)
  super(**)

  @latitude = latitude
  @longitude = longitude
  @name = name
  @address = address

  validate!
end

Instance Attribute Details

#addressString?

Returns:

  • (String, nil)


26
27
28
# File 'lib/ruby/whatsapp/messages/location.rb', line 26

def address
  @address
end

#latitudeFloat

Returns:

  • (Float)


14
15
16
# File 'lib/ruby/whatsapp/messages/location.rb', line 14

def latitude
  @latitude
end

#longitudeFloat

Returns:

  • (Float)


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

def longitude
  @longitude
end

#nameString?

Returns:

  • (String, nil)


22
23
24
# File 'lib/ruby/whatsapp/messages/location.rb', line 22

def name
  @name
end

Instance Method Details

#serializeHash

Serializes the location message to a hash format suitable for the WhatsApp API.

Returns:

  • (Hash)

    The serialized location message.



50
51
52
# File 'lib/ruby/whatsapp/messages/location.rb', line 50

def serialize
  envelope(type: Defaults::TYPE, location: location_payload)
end