8000 Merge branch 'master' of github.com:twilio/twilio-python · randy3465/twilio-python@987ad19 · GitHub
[go: up one dir, main page]

Skip to content

Commit 987ad19

Browse files
author
Kevin Burke
committed
Merge branch 'master' of github.com:twilio/twilio-python
2 parents aa6e58b + f0403eb commit 987ad19

File tree

8 files changed

+66
-12
lines changed

8 files changed

+66
-12
lines changed

CHANGES.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ twilio-python Changelog
33

44
Here you can see the full list of changes between each twilio-python release.
55

6+
Version 3.6.4
7+
-------------
8+
9+
Released November 5, 2013
10+
11+
- Adds support for the 'digits' attribute of Play verbs in TwiML creation.
12+
- Updates documentation for Message TwiML verb
13+
- Bugfix for tty detection in error formatting
14+
615
Version 3.6.3
716
-------------
817

docs/api/twiml.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Secondary Verbs
4242
.. autoclass:: twilio.twiml.Pause
4343
:members:
4444

45-
.. autoclass:: twilio.twiml.Sms
45+
.. autoclass:: twilio.twiml.Message
4646
:members:
4747

4848
.. autoclass:: twilio.twiml.Enqueue

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
# The short X.Y version.
6060
version = '3.6'
6161
# The full version, including alpha/beta/rc tags.
62-
release = '3.6.3'
62+
release = '3.6.4'
6363

6464
# The language for content autogenerated by Sphinx. Refer to documentation
6565
# for a list of supported languages.

docs/usage/twiml.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,25 @@ All attributes are keyword arguments.
4545
<Play loop="3">https://api.twilio.com/cowbell.mp3</Play>
4646
<Response>
4747
48+
The Message and Sms verbs are slightly special: because :const:`from` is a
49+
Python keyword, use the :const:`sender` parameter to specify the number
50+
the message should come from:
51+
52+
.. code-block:: python
53+
54+
from twilio import twiml
55+
56+
r = twiml.Response()
57+
m = r.message("Hello MMS Monkey!", sender="+14155551234")
58+
print str(r)
59+
60+
.. code-block:: xml
61+
62+
<?xml version="1.0" encoding="utf-8"?>
63+
<Response>
64+
<Message from="+14155551234">Hello MMS Monkey!</Message>
65+
<Response>
66+
4867
Python 2.6+ added the :const:`with` statement for context management.
4968
Using :const:`with`, the module can *almost* emulate Ruby blocks.
5069

tests/test_twiml.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,16 @@ def testPlayBadAppend(self):
147147
""" should raise exceptions for wrong appending"""
148148
self.improperAppend(twiml.Play(""))
149149

150+
def testPlayDigits(self):
151+
"""should play digits"""
152+
r = Response()
153+
r.append(twiml.Play(digits='w123'))
154+
r = self.strip(r)
155+
self.assertEqual(r, '<?xml version="1.0" encoding="UTF-8"?><Response><Play digits="w123" /></Response>')
156+
157+
def testUrlOrDigitsRequired(self):
158+
self.assertRaises(TwimlException, twiml.Play)
159+
150160

151161
class TestRecord(TwilioTest):
152162

twilio/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version_info__ = ('3', '6', '3')
1+
__version_info__ = ('3', '6', '4')
22
__version__ = '.'.join(__version_info__)
33

44

twilio/rest/resources/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def teal(msg):
155155
# If it makes sense to print a human readable error message, try to do
156156
# it. The one problem is that someone might catch this error and try to
157157
# display the message from it to an end user.
158-
if sys.stderr.isatty():
158+
if hasattr(sys.stderr, 'isatty') and sys.stderr.isatty():
159159
msg = red("\nHTTP Error. ")
160160
msg += white("Your request was:\n\n")
161161
msg += teal("%s %s" % (method, uri))

twilio/twiml.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ def say(self, text, **kwargs):
114114
:class:`Response` """
115115
return self.append(Say(text, **kwargs))
116116

117-
def play(self, url, **kwargs):
117+
def play(self, url=None, digits=None, **kwargs):
118118
"""Return a newly created :class:`Play` verb, nested inside this
119119
:class:`Response` """
120-
return self.append(Play(url, **kwargs))
120+
return self.append(Play(url=url, digits=digits, **kwargs))
121121

122122
def pause(self, **kwargs):
123123
"""Return a newly created :class:`Pause` verb, nested inside this
@@ -237,18 +237,34 @@ def __init__(self, text, **kwargs):
237237

238238

239239
class Play(Verb):
240-
"""Play an audio file at a URL
240+
"""Play DTMF digits or audio from a URL.
241241
242-
:param url: point to af audio file. The MIME type on the file must be set
243-
correctly.
242+
:param str url: point to an audio file. The MIME type on the file must be
243+
set correctly. At least one of `url` and `digits` must be
244+
specified. If both are given, the digits will play prior
245+
to the audio from the URL.
244246
245-
:param loop: specifies how many times you'd like the text repeated.
247+
:param str digits: a string of digits to play. To pause before playing
248+
digits, use leading 'w' characters. Each 'w' will cause
249+
Twilio to wait 0.5 seconds instead of playing a digit.
250+
At least one of `url` and `digits` must be specified.
251+
If both are given, the digits will play first.
252+
253+
:param int loop: specifies how many times you'd like the text repeated.
246254
Specifying '0' will cause the the :class:`Play` verb to loop
247255
until the call is hung up. Defaults to 1.
248256
"""
249-
def __init__(self, url, **kwargs):
257+
def __init__(self, url=None, digits=None, **kwargs):
258+
if url is None and digits is None:
259+
raise TwimlException(
260+
"Please specify either a url or digits to play.",
261+
)
262+
263+
if digits is not None:
264+
kwargs['digits'] = digits
250265
super(Play, self).__init__(**kwargs)
251-
self.body = url
266+
if url is not None:
267+
self.body = url
252268

253269

254270
class Pause(Verb):

0 commit comments

Comments
 (0)
0