Class: WhatsAppCloudApi::Template
- Defined in:
- lib/whats_app_cloud_api/models/template.rb
Overview
Template Model.
Instance Attribute Summary collapse
-
#components ⇒ List of Component
Array of components objects containing the parameters of the message.
-
#language ⇒ Language
Specifies the language the template may be rendered in.
-
#name ⇒ String
Name of the template.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
-
.names ⇒ Object
A mapping from model property names to API property names.
Instance Method Summary collapse
-
#initialize(name = nil, language = nil, components = nil) ⇒ Template
constructor
A new instance of Template.
-
#nullables ⇒ Object
An array for nullable fields.
-
#optionals ⇒ Object
An array for optional fields.
Methods inherited from BaseModel
Constructor Details
#initialize(name = nil, language = nil, components = nil) ⇒ Template
Returns a new instance of Template.
46 47 48 49 50 51 52 |
# File 'lib/whats_app_cloud_api/models/template.rb', line 46 def initialize(name = nil, language = nil, components = nil) @name = name unless name == SKIP @language = language unless language == SKIP @components = components unless components == SKIP end |
Instance Attribute Details
#components ⇒ List of Component
Array of components objects containing the parameters of the message.
23 24 25 |
# File 'lib/whats_app_cloud_api/models/template.rb', line 23 def components @components end |
#language ⇒ Language
Specifies the language the template may be rendered in. Only the deterministic language policy works with media template messages.
19 20 21 |
# File 'lib/whats_app_cloud_api/models/template.rb', line 19 def language @language end |
#name ⇒ String
Name of the template.
14 15 16 |
# File 'lib/whats_app_cloud_api/models/template.rb', line 14 def name @name end |
Class Method Details
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/whats_app_cloud_api/models/template.rb', line 55 def self.from_hash(hash) return nil unless hash # Extract variables from the hash. name = hash.key?('name') ? hash['name'] : SKIP language = Language.from_hash(hash['language']) if hash['language'] # Parameter is an array, so we need to iterate through it components = nil unless hash['components'].nil? components = [] hash['components'].each do |structure| components << (Component.from_hash(structure) if structure) end end components = SKIP unless hash.key?('components') # Create object from extracted values. Template.new(name, language, components) end |
.names ⇒ Object
A mapping from model property names to API property names.
26 27 28 29 30 31 32 |
# File 'lib/whats_app_cloud_api/models/template.rb', line 26 def self.names @_hash = {} if @_hash.nil? @_hash['name'] = 'name' @_hash['language'] = 'language' @_hash['components'] = 'components' @_hash end |
Instance Method Details
#nullables ⇒ Object
An array for nullable fields
42 43 44 |
# File 'lib/whats_app_cloud_api/models/template.rb', line 42 def nullables [] end |
#optionals ⇒ Object
An array for optional fields
35 36 37 38 39 |
# File 'lib/whats_app_cloud_api/models/template.rb', line 35 def optionals %w[ components ] end |