Class: WhatsAppCloudApi::Template

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

Overview

Template Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

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

#componentsList of Component

Array of components objects containing the parameters of the message.

Returns:



23
24
25
# File 'lib/whats_app_cloud_api/models/template.rb', line 23

def components
  @components
end

#languageLanguage

Specifies the language the template may be rendered in. Only the deterministic language policy works with media template messages.

Returns:



19
20
21
# File 'lib/whats_app_cloud_api/models/template.rb', line 19

def language
  @language
end

#nameString

Name of the template.

Returns:

  • (String)


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

.namesObject

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

#nullablesObject

An array for nullable fields



42
43
44
# File 'lib/whats_app_cloud_api/models/template.rb', line 42

def nullables
  []
end

#optionalsObject

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