Class: WhatsAppCloudApi::Section

Inherits:
BaseModel show all
Defined in:
lib/whats_app_cloud_api/models/section.rb

Overview

Section Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(title = nil, rows = nil) ⇒ Section

Returns a new instance of Section.



44
45
46
47
48
# File 'lib/whats_app_cloud_api/models/section.rb', line 44

def initialize(title = nil,
               rows = nil)
  @title = title unless title == SKIP
  @rows = rows unless rows == SKIP
end

Instance Attribute Details

#rowsList of Row

Required for List Messages. Contains a list of rows. You can have a total of 10 rows across your sections. Each row must have a title (Maximum length: 24 characters) and an ID (Maximum length: 200 characters). You can add a description (Maximum length: 72 characters), but it is optional.

Returns:

  • (List of Row)


21
22
23
# File 'lib/whats_app_cloud_api/models/section.rb', line 21

def rows
  @rows
end

#titleString

Required if the message has more than one section. Title of the section.

Returns:

  • (String)


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

def title
  @title
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/whats_app_cloud_api/models/section.rb', line 51

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  title = hash.key?('title') ? hash['title'] : SKIP
  # Parameter is an array, so we need to iterate through it
  rows = nil
  unless hash['rows'].nil?
    rows = []
    hash['rows'].each do |structure|
      rows << (Row.from_hash(structure) if structure)
    end
  end

  rows = SKIP unless hash.key?('rows')

  # Create object from extracted values.
  Section.new(title,
              rows)
end

.namesObject

A mapping from model property names to API property names.



24
25
26
27
28
29
# File 'lib/whats_app_cloud_api/models/section.rb', line 24

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['title'] = 'title'
  @_hash['rows'] = 'rows'
  @_hash
end

Instance Method Details

#nullablesObject

An array for nullable fields



40
41
42
# File 'lib/whats_app_cloud_api/models/section.rb', line 40

def nullables
  []
end

#optionalsObject

An array for optional fields



32
33
34
35
36
37
# File 'lib/whats_app_cloud_api/models/section.rb', line 32

def optionals
  %w[
    title
    rows
  ]
end