@@ -12,13 +12,24 @@ class TwimlException(Exception):
12
12
class Verb (object ):
13
13
"""Twilio basic verb object.
14
14
"""
15
+ GET = "GET"
16
+ POST = "POST"
17
+ nestables = None
18
+
15
19
def __init__ (self , ** kwargs ):
16
20
self .name = self .__class__ .__name__
17
21
self .body = None
18
- self .nestables = None
19
22
self .verbs = []
20
23
self .attrs = {}
21
24
25
+ if kwargs .get ("waitMethod" , "GET" ) not in ["GET" , "POST" ]:
26
+ raise TwimlException ("Invalid waitMethod parameter, "
27
+ "must be 'GET' or 'POST'" )
28
+
29
+ if kwargs .get ("method" , "GET" ) not in ["GET" , "POST" ]:
30
+ raise TwimlException ("Invalid method parameter, "
31
+ "must be 'GET' or 'POST'" )
32
+
22
33
for k , v in kwargs .items ():
23
34
if k == "sender" :
24
35
k = "from"
@@ -70,6 +81,7 @@ def xml(self):
70
81
return el
71
82
72
83
def append (self , verb ):
84
+ print self .nestables
73
85
if not self .nestables or verb .name not in self .nestables :
74
86
raise TwimlException ("%s is not nestable inside %s" % \
75
87
(verb .name , self .name ))
@@ -79,22 +91,22 @@ def append(self, verb):
79
91
80
92
class Response (Verb ):
81
93
"""Twilio response object."""
94
+ nestables = [
95
+ 'Say' ,
96
+ 'Play' ,
97
+ 'Gather' ,
98
+ 'Record' ,
99
+ 'Dial' ,
100
+ 'Redirect' ,
101
+ 'Pause' ,
102
+ 'Hangup' ,
103
+ 'Reject' ,
104
+ 'Sms' ,
105
+ ]
106
+
82
107
def __init__ (self , ** kwargs ):
83
108
"""Version: Twilio API version e.g. 2008-08-01 """
84
-
85
- Verb .__init__ (self , ** kwargs )
86
- self .nestables = [
87
- 'Say' ,
88
- 'Play' ,
89
- 'Gather' ,
90
- 'Record' ,
91
- 'Dial' ,
92
- 'Redirect' ,
93
- 'Pause' ,
94
- 'Hangup' ,
95
- 'Reject' ,
96
- 'Sms' ,
97
- ]
109
+ super (Response , self ).__init__ (** kwargs )
98
110
99
111
def say (self , text , ** kwargs ):
100
112
"""Return a newly created :class:`Say` verb, nested inside this
@@ -203,11 +215,11 @@ class Say(Verb):
203
215
FRENCH = 'fr'
204
216
GERMAN = 'de'
205
217
206
- def __init__ (self , text , voice = None , language = None , loop = None , ** kwargs ):
207
- Verb .__init__ (self , voice = voice , language = language , loop = loop ,
208
- ** kwargs )
218
+ def __init__ (self , text , ** kwargs ):
219
+ super (Say , self ).__init__ (** kwargs )
209
220
self .body = text
210
221
222
+
211
223
class Play (Verb ):
212
224
"""Play an audio file at a URL
213
225
@@ -218,8 +230,8 @@ class Play(Verb):
218
230
Specifying '0' will cause the the :class:`Say` verb to loop
219
231
until the call is hung up. Defaults to 1.
220
232
"""
221
- def __init__ (self , url , loop = None , ** kwargs ):
222
- Verb . __init__ ( self , loop = loop , ** kwargs )
233
+ def __init__ (self , url , ** kwargs ):
234
+ super ( Play , self ). __init__ ( ** kwargs )
223
235
self .body = url
224
236
225
237
@@ -229,8 +241,6 @@ class Pause(Verb):
229
241
:param length: specifies how many seconds Twilio will wait silently before
230
242
continuing on.
231
243
"""
232
- def __init__ (self , length = None , ** kwargs ):
233
- Verb .__init__ (self , length = length , ** kwargs )
234
244
235
245
236
246
class Redirect (Verb ):
@@ -244,26 +254,21 @@ class Redirect(Verb):
244
254
GET = 'GET'
245
255
POST = 'POST'
246
256
247
- def __init__ (self , url = "" , method = None , ** kwargs ):
248
- Verb .__init__ (self , method = method , ** kwargs )
249
- if method and method not in [self .GET , self .POST ]:
250
- raise TwimlException ( \
251
- "Invalid method parameter, must be 'GET' or 'POST'" )
257
+ def __init__ (self , url = "" , ** kwargs ):
258
+ super (Redirect , self ).__init__ (** kwargs )
252
259
self .body = url
253
260
254
261
255
262
class Hangup (Verb ):
256
263
"""Hangup the call
257
264
"""
258
- def __init__ (self , ** kwargs ):
259
- Verb .__init__ (self )
260
265
261
266
262
267
class Reject (Verb ):
263
268
"""Hangup the call
269
+
270
+ :param reason: not sure
264
271
"""
265
- def __init__ (self , reason = None , ** kwargs ):
266
- Verb .__init__ (self , reason = reason , ** kwargs )
267
272
268
273
269
274
class Gather (Verb ):
@@ -277,17 +282,10 @@ class Gather(Verb):
277
282
"""
278
283
GET = 'GET'
279
284
POST = 'POST'
285
+ nestables = ['Say' , 'Play' , 'Pause' ]
280
286
281
- def __init__ (self , action = None , method = None , numDigits = None , timeout = None ,
282
- finishOnKey = None , ** kwargs ):
283
-
284
- Verb .__init__ (self , action = action , method = method ,
285
- numDigits = numDigits , timeout = timeout , finishOnKey = finishOnKey ,
286
- ** kwargs )
287
- if method and (method != self .GET and method != self .POST ):
288
- raise TwimlException ( \
289
- "Invalid method parameter, must be 'GET' or 'POST'" )
290
- self .nestables = ['Say' , 'Play' , 'Pause' ]
287
+ def __init__ (self , ** kwargs ):
288
+ super (Gather , self ).__init__ (** kwargs )
291
289
292
290
def say (self , text , ** kwargs ):
293
291
return self .append (Say (text , ** kwargs ))
@@ -314,8 +312,8 @@ class Number(Verb):
314
312
:param number: phone number to dial
315
313
:param sendDigits: key to press after connecting to the number
316
314
"""
317
- def __init__ (self , number , sendDigits = None , ** kwargs ):
318
- Verb . __init__ ( self , sendDigits = sendDigits , ** kwargs )
315
+ def __init__ (self , number , ** kwargs ):
316
+ super ( Number , self ). __init__ ( ** kwargs )
319
317
self .body = number
320
318
321
319
@@ -325,7 +323,7 @@ class Client(Verb):
325
323
:param name: Client name to connect to
326
324
"""
327
325
def __init__ (self , name , ** kwargs ):
328
- Verb . __init__ ( self , ** kwargs )
326
+ super ( Client , self ). __init__ ( ** kwargs )
329
327
self .body = name
330
328
331
329
@@ -341,13 +339,8 @@ class Sms(Verb):
341
339
GET = 'GET'
342
340
POST = 'POST'
343
341
344
- def __init__ (self , msg , to = None , sender = None , method = None , action = None ,
345
- statusCallback = None , ** kwargs ):
346
- Verb .__init__ (self , action = action , method = method , to = to , sender = sender ,
347
- statusCallback = statusCallback , ** kwargs )
348
- if method and (method != self .GET and method != self .POST ):
349
- raise TwimlException ( \
350
- "Invalid method parameter, must be GET or POST" )
342
+ def __init__ (self , msg , ** kwargs ):
343
+ super (Sms , self ).__init__ (** kwargs )
351
344
self .body = msg
352
345
353
346
@@ -365,16 +358,8 @@ class Conference(Verb):
365
358
GET = 'GET'
366
359
POST = 'POST'
367
360
368
- def __init__ (self , name , muted = None , beep = None ,
369
- startConferenceOnEnter = None , endConferenceOnExit = None , waitUrl = None ,
370
- waitMethod = None , maxParticipants = None , ** kwargs ):
371
- Verb .__init__ (self , muted = muted , beep = beep ,
372
- startConferenceOnEnter = startConferenceOnEnter ,
373
- endConferenceOnExit = endConferenceOnExit , waitUrl = waitUrl ,
374
- waitMethod = waitMethod , maxParticipants = maxParticipants , ** kwargs )
375
- if waitMethod and (waitMethod != self .GET and waitMethod != self .POST ):
376
- raise TwimlException ( \
377
- "Invalid waitMethod parameter, must be GET or POST" )
361
+ def __init__ (self , name , ** kwargs ):
362
+ super (Conference , self ).__init__ (** kwargs )
378
363
self .body = name
379
364
380
365
@@ -383,21 +368,25 @@ class Dial(Verb):
383
368
384
369
:param action: submit the result of the dial to this URL
385
370
:param method: submit to 'action' url using GET or POST
371
+ :param time timeout: The number of seconds to waits for the called
372
+ party to answer the call
373
+ :param bool hangupOnStar: Allow the calling party to hang up on the
374
+ called party by pressing the '*' key
375
+ :param int timeLimit: The maximum duration of the Call in seconds
376
+ :param callerId: The caller ID that will appear to the called party
377
+ :param bool record: Record both legs of a call within this <Dial>
386
378
"""
387
379
GET = 'GET'
388
380
POST = 'POST'
381
+ nestables = ['Number' , 'Conference' , 'Client' ]
389
382
390
- def __init__ (self , number = None , action = None , method = None , ** kwargs ):
391
- Verb .__init__ (self , action = action , method = method , ** kwargs )
392
- self .nestables = ['Number' , 'Conference' , 'Client' ]
383
+ def __init__ (self , number = None , ** kwargs ):
384
+ super (Dial , self ).__init__ (** kwargs )
393
385
if number and len (number .split (',' )) > 1 :
394
386
for n in number .split (',' ):
395
387 self .append (Number (n .strip ()))
396
388
else :
397
389
self .body = number
398
- if method and (method != self .GET and method != self .POST ):
399
- raise TwimlException ( \
400
- "Invalid method parameter, must be GET or POST" )
401
390
402
391
def client (self , name , ** kwargs ):
403
392
return self .append (Client (name , ** kwargs ))
@@ -425,14 +414,3 @@ class Record(Verb):
425
414
"""
426
415
GET = 'GET'
427
416
POST = 'POST'
428
-
429
- def __init__ (self , action = None , method = None , timeout = None ,
430
- finishOnKey = None , maxLength = None , transcribe = None ,
431
- transcribeCallback = None , playBeep = None , ** kwargs ):
432
- Verb .__init__ (self , action = action , method = method , timeout = timeout ,
433
- finishOnKey = finishOnKey , maxLength = maxLength ,
434
- transcribe = transcribe , transcribeCallback = transcribeCallback ,
435
- playBeep = playBeep , ** kwargs )
436
- if method and (method != self .GET and method != self .POST ):
437
- raise TwimlException ( \
438
- "Invalid method parameter, must be GET or POST" )
0 commit comments