Skip to content

Commit 962e524

Browse files
author
Kevin Burke
committed
Document a whole bunch of functions
1 parent 53d161f commit 962e524

13 files changed

Lines changed: 182 additions & 82 deletions

File tree

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: clean venv install analysis test test-install
1+
.PHONY: clean venv install analysis test test-install docs
22

33
venv:
44
virtualenv venv
@@ -16,5 +16,8 @@ analysis:
1616
test: analysis
1717
. venv/bin/activate; nosetests
1818

19+
docs:
20+
. venv/bin/activate; cd docs && make html
21+
1922
clean:
2023
rm -rf venv

docs/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ clean:
3737
-rm -rf $(BUILDDIR)/*
3838

3939
html:
40-
pip install -r ../requirements.txt
4140
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
4241
@echo
4342
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."

docs/api/rest/index.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
===================================
2+
:mod:`twilio`
3+
===================================
4+
5+
.. module:: twilio
6+
7+
.. autoclass:: TwilioRestException
8+
:members:
9+
:inherited-members:
10+
111
.. module:: twilio.rest
212

313
==============================

docs/api/rest/resources.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
.. autoclass:: ListResource
88
:members: count, get, iter
99

10+
.. autoclass:: InstanceResource
11+
1012
Accounts
1113
>>>>>>>>>
1214

@@ -876,7 +878,7 @@ SMS Messages
876878

877879
.. attribute:: body
878880

879-
The text body of the SMS message. Up to 160 characters long.
881+
The text body of the SMS message.
880882

881883
.. attribute:: status
882884

docs/changelog.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
.. include:: ../CHANGES
1+
.. include:: ../CHANGES.md

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@
232232
epub_title = u'twilio-python'
233233
epub_author = u'kyle@twilio.com'
234234
epub_publisher = u'Twilio Inc.'
235-
epub_copyright = u'2010, Twilio Inc.'
235+
epub_copyright = u'2013, Twilio Inc.'
236236

237237
# The language of the text. It defaults to the language option
238238
# or en if the language is not set.

docs/index.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,24 @@ package manager for Python.
1212

1313
.. code-block:: bash
1414
15-
$ pip install twilio
15+
pip install twilio
1616
1717
Don't have pip installed? Try installing it, by running this from the command
1818
line:
1919

2020
.. code-block:: bash
2121
22-
$ curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python
22+
curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python
2323
2424
Or, install the library by downloading
2525
`the source <https://github.com/twilio/twilio-python/zipball/master>`_,
26-
installing :data:`setuptools`,
26+
installing `setuptools <http://pythonhosted.org/setuptools/>`_,
2727
navigating in the Terminal to the folder containing the **twilio-python**
2828
library, and then running:
2929

3030
.. code-block:: bash
3131
32-
$ python setup.py install
32+
python setup.py install
3333
3434
3535
Getting Started
@@ -146,7 +146,7 @@ All development occurs over on
146146

147147
.. code-block:: bash
148148
149-
$ git clone git@github.com:twilio/twilio-python.git
149+
git clone git@github.com:twilio/twilio-python.git
150150
151151
152152
Report bugs using the Github

docs/usage/messages.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ Send a text message in only a few lines of code.
2929
body="Hello!")
3030
3131
32-
.. note:: The message body must be less than 160 characters in length
33-
3432
If you want to send a message from a `short code
3533
<http://www.twilio.com/api/sms/short-codes>`_ on Twilio, just set :attr:`from_`
3634
to your short code's number.

twilio/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ class TwilioException(Exception):
77

88

99
class TwilioRestException(TwilioException):
10+
""" A generic 400 or 500 level exception from the Twilio API
11+
12+
:param int status: the HTTP status that was returned for the exception
13+
:param str uri: The URI that caused the exception
14+
:param str msg: A human-readable message for the error
15+
:param int|None code: A Twilio-specific error code for the error. This is not
16+
available for all errors.
17+
"""
18+
19+
# XXX: Move this to the twilio.rest folder
1020

1121
def __init__(self, status, uri, msg="", code=None):
1222
self.uri = uri

twilio/rest/__init__.py

Lines changed: 65 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
def find_credentials():
3030
"""
31-
Look in the current environment for Twilio credentails
31+
Look in the current environment for Twilio credentials
3232
"""
3333
try:
3434
account = os.environ["TWILIO_ACCOUNT_SID"]
@@ -41,59 +41,13 @@ def find_credentials():
4141
class TwilioRestClient(object):
4242
"""
4343
A client for accessing the Twilio REST API
44-
"""
45-
46-
def request(self, path, method=None, vars=None):
47-
"""sends a request and gets a response from the Twilio REST API
48-
49-
.. deprecated:: 3.0
50-
51-
:param path: the URL (relative to the endpoint URL, after the /v1
52-
:param url: the HTTP method to use, defaults to POST
53-
:param vars: for POST or PUT, a dict of data to send
54-
55-
:returns: Twilio response in XML or raises an exception on error
56-
57-
This method is only included for backwards compatability reasons.
58-
It will be removed in a future version
59-
"""
60-
logging.warning(":meth:`TwilioRestClient.request` is deprecated and "
61-
"will be removed in a future version")
62-
63-
vars = vars or {}
64-
params = None
65-
data = None
66-
67-
if not path or len(path) < 1:
68-
raise ValueError('Invalid path parameter')
69-
if method and method not in ['GET', 'POST', 'DELETE', 'PUT']:
70-
raise NotImplementedError(
71-
'HTTP %s method not implemented' % method)
72-
73-
if path[0] == '/':
74-
uri = self.base + path
75-
else:
76-
uri = self.base + '/' + path
77-
78-
if method == "GET":
79-
params = vars
80-
elif method == "POST" or method == "PUT":
81-
data = vars
8244
83-
user_agent = "twilio-python %s (python-%s)" % (
84-
LIBRARY_VERSION,
85-
platform.python_version(),
86-
)
87-
88-
headers = {
89-
"User-Agent": user_agent,
90-
"Accept-Charset": "utf-8",
91-
}
92-
93-
resp = make_request(method, uri, auth=self.auth, data=data,
94-
params=params, headers=headers)
95-
96-
return resp.content
45+
:param str account: Your Account SID from `your dashboard
46+
<https://twilio.com/user/account>`_
47+
:param str token: Your Auth Token from `your dashboard
48+
<https://twilio.com/user/account>`_
49+
:param float timeout: The socket and read timeout for making requests to Twilio
50+
"""
9751

9852
def __init__(self, account=None, token=None, base="https://api.twilio.com",
9953
version="2010-04-01", client=None, timeout=UNSET_TIMEOUT):
@@ -154,16 +108,70 @@ def __init__(self, account=None, token=None, base="https://api.twilio.com",
154108

155109
def participants(self, conference_sid):
156110
"""
157-
Return a :class:`Participants` instance for the :class:`Conference`
158-
with the given conference_sid
111+
Return a :class:`~twilio.rest.resources.Participants` instance for the
112+
:class:`~twilio.rest.resources.Conference` with the given conference_sid
159113
"""
160114
base_uri = "{}/Conferences/{}".format(self.account_uri, conference_sid)
161115
return Participants(base_uri, self.auth, self.timeout)
162116

163117
def members(self, queue_sid):
164118
"""
165-
Return a :class:`Members` instance for the :class:`Queue`
166-
with the given queue_sid
119+
Return a :class:`Members <twilio.rest.resources.Members>` instance for
120+
the :class:`Queue <twilio.rest.resources.Queue>` with the given queue_sid
167121
"""
168122
base_uri = "{}/Queues/{}".format(self.account_uri, queue_sid)
169123
return Members(base_uri, self.auth, self.timeout)
124+
125+
126+
def request(self, path, method=None, vars=None):
127+
"""sends a request and gets a response from the Twilio REST API
128+
129+
.. deprecated:: 3.0
130+
131+
:param path: the URL (relative to the endpoint URL, after the /v1
132+
:param url: the HTTP method to use, defaults to POST
133+
:param vars: for POST or PUT, a dict of data to send
134+
135+
:returns: Twilio response in XML or raises an exception on error
136+
137+
This method is only included for backwards compatability reasons.
138+
It will be removed in a future version
139+
"""
140+
logging.warning(":meth:`TwilioRestClient.request` is deprecated and "
141+
"will be removed in a future version")
142+
143+
vars = vars or {}
144+
params = None
145+
data = None
146+
147+
if not path or len(path) < 1:
148+
raise ValueError('Invalid path parameter')
149+
if method and method not in ['GET', 'POST', 'DELETE', 'PUT']:
150+
raise NotImplementedError(
151+
'HTTP %s method not implemented' % method)
152+
153+
if path[0] == '/':
154+
uri = self.base + path
155+
else:
156+
uri = self.base + '/' + path
157+
158+
if method == "GET":
159+
params = vars
160+
elif method == "POST" or method == "PUT":
161+
data = vars
162+
163+
user_agent = "twilio-python %s (python-%s)" % (
164+
LIBRARY_VERSION,
165+
platform.python_version(),
166+
)
167+
168+
headers = {
169+
"User-Agent": user_agent,
170+
"Accept-Charset": "utf-8",
171+
}
172+
173+
resp = make_request(method, uri, auth=self.auth, data=data,
174+
params=params, headers=headers)
175+
176+
return resp.content
177+

0 commit comments

Comments
 (0)