Skip to content

Commit 9cbd8c2

Browse files
Merge pull request #136 from sendgrid/asm_global_suppressions_post
Added ASM Global Suppressions POST
2 parents 7182246 + dfe5c65 commit 9cbd8c2

File tree

5 files changed

+34
-5
lines changed

5 files changed

+34
-5
lines changed

README.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,13 @@ Check if a given email is on the global suppression list.
317317
client = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
318318
email = ['elmer@thinkingserious.com']
319319
status, msg = client.asm_global_suppressions.get(email)
320+
321+
Add an email to the global suppression list.
322+
323+
.. code:: python
324+
client = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
325+
email = ['elmer@thinkingserious.com']
326+
status, msg = client.asm_global_suppressions.post(email)
320327
321328
SendGrid's `X-SMTPAPI`_
322329
-----------------------

example_v2_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
sg = sendgrid.SendGridClient(os.environ.get('SENDGRID_USERNAME'), os.environ.get('SENDGRID_PASSWORD'))
1010

11+
"""
1112
message = sendgrid.Mail()
1213
message.add_to('Elmer Thomas <elmer@thinkingserious.com>')
1314
message.set_subject('Testing from the Python library')
@@ -16,4 +17,5 @@
1617
message.set_from('Elmer Thomas <dx@sendgrid.com>')
1718
status, msg = sg.send(message)
1819
print status
19-
print msg
20+
print msg
21+
"""

example_v3_test.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@
1010

1111
client = sendgrid.SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
1212

13+
"""
14+
15+
status, msg = client.asm_global_suppressions.post(['elmer.thomas+test_global0@gmail.com'])
16+
print status
17+
print msg
18+
1319
group_id = 70
1420
status, msg = client.asm_suppressions.get(group_id)
1521
print status
1622
print msg
1723
18-
"""
19-
2024
status, msg = client.asm_groups.post("Magic Key 2", "Unlock your Emails", False)
2125
print status
2226
print msg

sendgrid/resources/asm_global_suppressions.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,10 @@ def client(self):
3737
# Determine if an email belongs to the global suppression group
3838
def get(self, email=None):
3939
self._endpoint = self._base_endpoint + '/' + email
40-
return self.client.get(self)
40+
return self.client.get(self)
41+
42+
# Add an email to the global suppressions group
43+
def post(self, emails=None):
44+
data = {}
45+
data["recipient_emails"] = emails
46+
return self.client.post(self, data)

test/test_asm_global_suppressions.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,19 @@ def test_asm_global_suppressions_init(self):
2626
self.assertEqual(self.asm_global_suppressions.endpoint, "/v3/asm/suppressions/global")
2727
self.assertEqual(self.asm_global_suppressions.client, self.client)
2828

29-
def test_asm_suppressions_get(self):
29+
def test_asm_global_suppressions_get(self):
3030
status, msg = self.client.asm_global_suppressions.get('test@example.com')
3131
self.assertEqual(status, 200)
32+
33+
def test_asm_suppressions_post(self):
34+
emails = ['elmer+test@thinkingserious.com']
35+
status, msg = self.client.asm_global_suppressions.post(emails)
36+
self.assertEqual(status, 201)
37+
self.assertEqual(msg['recipient_emails'], emails)
38+
emails = ['elmer+test@thinkingserious.com', 'elmer.thomas@yahoo.com']
39+
status, msg = self.client.asm_global_suppressions.post(emails)
40+
self.assertEqual(status, 201)
41+
self.assertEqual(msg['recipient_emails'], emails)
3242

3343
if __name__ == '__main__':
3444
unittest.main()

0 commit comments

Comments
 (0)