Skip to content

Commit 4f37988

Browse files
committed
Merge pull request #40 from aydrian/ISSUE-14
Added Templates resource lib
2 parents d2af4f9 + 28a7278 commit 4f37988

15 files changed

+530
-2
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,6 @@ venv/
5959

6060
# autoenv
6161
.env
62+
63+
# Mac OSX
64+
.DS_Store

AUTHORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Core contributors
22
-----------------
33

44
- Bob Evans <[email protected]> `@bizob2828 <https://github.com/bizob2828>`_
5+
- Aydrian Howard <[email protected]> `@aydrian <https://github.com/aydrian>`_
56
- Rich Leland <[email protected]> `@richleland <https://github.com/richleland>`_
67

78

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

examples/templates/create_template.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from sparkpost import SparkPost
2+
3+
sp = SparkPost('YOUR API KEY')
4+
response = sp.templates.create(
5+
id='TEST_ID',
6+
name='Test Template',
7+
from_email='[email protected]',
8+
subject='Test email template!',
9+
html='<b>This is a test email template!</b>'
10+
)
11+
print response

examples/templates/delete_template.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from sparkpost import SparkPost
2+
3+
sp = SparkPost('YOUR API KEY')
4+
template = sp.transmission.delete('template_id')
5+
print template

examples/templates/get_template.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from sparkpost import SparkPost
2+
3+
sp = SparkPost('YOUR API KEY')
4+
template = sp.transmission.get('template_id')
5+
print template

examples/templates/list_templates.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from sparkpost import SparkPost
2+
3+
sp = SparkPost('YOUR API KEY')
4+
template_list = sp.templates.list()
5+
print template_list
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from sparkpost import SparkPost
2+
3+
sp = SparkPost('YOUR API KEY')
4+
sub_data = {
5+
'first_name': 'John',
6+
'last_name': 'Doe'
7+
}
8+
template = sp.transmission.preview('template_id', sub_data, True)
9+
print template

0 commit comments

Comments
 (0)