Skip to content

Commit 28a7278

Browse files
committed
Added spinx docs and updated draft parameter
1 parent cc97a32 commit 28a7278

File tree

5 files changed

+87
-11
lines changed

5 files changed

+87
-11
lines changed

docs/api/templates.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.. module:: sparkpost.templates
2+
3+
:mod:`sparkpost.templates`
4+
=============================
5+
6+
.. autoclass:: Templates
7+
:members:

docs/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Alternatively, you can pass the API key to the SparkPost class:
3232
3333
from sparkpost import SparkPost
3434
sp = SparkPost('YOUR API KEY')
35-
35+
3636
.. _API & SMTP: https://app.sparkpost.com/configuration/credentials
3737

3838

@@ -45,6 +45,7 @@ The following resources are available in python-sparkpost:
4545
:maxdepth: 1
4646

4747
resources/metrics
48+
resources/templates
4849
resources/transmissions
4950

5051

@@ -77,4 +78,3 @@ Contribute
7778

7879
.. _`the repository`: http://github.com/SparkPost/python-sparkpost
7980
.. _AUTHORS: https://github.com/SparkPost/python-sparkpost/blob/master/AUTHORS.rst
80-

docs/resources/templates.rst

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
Templates
2+
=============
3+
4+
Let's use the underlying `templates API`_ to create a template:
5+
6+
.. code-block:: python
7+
8+
from sparkpost import SparkPost
9+
10+
sp = SparkPost()
11+
12+
response = sp.templates.create(
13+
id='TEST_ID',
14+
name='Test Template',
15+
from_email='[email protected]',
16+
subject='Test email template!',
17+
html='<b>This is a test email template!</b>'
18+
)
19+
20+
print response
21+
# outputs {u'id': u'TEST_ID'}
22+
23+
.. _templates API: https://www.sparkpost.com/api#/reference/templates
24+
25+
26+
Retrieve a template
27+
-----------------------
28+
29+
.. code-block:: python
30+
31+
from sparkpost import SparkPost
32+
33+
sp = SparkPost()
34+
35+
sp.templates.get('my-template-id')
36+
37+
38+
List all templates
39+
----------------------
40+
41+
.. code-block:: python
42+
43+
from sparkpost import SparkPost
44+
45+
sp = SparkPost()
46+
47+
sp.templates.list()
48+
49+
50+
API reference
51+
-------------
52+
53+
:doc:`/api/templates`
54+
55+
56+
Further examples
57+
----------------
58+
59+
See the `python-sparkpost templates examples`_.
60+
61+
.. _python-sparkpost templates examples: https://github.com/SparkPost/python-sparkpost/tree/master/examples/templates
62+
63+
64+
Additional documentation
65+
------------------------
66+
67+
See the `SparkPost Templates API Reference`_.
68+
69+
.. _SparkPost Templates API Reference: https://www.sparkpost.com/api#/reference/templates

sparkpost/templates.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,12 @@ def delete(self, template_id):
124124
results = self.request('DELETE', uri)
125125
return results
126126

127-
def get(self, template_id, is_draft=None):
127+
def get(self, template_id, draft=None):
128128
"""
129129
Get a template by ID
130130
131131
:param str template_id: ID of the template you want to retrieve
132-
:param bool is_draft: Defaults to None. If True, returns the most
132+
:param bool draft: Defaults to None. If True, returns the most
133133
recent draft template. If False, returns the most recent published
134134
template. If None, returns the most recent template version
135135
regardless of draft or published.
@@ -139,8 +139,8 @@ def get(self, template_id, is_draft=None):
139139
"""
140140
uri = "%s/%s" % (self.uri, template_id)
141141
params = {}
142-
if is_draft is not None:
143-
params['draft'] = str(is_draft).lower()
142+
if draft is not None:
143+
params['draft'] = str(draft).lower()
144144
results = self.request('GET', uri, params=params)
145145
return results
146146

@@ -154,15 +154,15 @@ def list(self):
154154
results = self.request('GET', self.uri)
155155
return results
156156

157-
def preview(self, template_id, substitution_data, is_draft=None):
157+
def preview(self, template_id, substitution_data, draft=None):
158158
"""
159159
Get a preivew of your template by ID with the
160160
provided substitution_data
161161
162162
:param str template_id: ID of the template you want to retrieve
163163
:param dict substitution_data: data to be substituted in the
164164
template content
165-
:param bool is_draft: Defaults to None. If True, previews the most
165+
:param bool draft: Defaults to None. If True, previews the most
166166
recent draft template. If False, previews the most recent published
167167
template. If None, previews the most recent template version
168168
regardless of draft or published.
@@ -173,8 +173,8 @@ def preview(self, template_id, substitution_data, is_draft=None):
173173
"""
174174
uri = "%s/%s/preview" % (self.uri, template_id)
175175
params = {}
176-
if is_draft is not None:
177-
params['draft'] = str(is_draft).lower()
176+
if draft is not None:
177+
params['draft'] = str(draft).lower()
178178
results = self.request('POST',
179179
uri,
180180
params=params,

test/test_templates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def test_success_preview():
179179

180180

181181
@responses.activate
182-
def test_success_preview_with_is_draft():
182+
def test_success_preview_with_draft():
183183
responses.add(
184184
responses.POST,
185185
'https://api.sparkpost.com/api/v1/templates/foobar/preview?draft=true',

0 commit comments

Comments
 (0)