Class: WhatsAppCloudApi::Location

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/whats_app_cloud_api/models/location.rb

Overview

Location Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

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

Returns a new instance of Location.



51
52
53
54
55
56
57
58
59
# File 'lib/whats_app_cloud_api/models/location.rb', line 51

def initialize(latitude = nil,
               longitude = nil,
               name = nil,
               address = nil)
  @latitude = latitude unless latitude == SKIP
  @longitude = longitude unless longitude == SKIP
  @name = name unless name == SKIP
  @address = address unless address == SKIP
end

Instance Attribute Details

#addressString

Address of the location. Only displayed if name is present.

Returns:

  • (String)


26
27
28
# File 'lib/whats_app_cloud_api/models/location.rb', line 26

def address
  @address
end

#latitudeString

Latitude of the location.

Returns:

  • (String)


14
15
16
# File 'lib/whats_app_cloud_api/models/location.rb', line 14

def latitude
  @latitude
end

#longitudeString

Longitude of the location.

Returns:

  • (String)


18
19
20
# File 'lib/whats_app_cloud_api/models/location.rb', line 18

def longitude
  @longitude
end

#nameString

Name of the location.

Returns:

  • (String)


22
23
24
# File 'lib/whats_app_cloud_api/models/location.rb', line 22

def name
  @name
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/whats_app_cloud_api/models/location.rb', line 62

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  latitude = hash.key?('latitude') ? hash['latitude'] : SKIP
  longitude = hash.key?('longitude') ? hash['longitude'] : SKIP
  name = hash.key?('name') ? hash['name'] : SKIP
  address = hash.key?('address') ? hash['address'] : SKIP

  # Create object from extracted values.
  Location.new(latitude,
               longitude,
               name,
               address)
end

.namesObject

A mapping from model property names to API property names.



29
30
31
32
33
34
35
36
# File 'lib/whats_app_cloud_api/models/location.rb', line 29

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['latitude'] = 'latitude'
  @_hash['longitude'] = 'longitude'
  @_hash['name'] = 'name'
  @_hash['address'] = 'address'
  @_hash
end

Instance Method Details

#nullablesObject

An array for nullable fields



47
48
49
# File 'lib/whats_app_cloud_api/models/location.rb', line 47

def nullables
  []
end

#optionalsObject

An array for optional fields



39
40
41
42
43
44
# File 'lib/whats_app_cloud_api/models/location.rb', line 39

def optionals
  %w[
    name
    address
  ]
end