forked from PagerDuty/go-pagerduty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
notification.go
83 lines (70 loc) · 2.96 KB
/
notification.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package pagerduty
import (
"context"
"github.com/google/go-querystring/query"
)
// Notification is a message containing the details of the incident.
type Notification struct {
ID string `json:"id"`
Type string `json:"type"`
StartedAt string `json:"started_at"`
Address string `json:"address"`
User APIObject `json:"user"`
ConferenceAddress string `json:"conferenceAddress"`
Status string `json:"status"`
}
// ListNotificationOptions is the data structure used when calling the ListNotifications API endpoint.
type ListNotificationOptions struct {
// Limit is the pagination parameter that limits the number of results per
// page. PagerDuty defaults this value to 25 if omitted, and sets an upper
// bound of 100.
Limit uint `url:"limit,omitempty"`
// Offset is the pagination parameter that specifies the offset at which to
// start pagination results. When trying to request the next page of
// results, the new Offset value should be currentOffset + Limit.
Offset uint `url:"offset,omitempty"`
// Total is the pagination parameter to request that the API return the
// total count of items in the response. If this field is omitted or set to
// false, the total number of results will not be sent back from the PagerDuty API.
//
// Setting this to true will slow down the API response times, and so it's
// recommended to omit it unless you've a specific reason for wanting the
// total count of items in the collection.
Total bool `url:"total,omitempty"`
TimeZone string `url:"time_zone,omitempty"`
Since string `url:"since,omitempty"`
Until string `url:"until,omitempty"`
Filter string `url:"filter,omitempty"`
Includes []string `url:"include,omitempty,brackets"`
}
// ListNotificationsResponse is the data structure returned from the ListNotifications API endpoint.
type ListNotificationsResponse struct {
APIListObject
Notifications []Notification
}
// ListNotifications lists notifications for a given time range, optionally
// filtered by type (sms_notification, email_notification, phone_notification,
// or push_notification).
//
// Deprecated: 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(ctx, "/notifications?"+v.Encode())
if err != nil {
return nil, err
}
var result ListNotificationsResponse
if err := c.decodeJSON(resp, &result); err != nil {
return nil, err
}
return &result, nil
}