Skip to content

Commit cc7eb14

Browse files
Merge pull request #133 from sendgrid/unsubscribe-groups-post
Added ASM groups POST
2 parents 15e001a + 0c0927a commit cc7eb14

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

README.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,12 @@ Get a single record.
273273
274274
status, msg = client.asm_groups.get(record_id)
275275
276+
Create a new suppression group.
277+
278+
.. code:: python
279+
280+
status, msg = client.asm_groups.post(name, description, is_default)
281+
276282
ASM Suppressions
277283
~~~~~~~~~~~~~~~~
278284

example_v3_test.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,28 @@
1010

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

13+
status, msg = client.asm_groups.post("Magic Key 2", "Unlock your Emails", False)
14+
print status
15+
print msg
16+
17+
status, msg = client.asm_groups.get()
18+
print status
19+
print msg
20+
21+
"""
22+
23+
status, msg = client.asm_groups.get()
24+
print status
25+
print msg
26+
27+
status, msg = client.asm_groups.post("Magic Key", "Unlock your Emails")
28+
print status
29+
print msg
30+
31+
status, msg = client.asm_groups.get()
32+
print status
33+
print msg
34+
1335
# In the global suppression list
1436
status, msg = client.asm_global_suppressions.get('[email protected]')
1537
print status
@@ -20,7 +42,6 @@
2042
print status
2143
print msg
2244
23-
"""
2445
status, msg = client.apikeys.get()
2546
print status
2647
print msg

sendgrid/resources/asm_groups.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,13 @@ def get(self, id=None):
5353
self._endpoint = self._endpoint + "&id=" + str(i)
5454
count = count + 1
5555

56-
return self.client.get(self)
56+
return self.client.get(self)
57+
58+
# Create a new unsubscribe group
59+
def post(self, name, description, is_default):
60+
self._endpoint = self._base_endpoint
61+
data = {}
62+
data["name"] = name
63+
data["description"] = description
64+
data["is_default"] = is_default
65+
return self.client.post(self, data)

test/test_asm_groups.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ def test_asm_groups_init(self):
2929
def test_asm_groups_get(self):
3030
status, msg = self.client.asm_groups.get()
3131
self.assertEqual(status, 200)
32+
33+
def test_asm_groups_post(self):
34+
name = "Marketing"
35+
description = "Marketing emails"
36+
is_default = True
37+
status, msg = self.client.asm_groups.post(name, description, is_default)
38+
self.assertEqual(status, 201)
3239

3340
if __name__ == '__main__':
3441
unittest.main()

0 commit comments

Comments
 (0)