Class: WhatsAppCloudApi::Component

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

Overview

Component Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(type = nil, parameters = nil, sub_type = nil, index = nil) ⇒ Component

Returns a new instance of Component.



56
57
58
59
60
61
62
63
64
# File 'lib/whats_app_cloud_api/models/component.rb', line 56

def initialize(type = nil,
               parameters = nil,
               sub_type = nil,
               index = nil)
  @type = type unless type == SKIP
  @sub_type = sub_type unless sub_type == SKIP
  @parameters = parameters unless parameters == SKIP
  @index = index unless index == SKIP
end

Instance Attribute Details

#indexString

Required when type=button. Not used for the other types. Position index of the button. You can have up to 3 buttons using index values of 0 to 2.

Returns:

  • (String)


31
32
33
# File 'lib/whats_app_cloud_api/models/component.rb', line 31

def index
  @index
end

#parametersList of Object

Required when type=button. Array of parameter objects with the content of the message. For components of type=button, see the button parameter object.

Returns:

  • (List of Object)


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

def parameters
  @parameters
end

#sub_typeSubTypeEnum

Required when type=button. Not used for the other types. Type of button to create.

Returns:



20
21
22
# File 'lib/whats_app_cloud_api/models/component.rb', line 20

def sub_type
  @sub_type
end

#typeComponentTypeEnum

Describes the component type. For text-based templates, we only support the type=body.

Returns:



15
16
17
# File 'lib/whats_app_cloud_api/models/component.rb', line 15

def type
  @type
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/whats_app_cloud_api/models/component.rb', line 67

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  type = hash.key?('type') ? hash['type'] : SKIP
  parameters = hash.key?('parameters') ? hash['parameters'] : SKIP
  sub_type = hash.key?('sub_type') ? hash['sub_type'] : SKIP
  index = hash.key?('index') ? hash['index'] : SKIP

  # Create object from extracted values.
  Component.new(type,
                parameters,
                sub_type,
                index)
end

.namesObject

A mapping from model property names to API property names.



34
35
36
37
38
39
40
41
# File 'lib/whats_app_cloud_api/models/component.rb', line 34

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['type'] = 'type'
  @_hash['sub_type'] = 'sub_type'
  @_hash['parameters'] = 'parameters'
  @_hash['index'] = 'index'
  @_hash
end

Instance Method Details

#nullablesObject

An array for nullable fields



52
53
54
# File 'lib/whats_app_cloud_api/models/component.rb', line 52

def nullables
  []
end

#optionalsObject

An array for optional fields



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

def optionals
  %w[
    sub_type
    index
  ]
end