forked from PagerDuty/go-pagerduty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
on_call.go
62 lines (52 loc) · 2.14 KB
/
on_call.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
package pagerduty
import (
"context"
"github.com/google/go-querystring/query"
)
// OnCall represents a contiguous unit of time for which a user will be on call for a given escalation policy and escalation rule.
type OnCall struct {
User User `json:"user,omitempty"`
Schedule Schedule `json:"schedule,omitempty"`
EscalationPolicy EscalationPolicy `json:"escalation_policy,omitempty"`
EscalationLevel uint `json:"escalation_level,omitempty"`
Start string `json:"start,omitempty"`
End string `json:"end,omitempty"`
}
// ListOnCallsResponse is the data structure returned from calling the ListOnCalls API endpoint.
type ListOnCallsResponse struct {
APIListObject
OnCalls []OnCall `json:"oncalls"`
}
// ListOnCallOptions is the data structure used when calling the ListOnCalls API endpoint.
type ListOnCallOptions struct {
APIListObject
TimeZone string `url:"time_zone,omitempty"`
Includes []string `url:"include,omitempty,brackets"`
UserIDs []string `url:"user_ids,omitempty,brackets"`
EscalationPolicyIDs []string `url:"escalation_policy_ids,omitempty,brackets"`
ScheduleIDs []string `url:"schedule_ids,omitempty,brackets"`
Since string `url:"since,omitempty"`
Until string `url:"until,omitempty"`
Earliest bool `url:"earliest,omitempty"`
}
// ListOnCalls list the on-call entries during a given time range. It's
// recommended to use ListOnCallsWithContext instead.
func (c *Client) ListOnCalls(o ListOnCallOptions) (*ListOnCallsResponse, error) {
return c.ListOnCallsWithContext(context.Background(), o)
}
// ListOnCallsWithContext list the on-call entries during a given time range.
func (c *Client) ListOnCallsWithContext(ctx context.Context, o ListOnCallOptions) (*ListOnCallsResponse, error) {
v, err := query.Values(o)
if err != nil {
return nil, err
}
resp, err := c.get(ctx, "/oncalls?"+v.Encode())
if err != nil {
return nil, err
}
var result ListOnCallsResponse
if err := c.decodeJSON(resp, &result); err != nil {
return nil, err
}
return &result, nil
}