Class: WhatsAppCloudApi::Action

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

Overview

Action Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(button = nil, buttons = nil, sections = nil) ⇒ Action

Returns a new instance of Action.



50
51
52
53
54
55
56
# File 'lib/whats_app_cloud_api/models/action.rb', line 50

def initialize(button = nil,
               buttons = nil,
               sections = nil)
  @button = button unless button == SKIP
  @buttons = buttons unless buttons == SKIP
  @sections = sections unless sections == SKIP
end

Instance Attribute Details

#buttonString

Required for List Messages. Button content. It cannot be an empty string and must be unique within the message. Emojis are supported, markdown is not.

Returns:

  • (String)


16
17
18
# File 'lib/whats_app_cloud_api/models/action.rb', line 16

def button
  @button
end

#buttonsList of Button

Required for Reply Buttons. You can have up to 3 buttons. You cannot have leading or trailing spaces when setting the ID.

Returns:



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

def buttons
  @buttons
end

#sectionsList of Section

Required for List Messages.

Returns:



25
26
27
# File 'lib/whats_app_cloud_api/models/action.rb', line 25

def sections
  @sections
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/whats_app_cloud_api/models/action.rb', line 59

def self.from_hash(hash)
  return nil unless hash

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

  buttons = SKIP unless hash.key?('buttons')
  # Parameter is an array, so we need to iterate through it
  sections = nil
  unless hash['sections'].nil?
    sections = []
    hash['sections'].each do |structure|
      sections << (Section.from_hash(structure) if structure)
    end
  end

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

  # Create object from extracted values.
  Action.new(button,
             buttons,
             sections)
end

.namesObject

A mapping from model property names to API property names.



28
29
30
31
32
33
34
# File 'lib/whats_app_cloud_api/models/action.rb', line 28

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['button'] = 'button'
  @_hash['buttons'] = 'buttons'
  @_hash['sections'] = 'sections'
  @_hash
end

Instance Method Details

#nullablesObject

An array for nullable fields



46
47
48
# File 'lib/whats_app_cloud_api/models/action.rb', line 46

def nullables
  []
end

#optionalsObject

An array for optional fields



37
38
39
40
41
42
43
# File 'lib/whats_app_cloud_api/models/action.rb', line 37

def optionals
  %w[
    button
    buttons
    sections
  ]
end