diff --git a/README.rst b/README.rst index 2f7c3065a..589923bf9 100644 --- a/README.rst +++ b/README.rst @@ -321,9 +321,18 @@ Check if a given email is on the global suppression list. Add an email to the global suppression list. .. code:: python - client = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY')) - email = ['elmer@thinkingserious.com'] - status, msg = client.asm_global_suppressions.post(email) + client = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY')) + email = ['elmer@thinkingserious.com'] + status, msg = client.asm_global_suppressions.post(email) + +Suppression Unsubscribes +~~~~~~~~~~~~~~~~~~~~~~~~ + +Get a list of all SendGrid globally unsubscribed emails. + +.. code:: python + client = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY')) + status, msg = client.suppressions.get() SendGrid's `X-SMTPAPI`_ ----------------------- diff --git a/example_v3_test.py b/example_v3_test.py index bfe2832c1..6474d1f87 100755 --- a/example_v3_test.py +++ b/example_v3_test.py @@ -12,6 +12,10 @@ """ +status, msg = client.suppressions.get() +print status +print msg + status, msg = client.asm_global_suppressions.post(['elmer.thomas+test_global0@gmail.com']) print status print msg diff --git a/sendgrid/client.py b/sendgrid/client.py index 2c490bc95..f16bc6cde 100644 --- a/sendgrid/client.py +++ b/sendgrid/client.py @@ -15,6 +15,7 @@ from .resources.asm_groups import ASMGroups from .resources.asm_suppressions import ASMSuppressions from .resources.asm_global_suppressions import ASMGlobalSuppressions +from .resources.suppressions import Suppressions class SendGridAPIClient(object): @@ -38,6 +39,7 @@ def __init__(self, apikey, **opts): self.asm_groups = ASMGroups(self) self.asm_suppressions = ASMSuppressions(self) self.asm_global_suppressions = ASMGlobalSuppressions(self) + self.suppressions = Suppressions(self) @property def apikey(self): diff --git a/sendgrid/resources/suppressions.py b/sendgrid/resources/suppressions.py new file mode 100644 index 000000000..73816f742 --- /dev/null +++ b/sendgrid/resources/suppressions.py @@ -0,0 +1,31 @@ +class Suppressions(object): + + def __init__(self, client, **opts): + """ + Constructs SendGrid Suppressions object + """ + self._name = None + self._base_endpoint = "/v3/suppression/unsubscribes" + self._endpoint = "/v3/suppression/unsubscribes" + self._client = client + + @property + def base_endpoint(self): + return self._base_endpoint + + @property + def endpoint(self): + endpoint = self._endpoint + return endpoint + + @endpoint.setter + def endpoint(self, value): + self._endpoint = value + + @property + def client(self): + return self._client + + # Get all global suppressions + def get(self): + return self.client.get(self) \ No newline at end of file diff --git a/test/test_suppressions.py b/test/test_suppressions.py new file mode 100644 index 000000000..5389bb14c --- /dev/null +++ b/test/test_suppressions.py @@ -0,0 +1,34 @@ +from .base_test import BaseTest, MockSendGridAPIClientRequest +import os +try: + import unittest2 as unittest +except ImportError: + import unittest +try: + from StringIO import StringIO +except ImportError: # Python 3 + from io import StringIO + +import sendgrid +from sendgrid.client import SendGridAPIClient +from sendgrid.version import __version__ + +SG_KEY = os.getenv('SG_KEY') or 'SENDGRID_APIKEY' + +class TestSuppressions(unittest.TestCase): + def setUp(self): + SendGridAPIClient = MockSendGridAPIClientRequest + self.client = SendGridAPIClient(SG_KEY) + + def test_suppressions_init(self): + self.suppressions = self.client.suppressions + self.assertEqual(self.suppressions.base_endpoint, "/v3/suppression/unsubscribes") + self.assertEqual(self.suppressions.endpoint, "/v3/suppression/unsubscribes") + self.assertEqual(self.suppressions.client, self.client) + + def test_suppressions_get(self): + status, msg = self.client.suppressions.get() + self.assertEqual(status, 200) + +if __name__ == '__main__': + unittest.main() \ No newline at end of file