Skip to content

Commit

Permalink
Merge pull request #137 from sendgrid/unsubscribes
Browse files Browse the repository at this point in the history
Added GET for suppressionn/unsubscribes
  • Loading branch information
thinkingserious committed Oct 26, 2015
2 parents 7f30b43 + 4b2d4f5 commit ddf473b
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 3 deletions.
15 changes: 12 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ['[email protected]']
status, msg = client.asm_global_suppressions.post(email)
client = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
email = ['[email protected]']
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`_
-----------------------
Expand Down
4 changes: 4 additions & 0 deletions example_v3_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

"""
status, msg = client.suppressions.get()
print status
print msg
status, msg = client.asm_global_suppressions.post(['[email protected]'])
print status
print msg
Expand Down
2 changes: 2 additions & 0 deletions sendgrid/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand All @@ -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):
Expand Down
31 changes: 31 additions & 0 deletions sendgrid/resources/suppressions.py
Original file line number Diff line number Diff line change
@@ -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)
34 changes: 34 additions & 0 deletions test/test_suppressions.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit ddf473b

Please sign in to comment.