Class: Whatsapp::Messages::Template::Parameter
- Inherits:
-
Object
- Object
- Whatsapp::Messages::Template::Parameter
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/ruby/whatsapp/messages/template/parameter.rb
Overview
Parameters for template components
Defined Under Namespace
Modules: Types
Instance Attribute Summary collapse
- #currency ⇒ Hash?
- #date_time ⇒ Hash?
- #document ⇒ Hash?
- #image ⇒ Hash?
- #location ⇒ Hash?
- #payload ⇒ String?
- #text ⇒ String?
- #type ⇒ String
- #video ⇒ Hash?
Instance Method Summary collapse
-
#initialize(type:, text: nil, currency: nil, date_time: nil, image: nil, document: nil, video: nil, location: nil, payload: nil) ⇒ Parameter
constructor
A new instance of Parameter.
-
#serialize ⇒ Hash
Serializes the parameter to a hash format suitable for the WhatsApp API.
Constructor Details
#initialize(type:, text: nil, currency: nil, date_time: nil, image: nil, document: nil, video: nil, location: nil, payload: nil) ⇒ Parameter
Returns a new instance of Parameter.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/ruby/whatsapp/messages/template/parameter.rb', line 69 def initialize(type:, text: nil, currency: nil, date_time: nil, image: nil, document: nil, video: nil, location: nil, payload: nil) @type = type @text = text @currency = currency @date_time = date_time @image = image @document = document @video = video @location = location @payload = payload validate! end |
Instance Attribute Details
#currency ⇒ Hash?
31 32 33 |
# File 'lib/ruby/whatsapp/messages/template/parameter.rb', line 31 def currency @currency end |
#date_time ⇒ Hash?
35 36 37 |
# File 'lib/ruby/whatsapp/messages/template/parameter.rb', line 35 def date_time @date_time end |
#document ⇒ Hash?
43 44 45 |
# File 'lib/ruby/whatsapp/messages/template/parameter.rb', line 43 def document @document end |
#image ⇒ Hash?
39 40 41 |
# File 'lib/ruby/whatsapp/messages/template/parameter.rb', line 39 def image @image end |
#location ⇒ Hash?
51 52 53 |
# File 'lib/ruby/whatsapp/messages/template/parameter.rb', line 51 def location @location end |
#payload ⇒ String?
55 56 57 |
# File 'lib/ruby/whatsapp/messages/template/parameter.rb', line 55 def payload @payload end |
#text ⇒ String?
27 28 29 |
# File 'lib/ruby/whatsapp/messages/template/parameter.rb', line 27 def text @text end |
#type ⇒ String
23 24 25 |
# File 'lib/ruby/whatsapp/messages/template/parameter.rb', line 23 def type @type end |
#video ⇒ Hash?
47 48 49 |
# File 'lib/ruby/whatsapp/messages/template/parameter.rb', line 47 def video @video end |
Instance Method Details
#serialize ⇒ Hash
Serializes the parameter to a hash format suitable for the WhatsApp API.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/ruby/whatsapp/messages/template/parameter.rb', line 86 def serialize result = { type: } case type when Types::TEXT result[:text] = text when Types::CURRENCY result[:currency] = currency when Types::DATE_TIME result[:date_time] = date_time when Types::IMAGE result[:image] = image when Types::DOCUMENT result[:document] = document when Types::VIDEO result[:video] = video when Types::LOCATION result[:location] = location when Types::PAYLOAD result[:payload] = payload end result.compact end |