|
| 1 | +import json |
| 2 | + |
| 3 | + |
| 4 | +class SubscriptionList(object): |
| 5 | + """ |
| 6 | + Subscribe or unsubscribe channels to/from Subscription lists. These lists must |
| 7 | + be created in the Airship web dashboard prior to making these calls. The |
| 8 | + value for list_id can be found after creating these lists. |
| 9 | +
|
| 10 | + :param airship: Required. An urbanairship.Airship instance. |
| 11 | + :param list_id: Required. The list_id from the Airship web dashboard. |
| 12 | + """ |
| 13 | + |
| 14 | + def __init__(self, airship, list_id): |
| 15 | + self.airship = airship |
| 16 | + self.list_id = list_id |
| 17 | + |
| 18 | + def unsubscribe(self, audience): |
| 19 | + """ |
| 20 | + Unsubscribe an audience from a subscription list. |
| 21 | +
|
| 22 | + :param audience: Required. A single audience selector (ex: |
| 23 | + urbanairship.ios_channel) to unsubscribe. |
| 24 | + """ |
| 25 | + payload = { |
| 26 | + "subscription_lists": {"action": "unsubscribe", "list_id": self.list_id}, |
| 27 | + "audience": audience, |
| 28 | + } |
| 29 | + |
| 30 | + response = self.airship.request( |
| 31 | + method="POST", |
| 32 | + body=json.dumps(payload).encode("utf-8"), |
| 33 | + url=self.airship.urls.get("subscription_lists_url"), |
| 34 | + version=3, |
| 35 | + ) |
| 36 | + |
| 37 | + return response |
| 38 | + |
| 39 | + def subscribe(self, audience): |
| 40 | + """ |
| 41 | + Subscribe an audience from a subscription list. |
| 42 | +
|
| 43 | + :param list_id: Required. The list_id from the Airship web dashboard. |
| 44 | + :param audience: Required. A single audience selector (ex: |
| 45 | + urbanairship.ios_channel) to subscribe. |
| 46 | + """ |
| 47 | + payload = { |
| 48 | + "subscription_lists": {"action": "subscribe", "list_id": self.list_id}, |
| 49 | + "audience": audience, |
| 50 | + } |
| 51 | + |
| 52 | + response = self.airship.request( |
| 53 | + method="POST", |
| 54 | + body=json.dumps(payload).encode("utf-8"), |
| 55 | + url=self.airship.urls.get("subscription_lists_url"), |
| 56 | + version=3, |
| 57 | + ) |
| 58 | + |
| 59 | + return response |
0 commit comments