Skip to content

Commit

Permalink
Merge pull request #288 from PagerDuty/ctx_notification
Browse files Browse the repository at this point in the history
Update notification.go to accept a context.Context
  • Loading branch information
Scott McAllister authored Mar 10, 2021
2 parents 2d1e08e + 1f73604 commit a470c85
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit a470c85

Please sign in to comment.