Class: WhatsappSdk::Resource::ParameterObject

Inherits:
Object
  • Object
show all
Defined in:
lib/whatsapp_sdk/resource/parameter_object.rb

Defined Under Namespace

Modules: Format, Type Classes: InvalidType

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, text: nil, currency: nil, date_time: nil, image: nil, document: nil, video: nil, location: nil) ⇒ ParameterObject

Returns a new instance of ParameterObject.



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/whatsapp_sdk/resource/parameter_object.rb', line 95

def initialize(
  type:,
  text: nil,
  currency: nil,
  date_time: nil,
  image: nil,
  document: nil,
  video: nil,
  location: nil
)
  @type = type
  @text = text
  @currency = currency
  @date_time = date_time
  @image = image
  @document = document
  @video = video
  @location = location
  validate
end

Instance Attribute Details

#currencyObject

Returns Currency if the parameter object type is currency.



68
69
70
# File 'lib/whatsapp_sdk/resource/parameter_object.rb', line 68

def currency
  @currency
end

#date_timeObject

Returns date_time if the parameter object type is date_time.



73
74
75
# File 'lib/whatsapp_sdk/resource/parameter_object.rb', line 73

def date_time
  @date_time
end

#documentObject

Returns document if the parameter object type is document.



83
84
85
# File 'lib/whatsapp_sdk/resource/parameter_object.rb', line 83

def document
  @document
end

#imageObject

Returns image if the parameter object type is image.



78
79
80
# File 'lib/whatsapp_sdk/resource/parameter_object.rb', line 78

def image
  @image
end

#locationObject

Returns location if the parameter object type is location



93
94
95
# File 'lib/whatsapp_sdk/resource/parameter_object.rb', line 93

def location
  @location
end

#textObject

Returns Text string if the parameter object type is text. For the header component, the character limit is 60 characters. For the body component, the character limit is 1024 characters.



63
64
65
# File 'lib/whatsapp_sdk/resource/parameter_object.rb', line 63

def text
  @text
end

#typeObject

Returns the parameter type.



19
20
21
# File 'lib/whatsapp_sdk/resource/parameter_object.rb', line 19

def type
  @type
end

#videoObject

Returns video if the parameter object type is video.



88
89
90
# File 'lib/whatsapp_sdk/resource/parameter_object.rb', line 88

def video
  @video
end

Instance Method Details

#to_jsonObject



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/whatsapp_sdk/resource/parameter_object.rb', line 116

def to_json
  json = { type: type }
  json[type.to_sym] = case type
                      when "text"
                        text
                      when "currency"
                        currency.to_json
                      when "date_time"
                        date_time.to_json
                      when "image"
                        image.to_json
                      when "document"
                        document.to_json
                      when "video"
                        video.to_json
                      when "location"
                        location.to_json
                      else
                        raise "Invalid type: #{type}"
                      end

  json
end