From 1f7360490e07d3b644585a9047562a1289a09028 Mon Sep 17 00:00:00 2001 From: Tim Heckman Date: Thu, 25 Feb 2021 17:56:48 -0800 Subject: [PATCH] Update notification.go to accept a context.Context Updates #267 --- notification.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/notification.go b/notification.go index 5e5e704e..6516ea06 100644 --- a/notification.go +++ b/notification.go @@ -31,16 +31,31 @@ type ListNotificationsResponse struct { Notifications []Notification } -// ListNotifications lists notifications for a given time range, optionally filtered by type (sms_notification, email_notification, phone_notification, or push_notification). +// ListNotifications lists notifications for a given time range, optionally +// filtered by type (sms_notification, email_notification, phone_notification, +// or push_notification). It's recommended to use ListNotificationsWithContext instead. func (c *Client) ListNotifications(o ListNotificationOptions) (*ListNotificationsResponse, error) { + return c.ListNotificationsWithContext(context.Background(), o) +} + +// ListNotificationsWithContext lists notifications for a given time range, +// optionally filtered by type (sms_notification, email_notification, +// phone_notification, or push_notification). +func (c *Client) ListNotificationsWithContext(ctx context.Context, o ListNotificationOptions) (*ListNotificationsResponse, error) { v, err := query.Values(o) if err != nil { return nil, err } - resp, err := c.get(context.TODO(), "/notifications?"+v.Encode()) + + resp, err := c.get(ctx, "/notifications?"+v.Encode()) if err != nil { return nil, err } + var result ListNotificationsResponse - return &result, c.decodeJSON(resp, &result) + if err := c.decodeJSON(resp, &result); err != nil { + return nil, err + } + + return &result, nil }