-
Notifications
You must be signed in to change notification settings - Fork 0
/
incidents.go
102 lines (89 loc) · 3.14 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package reamaze
import (
"encoding/json"
"errors"
"net/http"
"net/url"
"reflect"
)
// GetIncidents will allow you to retrieve the incidents for the Brand
// https://www.reamaze.com/api/get_incidents
func (c *Client) GetIncidents() (*GetIncidentsResponse, error) {
var response *GetIncidentsResponse
urlEndpoint := incidentsEndpoint
resp, err := c.reamazeRequest(http.MethodGet, urlEndpoint, []byte{})
if err != nil {
return nil, err
}
err = json.Unmarshal(resp, &response)
if err != nil {
return nil, err
}
return response, nil
}
// GetIncidents will allow you to retrieve the incidents for the Brand
// https://www.reamaze.com/api/get_incident
func (c *Client) GetIncident(identifier string) (*GetIncidentResponse, error) {
var response *GetIncidentResponse
if len(identifier) == 0 {
return nil, errors.New("GetIncident identifier cannot be empty, please provide identifier as argument")
}
urlEndpoint := incidentsEndpoint + "/" + url.PathEscape(identifier)
resp, err := c.reamazeRequest(http.MethodGet, urlEndpoint, []byte{})
if err != nil {
return nil, err
}
err = json.Unmarshal(resp, &response)
if err != nil {
return nil, err
}
return response, nil
}
// UpdateIncident will allow you to retrieve the incidents for the Brand
// https://www.reamaze.com/api/put_incident
func (c *Client) UpdateIncident(identifier string, req *UpdateIncidentRequest) (*UpdateIncidentResponse, error) {
var response *UpdateIncidentResponse
emptyReq := &UpdateIncidentRequest{}
// checking if we don't have empty request
if reflect.DeepEqual(req, emptyReq) {
return nil, errors.New("UpdateIncident incorrect request, UpdateIncidentRequest is empty")
}
if len(identifier) == 0 {
return nil, errors.New("UpdateIncident identifier cannot be empty, please provide identifier as argument")
}
urlEndpoint := incidentsEndpoint + "/" + url.PathEscape(identifier)
data, _ := json.Marshal(req)
resp, err := c.reamazeRequest(http.MethodPut, urlEndpoint, data)
if err != nil {
return nil, err
}
err = json.Unmarshal(resp, &response)
if err != nil {
return nil, err
}
return response, nil
}
// CreateIncident will allow you to create a new incident
// https://www.reamaze.com/api/post_incident
// The incidents_systems_attributes attribute is optional.
// The status attribute in updates_attributes can be one of the following: [investigating, identified, monitoring, resolved]
// The status attribute in incidents_systems_attributes can be one of the following: [operational, degraded_performance, partial_outage, major_outage, under_maintenance]
func (c *Client) CreateIncident(req *CreateIncidentRequest) (*CreateIncidentResponse, error) {
var response *CreateIncidentResponse
emptyReq := &CreateIncidentRequest{}
// checking if we don't have empty request
if reflect.DeepEqual(req, emptyReq) {
return nil, errors.New("CreateIncident incorrect request, CreateIncidentRequest is empty")
}
urlEndpoint := incidentsEndpoint
data, _ := json.Marshal(req)
resp, err := c.reamazeRequest(http.MethodPost, urlEndpoint, data)
if err != nil {
return nil, err
}
err = json.Unmarshal(resp, &response)
if err != nil {
return nil, err
}
return response, nil
}