forked from andygrunwald/go-incident
-
Notifications
You must be signed in to change notification settings - Fork 1
/
incidents.go
61 lines (50 loc) · 1.5 KB
/
incidents.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
package incident
import (
"context"
"fmt"
)
// IncidentsService handles communication with the incident related
// methods of the Incident.io API.
//
// API docs: https://api-docs.incident.io/#tag/Incidents
type IncidentsService service
// List list all incidents for an organisation.
//
// API docs: https://api-docs.incident.io/#operation/Incidents_List
func (s *IncidentsService) List(ctx context.Context, opts *IncidentsListOptions) (*IncidentsList, *Response, error) {
u := "incidents"
u, err := addOptions(u, opts)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
v := &IncidentsList{}
resp, err := s.client.Do(ctx, req, v)
if err != nil {
return nil, resp, err
}
return v, resp, nil
}
// Get returns a single incident.
//
// id represents the unique identifier for the incident
//
// API docs: https://api-docs.incident.io/#operation/Incidents_Show
func (s *IncidentsService) Get(ctx context.Context, id string) (*IncidentResponse, *Response, error) {
u := fmt.Sprintf("incidents/%s", id)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
// TODO Should we return the incident directly? Would be more userfriendly - Maybe talking to the Incident.io folks?
v := &IncidentResponse{}
resp, err := s.client.Do(ctx, req, v)
if err != nil {
return nil, resp, err
}
return v, resp, nil
}
// TODO Add Create Incident: https://api-docs.incident.io/#operation/Incidents_Create