-
Notifications
You must be signed in to change notification settings - Fork 716
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #137 from sendgrid/unsubscribes
Added GET for suppressionn/unsubscribes
- Loading branch information
Showing
5 changed files
with
83 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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`_ | ||
----------------------- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |