88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
|
# File 'lib/plivo/resources/messages.rb', line 88
def create(src = nil, dst = nil, text = nil, options = nil, powerpack_uuid = nil)
value = src
if(value.is_a?(Hash))
valid_param?(:src, value[:src], [Integer, String, Symbol], false)
valid_param?(:text, value[:text], [String, Symbol], true)
valid_param?(:dst, value[:dst], [String, Array], true)
valid_param?(:powerpack_uuid, value[:powerpack_uuid], [String, Symbol], false)
if (value[:dst] == value[:src])
raise InvalidRequestError, 'src and dst cannot be same'
end
if value.key?(:value).nil? && value.key(:powerpack_uuid).nil?
raise InvalidRequestError, 'value and powerpack uuid both cannot be nil'
end
if !value.key?(:value).nil? && !value.key(:powerpack_uuid).nil?
raise InvalidRequestError, 'value and powerpack uuid both cannot be present'
end
if !value.key?(:dst).nil? && !value.key(:powerpack_uuid).nil?
raise InvalidRequestError, 'dst is a required parameter'
end
params = {
src: value[:src],
text: value[:text],
powerpack_uuid: value[:powerpack_uuid]
}
if (value[:dst].is_a?(Array))
value[:dst].each do |dst_num|
valid_param?(:dst_num, dst_num, [Integer, String, Symbol], true)
params[:dst] = value[:dst].join('<')
end
else
params[:dst] = value[:dst]
end
if value.key?(:type) && valid_param?(:type, value[:type],String, true, %w[sms mms])
params[:type] = value[:type]
end
if value.key?(:url) && valid_param?(:url, value[:url], String, true)
params[:url] = value[:url]
if value.key?(:method) &&
valid_param?(:method, value[:method], String, true, %w[POST GET])
params[:method] = value[:method]
else
params[:method] = 'POST'
end
end
if value.key?(:log) &&
valid_param?(:log, value[:log], [TrueClass, FalseClass], true)
params[:log] = value[:log]
end
if value.key?(:message_expiry) &&
valid_param?(:message_expiry, value[:message_expiry], [Integer, Integer], true)
params[:message_expiry] = value[:message_expiry]
end
if value.key?(:trackable) &&
valid_param?(:trackable, value[:trackable], [TrueClass, FalseClass], true)
params[:trackable] = value[:trackable]
end
if value.key?(:media_urls) &&
valid_param?(:media_urls, value[:media_urls], Array, true)
params[:media_urls] = value[:media_urls]
end
if value.key?(:media_ids) &&
valid_param?(:media_ids, value[:media_ids], Array, true)
params[:media_ids] = value[:media_ids]
end
if value.key?(:dlt_entity_id) &&
valid_param?(:dlt_entity_id, value[:dlt_entity_id], String, true)
params[:dlt_entity_id] = value[:dlt_entity_id]
end
if value.key?(:dlt_template_id) &&
valid_param?(:dlt_template_id, value[:dlt_template_id], String, true)
params[:dlt_template_id] = value[:dlt_template_id]
end
if value.key?(:dlt_template_category) &&
valid_param?(:dlt_template_category, value[:dlt_template_category], String, true)
params[:dlt_template_category] = value[:dlt_template_category]
end
else
valid_param?(:src, src, [Integer, String, Symbol], false)
valid_param?(:text, text, [String, Symbol], true)
valid_param?(:dst, dst, [String, Array], true)
valid_param?(:powerpack_uuid, powerpack_uuid, [String, Symbol], false)
dst.each do |dst_num|
valid_param?(:dst_num, dst_num, [Integer, String, Symbol], true)
end
if dst.include? src
raise InvalidRequestError, 'src and dst cannot be same'
end
if src.nil? && powerpack_uuid.nil?
raise InvalidRequestError, 'src and powerpack uuid both cannot be nil'
end
if !src.nil? && !powerpack_uuid.nil?
raise InvalidRequestError, 'src and powerpack uuid both cannot be present'
end
params = {
src: src,
text: text,
powerpack_uuid: powerpack_uuid
}
if (dst.is_a?(Array))
dst.each do |dst_num|
valid_param?(:dst_num, dst_num, [Integer, String, Symbol], true)
params[:dst] = dst.join('<')
end
else
params[:dst] = dst
end
return perform_create(params) if options.nil?
valid_param?(:options, options, Hash, true)
if options.key?(:type) &&
valid_param?(:type, options[:type], String, true, %w[sms mms])
params[:type] = options[:type]
end
if options.key?(:url) && valid_param?(:url, options[:url], String, true)
params[:url] = options[:url]
if options.key?(:method) &&
valid_param?(:method, options[:method], String, true, %w[POST GET])
params[:method] = options[:method]
else
params[:method] = 'POST'
end
end
if options.key?(:media_urls) &&
valid_param?(:media_urls, options[:media_urls], Array, true)
params[:media_urls] = options[:media_urls]
end
if options.key?(:media_ids) &&
valid_param?(:media_ids, options[:media_ids], Array, true)
params[:media_ids] = options[:media_ids]
end
if options.key?(:log) &&
valid_param?(:log, options[:log], [TrueClass, FalseClass], true)
params[:log] = options[:log]
end
if options.key?(:media_urls) &&
valid_param?(:media_urls, options[:media_urls], Array, true)
params[:media_urls] = options[:media_urls]
end
if options.key?(:media_ids) &&
valid_param?(:media_ids, options[:media_ids], Array, true)
params[:media_ids] = options[:media_ids]
end
if options.key?(:message_expiry) &&
valid_param?(:message_expiry, options[:message_expiry], [Integer, Integer], true)
params[:message_expiry] = options[:message_expiry]
end
if options.key?(:trackable) &&
valid_param?(:trackable, options[:trackable], [TrueClass, FalseClass], true)
params[:trackable] = options[:trackable]
end
if options.key?(:dlt_entity_id) &&
valid_param?(:dlt_entity_id, options[:dlt_entity_id], String, true)
params[:dlt_entity_id] = options[:dlt_entity_id]
end
if options.key?(:dlt_template_id) &&
valid_param?(:dlt_template_id, options[:dlt_template_id], String, true)
params[:dlt_template_id] = options[:dlt_template_id]
end
if options.key?(:dlt_template_category) &&
valid_param?(:dlt_template_category, options[:dlt_template_category], String, true)
params[:dlt_template_category] = options[:dlt_template_category]
end
end
perform_create(params)
end
|