Class: WhatsAppCloudApi::Header

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

Overview

Header 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, text = nil, video = nil, image = nil, document = nil) ⇒ Header

Returns a new instance of Header.



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/whats_app_cloud_api/models/header.rb', line 62

def initialize(type = nil,
               text = nil,
               video = nil,
               image = nil,
               document = nil)
  @type = type unless type == SKIP
  @text = text unless text == SKIP
  @video = video unless video == SKIP
  @image = image unless image == SKIP
  @document = document unless document == SKIP
end

Instance Attribute Details

#documentDocument

Required if type is set to document. Contains the media object for this document.

Returns:



34
35
36
# File 'lib/whats_app_cloud_api/models/header.rb', line 34

def document
  @document
end

#imageImage

Required if type is set to image. Contains the media object for this image.

Returns:



29
30
31
# File 'lib/whats_app_cloud_api/models/header.rb', line 29

def image
  @image
end

#textString

Required if type is set to text. Text for the header. Formatting allows emojis, but not markdown.

Returns:

  • (String)


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

def text
  @text
end

#typeHeaderTypeEnum

The header type you would like to use.

Returns:



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

def type
  @type
end

#videoVideo

Required if type is set to video. Contains the media object for this video.

Returns:



24
25
26
# File 'lib/whats_app_cloud_api/models/header.rb', line 24

def video
  @video
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/whats_app_cloud_api/models/header.rb', line 75

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.

  type = hash.key?('type') ? hash['type'] : SKIP
  text = hash.key?('text') ? hash['text'] : SKIP
  video = Video.from_hash(hash['video']) if hash['video']
  image = Image.from_hash(hash['image']) if hash['image']
  document = Document.from_hash(hash['document']) if hash['document']

  # Create object from extracted values.

  Header.new(type,
             text,
             video,
             image,
             document)
end

.namesObject

A mapping from model property names to API property names.



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

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['type'] = 'type'
  @_hash['text'] = 'text'
  @_hash['video'] = 'video'
  @_hash['image'] = 'image'
  @_hash['document'] = 'document'
  @_hash
end

Instance Method Details

#nullablesObject

An array for nullable fields



58
59
60
# File 'lib/whats_app_cloud_api/models/header.rb', line 58

def nullables
  []
end

#optionalsObject

An array for optional fields



48
49
50
51
52
53
54
55
# File 'lib/whats_app_cloud_api/models/header.rb', line 48

def optionals
  %w[
    text
    video
    image
    document
  ]
end