Skip to content

Commit a943d7d

Browse files
Merge pull request #125 from thinkingserious/asm_suppressions_delete
Asm suppressions delete
2 parents cf3c155 + 12f1a53 commit a943d7d

4 files changed

Lines changed: 52 additions & 2 deletions

File tree

README.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,36 @@ Get a single record.
261261
.. code:: python
262262
263263
status, msg = client.asm_groups.get(record_id)
264+
265+
ASM Suppressions
266+
~~~~~~~~~~~~~~~~
267+
268+
Suppressions are email addresses that can be added to groups to prevent certain types of emails from being delivered to those addresses.
269+
270+
Add recipient addresses to the suppressions list for a given group.
271+
272+
.. code:: python
273+
274+
client = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
275+
group_id = <group_id_number> # If no group_id_number, the emails will be added to the global suppression group
276+
emails = ['elmer+test@thinkingserious.com', 'elmer+test2@thinkingserious.com']
277+
status, msg = client.asm_suppressions.post(group_id, emails)
278+
279+
Get suppressed addresses for a given group.
280+
281+
.. code:: python
282+
283+
status, msg = client.asm_suppressions.get(<group_id>)
284+
285+
Get suppression groups associated with a given recipient address.
286+
287+
.. code:: python
288+
289+
status, msg = client.asm_suppressions.get(None,<email_address>)
290+
291+
Delete a recipient email from the suppressions list for a group.
292+
293+
status, msg = client.asm_suppressions.delete(<group_id>,<email_address>)
264294

265295
SendGrid's `X-SMTPAPI`_
266296
-----------------------

example_v3_test.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,17 @@
1212

1313
client = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
1414

15-
status, msg = client.asm_suppressions.post(60, ['elmer+test@thinkingserious.com', 'elmer.thomas@yahoo.com'])
15+
status, msg = client.asm_suppressions.delete(67,'elmer+test@thinkingserious.com')
1616
print status
1717
print msg
1818

1919
"""
2020
21+
status, msg = client.asm_suppressions.post(60, ['elmer+test@thinkingserious.com', 'elmer.thomas@yahoo.com'])
22+
print status
23+
print msg
24+
25+
2126
status, msg = client.asm_suppressions.get(None,'elmer.thomas@yahoo.com')
2227
print status
2328
print msg

sendgrid/resources/asm_suppressions.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,9 @@ def post(self, id, emails):
5555
self._endpoint = self._base_endpoint + "/" + str(id) + "/suppressions"
5656
data = {}
5757
data["recipient_emails"] = emails
58-
return self.client.post(self, data)
58+
return self.client.post(self, data)
59+
60+
# Delete a recipient email from the suppressions list for a group.
61+
def delete(self, id, email):
62+
self.endpoint = self._base_endpoint + "/" + str(id) + "/suppressions/" + email
63+
return self.client.delete(self)

test/test_asm_suppressions.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ def test_asm_suppressions_post(self):
3636
status, msg = self.client.asm_suppressions.post(id, emails)
3737
self.assertEqual(status, 201)
3838
self.assertEqual(msg['recipient_emails'], emails)
39+
emails = ['elmer+test@thinkingserious.com', 'elmer.thomas@yahoo.com']
40+
status, msg = self.client.asm_suppressions.post(id, emails)
41+
self.assertEqual(status, 201)
42+
self.assertEqual(msg['recipient_emails'], emails)
43+
44+
def test_asm_supressions_delete(self):
45+
id = 67
46+
email = 'elmer+test@thinkingserious.com'
47+
status, msg = self.client.asm_suppressions.delete(id, email)
48+
self.assertEqual(status, 204)
3949

4050
if __name__ == '__main__':
4151
unittest.main()

0 commit comments

Comments
 (0)