-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pulses.go
54 lines (45 loc) · 1.16 KB
/
Pulses.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
package OtxApiClient
import (
"bytes"
"encoding/json"
"errors"
"log"
"net/http"
)
type pulsesService struct {
client *Client
}
type PulseIndicatorType string
const (
PulseIPv4Indicator PulseIndicatorType = "IPv4"
PulseHostnameIndicator PulseIndicatorType = "hostname"
)
var ErrInvalidResponse = errors.New("invalid response")
func (p *pulsesService) AddIndicator(pulseId string, indicator PulseIndicator) error {
editRequest := &PulseIndicatorEdit{Id: pulseId}
editRequest.Indicators.Add = []PulseIndicator{indicator}
postData, err := json.Marshal(editRequest)
log.Println(string(postData))
if err != nil {
return err
}
resp, err := p.client.doHttpRequest(http.MethodPatch, "/pulses/"+pulseId+"/", bytes.NewReader(postData))
if err != nil {
return err
}
if resp.StatusCode != 200 {
return ErrInvalidResponse
}
return nil
}
type PulseIndicatorEdit struct {
Id string `json:"id"`
Description string `json:"description,omitempty"`
Indicators struct {
Add []PulseIndicator `json:"add"`
} `json:"indicators"`
}
type PulseIndicator struct {
Type PulseIndicatorType `json:"type"`
Indicator string `json:"indicator"`
}