Skip to content

Commit 731eae3

Browse files
committed
Merge pull request #47 from aydrian/ISSUE-16
Added Suppression List resource lib
2 parents 39b4581 + af4cea5 commit 731eae3

14 files changed

+467
-1
lines changed

docs/api/suppression_list.rst

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

docs/resources/suppression_list.rst

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
Suppression List
2+
================
3+
4+
Let's use the underlying `suppression_list API`_ to create a suppression entry:
5+
6+
.. code-block:: python
7+
8+
from sparkpost import SparkPost
9+
10+
sp = SparkPost()
11+
12+
response = sp.suppression_list.create({
13+
"email": "[email protected]"
14+
"transactional": False,
15+
"non_transactional": True,
16+
"description": "User requested to not receive any non-transactional emails."
17+
})
18+
19+
print response
20+
# outputs {u'message': u'Recipient successfully created'}
21+
22+
.. _suppression_list API: https://www.sparkpost.com/api#/reference/suppression-list
23+
24+
25+
Get a suppression entry
26+
-----------------------
27+
28+
.. code-block:: python
29+
30+
from sparkpost import SparkPost
31+
32+
sp = SparkPost()
33+
34+
sp.suppression_list.get('[email protected]')
35+
36+
37+
List suppression entries
38+
------------------------
39+
40+
.. code-block:: python
41+
42+
from sparkpost import SparkPost
43+
44+
sp = SparkPost()
45+
46+
sp.suppression_list.list()
47+
48+
49+
API reference
50+
-------------
51+
52+
:doc:`/api/suppression_list`
53+
54+
55+
Further examples
56+
----------------
57+
58+
See the `python-sparkpost suppression_list examples`_.
59+
60+
.. _python-sparkpost suppression_list examples: https://github.com/SparkPost/python-sparkpost/tree/master/examples/suppression_list
61+
62+
63+
Additional documentation
64+
------------------------
65+
66+
See the `SparkPost Suppression List API Reference`_.
67+
68+
.. _SparkPost Suppression List API Reference: https://www.sparkpost.com/api#/reference/suppression-list
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from sparkpost import SparkPost
2+
3+
sp = SparkPost('YOUR API KEY')
4+
recipients = [
5+
{
6+
'email': '[email protected]',
7+
'transactional': False,
8+
'non_transactional': True,
9+
'description': 'Test description 1'
10+
},
11+
{
12+
'email': '[email protected]',
13+
'transactional': True,
14+
'non_transactional': True,
15+
'description': 'Test description 2'
16+
},
17+
{
18+
'email': '[email protected]',
19+
'transactional': True,
20+
'non_transactional': False,
21+
'description': 'Test description 3'
22+
}
23+
]
24+
result = sp.suppression_list.create(recipients)
25+
print result
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from sparkpost import SparkPost
2+
3+
sp = SparkPost('YOUR API KEY')
4+
result = sp.suppression_list.create({
5+
'email': '[email protected]',
6+
'transactional': False,
7+
'non_transactional': True,
8+
'description': 'Test description'
9+
})
10+
print result
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+
result = sp.suppression_list.delete('[email protected]')
5+
print result
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+
entry = sp.suppression_list.get('[email protected]')
5+
print entry
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+
results = sp.suppression_list.list(
5+
from_date='2015-05-07T00:00:00+0000',
6+
to_date='2015-05-07T23:59:59+0000',
7+
limit=5
8+
)
9+
print results
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from sparkpost import SparkPost
2+
3+
sp = SparkPost('YOUR API KEY')
4+
recipients = [
5+
{
6+
'email': '[email protected]',
7+
'transactional': False,
8+
'non_transactional': True,
9+
'description': 'Test description 1'
10+
},
11+
{
12+
'email': '[email protected]',
13+
'transactional': True,
14+
'non_transactional': True,
15+
'description': 'Test description 2'
16+
},
17+
{
18+
'email': '[email protected]',
19+
'transactional': True,
20+
'non_transactional': False,
21+
'description': 'Test description 3'
22+
}
23+
]
24+
result = sp.suppression_list.update(recipients)
25+
print result
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from sparkpost import SparkPost
2+
3+
sp = SparkPost('YOUR API KEY')
4+
result = sp.suppression_list.update({
5+
'email': '[email protected]',
6+
'transactional': False,
7+
'non_transactional': True,
8+
'description': 'Test description'
9+
})
10+
print result

sparkpost/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from .exceptions import SparkPostException
44
from .metrics import Metrics
55
from .recipient_lists import RecipientLists
6+
from .suppression_list import SuppressionList
67
from .templates import Templates
78
from .transmissions import Transmissions
89

@@ -29,6 +30,7 @@ def __init__(self, api_key=None, base_uri='https://api.sparkpost.com',
2930

3031
self.metrics = Metrics(self.base_uri, self.api_key)
3132
self.recipient_lists = RecipientLists(self.base_uri, self.api_key)
33+
self.suppression_list = SuppressionList(self.base_uri, self.api_key)
3234
self.templates = Templates(self.base_uri, self.api_key)
3335
self.transmissions = Transmissions(self.base_uri, self.api_key)
3436
# Keeping self.transmission for backwards compatibility.

0 commit comments

Comments
 (0)