Skip to content

Commit ddf473b

Browse files
Merge pull request #137 from sendgrid/unsubscribes
Added GET for suppressionn/unsubscribes
2 parents 7f30b43 + 4b2d4f5 commit ddf473b

File tree

5 files changed

+83
-3
lines changed

5 files changed

+83
-3
lines changed

README.rst

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,18 @@ Check if a given email is on the global suppression list.
321321
Add an email to the global suppression list.
322322

323323
.. code:: python
324-
client = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
325-
email = ['[email protected]']
326-
status, msg = client.asm_global_suppressions.post(email)
324+
client = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
325+
email = ['[email protected]']
326+
status, msg = client.asm_global_suppressions.post(email)
327+
328+
Suppression Unsubscribes
329+
~~~~~~~~~~~~~~~~~~~~~~~~
330+
331+
Get a list of all SendGrid globally unsubscribed emails.
332+
333+
.. code:: python
334+
client = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
335+
status, msg = client.suppressions.get()
327336
328337
SendGrid's `X-SMTPAPI`_
329338
-----------------------

example_v3_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212

1313
"""
1414
15+
status, msg = client.suppressions.get()
16+
print status
17+
print msg
18+
1519
status, msg = client.asm_global_suppressions.post(['[email protected]'])
1620
print status
1721
print msg

sendgrid/client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from .resources.asm_groups import ASMGroups
1616
from .resources.asm_suppressions import ASMSuppressions
1717
from .resources.asm_global_suppressions import ASMGlobalSuppressions
18+
from .resources.suppressions import Suppressions
1819

1920
class SendGridAPIClient(object):
2021

@@ -38,6 +39,7 @@ def __init__(self, apikey, **opts):
3839
self.asm_groups = ASMGroups(self)
3940
self.asm_suppressions = ASMSuppressions(self)
4041
self.asm_global_suppressions = ASMGlobalSuppressions(self)
42+
self.suppressions = Suppressions(self)
4143

4244
@property
4345
def apikey(self):

sendgrid/resources/suppressions.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
class Suppressions(object):
2+
3+
def __init__(self, client, **opts):
4+
"""
5+
Constructs SendGrid Suppressions object
6+
"""
7+
self._name = None
8+
self._base_endpoint = "/v3/suppression/unsubscribes"
9+
self._endpoint = "/v3/suppression/unsubscribes"
10+
self._client = client
11+
12+
@property
13+
def base_endpoint(self):
14+
return self._base_endpoint
15+
16+
@property
17+
def endpoint(self):
18+
endpoint = self._endpoint
19+
return endpoint
20+
21+
@endpoint.setter
22+
def endpoint(self, value):
23+
self._endpoint = value
24+
25+
@property
26+
def client(self):
27+
return self._client
28+
29+
# Get all global suppressions
30+
def get(self):
31+
return self.client.get(self)

test/test_suppressions.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from .base_test import BaseTest, MockSendGridAPIClientRequest
2+
import os
3+
try:
4+
import unittest2 as unittest
5+
except ImportError:
6+
import unittest
7+
try:
8+
from StringIO import StringIO
9+
except ImportError: # Python 3
10+
from io import StringIO
11+
12+
import sendgrid
13+
from sendgrid.client import SendGridAPIClient
14+
from sendgrid.version import __version__
15+
16+
SG_KEY = os.getenv('SG_KEY') or 'SENDGRID_APIKEY'
17+
18+
class TestSuppressions(unittest.TestCase):
19+
def setUp(self):
20+
SendGridAPIClient = MockSendGridAPIClientRequest
21+
self.client = SendGridAPIClient(SG_KEY)
22+
23+
def test_suppressions_init(self):
24+
self.suppressions = self.client.suppressions
25+
self.assertEqual(self.suppressions.base_endpoint, "/v3/suppression/unsubscribes")
26+
self.assertEqual(self.suppressions.endpoint, "/v3/suppression/unsubscribes")
27+
self.assertEqual(self.suppressions.client, self.client)
28+
29+
def test_suppressions_get(self):
30+
status, msg = self.client.suppressions.get()
31+
self.assertEqual(status, 200)
32+
33+
if __name__ == '__main__':
34+
unittest.main()

0 commit comments

Comments
 (0)