Skip to content

Commit 9135cc2

Browse files
committed
Added list example & fixed new calling method
1 parent 4e1ab48 commit 9135cc2

1 file changed

Lines changed: 24 additions & 6 deletions

File tree

examples/subscriptions_example.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
3) Use the tunnel HTTPS URL as notification_url pointing to /webhook, URL-encoded.
1111
4) To create a subscription, follow the example request below:
1212
- https://<your-tunnel-host>/subscriptions?notification_url=https%3A%2F%2F<your-tunnel-host>%2Fwebhook&client_state=abc123
13-
4) To renew a subscription, follow the example request below:
13+
5) To list subscriptions, follow the example request below:
14+
- http://<your-tunnel-host>/subscriptions/list
15+
6) To renew a subscription, follow the example request below:
1416
- http://<your-tunnel-host>/subscriptions/<subscription_id>/renew?expiration_minutes=55
15-
5) To delete a subscription, follow the example request below:
17+
7) To delete a subscription, follow the example request below:
1618
- http://<your-tunnel-host>/subscriptions/<subscription_id>/delete
1719
Graph will call https://<your-tunnel-host>/webhook; this app echoes validationToken and returns 202 for notifications.
1820
"""
@@ -38,7 +40,7 @@
3840
])
3941

4042
RESOURCE = "/me/mailFolders('inbox')/messages"
41-
DEFAULT_EXPIRATION_MINUTES = 2880
43+
DEFAULT_EXPIRATION_MINUTES = 10069 # Maximum expiration is 10,070 in the future.
4244

4345
app = Flask(__name__)
4446

@@ -63,7 +65,7 @@ def create_subscription():
6365
client_state = request.args.get("client_state")
6466
resource = request.args.get("resource", RESOURCE)
6567

66-
subscription = account.subscriptions.create_subscription(
68+
subscription = account.subscriptions().create_subscription(
6769
notification_url=notification_url,
6870
resource=resource,
6971
change_type="created",
@@ -73,10 +75,26 @@ def create_subscription():
7375
return jsonify(subscription), 201
7476

7577

78+
@app.get("/subscriptions/list")
79+
def list_subscriptions():
80+
limit_raw = request.args.get("limit")
81+
limit = None
82+
if limit_raw is not None:
83+
try:
84+
limit = int(limit_raw)
85+
except ValueError:
86+
abort(400, description="limit must be an integer")
87+
if limit <= 0:
88+
abort(400, description="limit must be a positive integer")
89+
90+
subscriptions = account.subscriptions().list_subscriptions(limit=limit)
91+
return jsonify(list(subscriptions)), 200
92+
93+
7694
@app.get("/subscriptions/<subscription_id>/renew")
7795
def renew_subscription(subscription_id: str):
7896
expiration_minutes = _int_arg("expiration_minutes", DEFAULT_EXPIRATION_MINUTES)
79-
updated = account.subscriptions.renew_subscription(
97+
updated = account.subscriptions().renew_subscription(
8098
subscription_id,
8199
expiration_minutes=expiration_minutes,
82100
)
@@ -85,7 +103,7 @@ def renew_subscription(subscription_id: str):
85103

86104
@app.get("/subscriptions/<subscription_id>/delete")
87105
def delete_subscription(subscription_id: str):
88-
deleted = account.subscriptions.delete_subscription(subscription_id)
106+
deleted = account.subscriptions().delete_subscription(subscription_id)
89107
if not deleted:
90108
abort(404, description="Subscription not found")
91109
return ("", 204)

0 commit comments

Comments
 (0)