Class: WhatsAppCloudApi::Parameter

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

Overview

Parameter 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, currency = nil, date_time = nil, image = nil, document = nil, video = nil) ⇒ Parameter

Returns a new instance of Parameter.



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

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

Instance Attribute Details

#currencyCurrency

Required when type=currency.

Returns:



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

def currency
  @currency
end

#date_timeDateTimeObject

Required when type=date_time.

Returns:



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

def date_time
  @date_time
end

#documentDocument

Required when type=document. Only PDF documents are supported for media-based message templates.

Returns:



38
39
40
# File 'lib/whats_app_cloud_api/models/parameter.rb', line 38

def document
  @document
end

#imageImage

Required when type=image.

Returns:



33
34
35
# File 'lib/whats_app_cloud_api/models/parameter.rb', line 33

def image
  @image
end

#textString

Required when type=text. The message’s text. For the header component, the character limit is 60 characters. For the body component, the character limit is 1024 characters.

Returns:

  • (String)


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

def text
  @text
end

#typeParameterTypeEnum

Describes the parameter type. For text-based templates, the only supported parameter types are text, currency, date_time.

Returns:



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

def type
  @type
end

#videoVideo

Required when type=video.

Returns:



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

def video
  @video
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/whats_app_cloud_api/models/parameter.rb', line 91

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
  currency = Currency.from_hash(hash['currency']) if hash['currency']
  date_time = DateTimeObject.from_hash(hash['date_time']) if hash['date_time']
  image = Image.from_hash(hash['image']) if hash['image']
  document = Document.from_hash(hash['document']) if hash['document']
  video = Video.from_hash(hash['video']) if hash['video']

  # Create object from extracted values.
  Parameter.new(type,
                text,
                currency,
                date_time,
                image,
                document,
                video)
end

.namesObject

A mapping from model property names to API property names.



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/whats_app_cloud_api/models/parameter.rb', line 45

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

Instance Method Details

#nullablesObject

An array for nullable fields



70
71
72
# File 'lib/whats_app_cloud_api/models/parameter.rb', line 70

def nullables
  []
end

#optionalsObject

An array for optional fields



58
59
60
61
62
63
64
65
66
67
# File 'lib/whats_app_cloud_api/models/parameter.rb', line 58

def optionals
  %w[
    text
    currency
    date_time
    image
    document
    video
  ]
end