-
Notifications
You must be signed in to change notification settings - Fork 3
/
eventapi_webhooks.go
51 lines (43 loc) · 1004 Bytes
/
eventapi_webhooks.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
package webapi
import (
"encoding/json"
model "github.com/raceresult/go-model"
)
// WebHooks contains all api endpoints regarding webhooks
type WebHooks struct {
api *EventAPI
}
// newWebHooks creates a new WebHooks api endpoint group
func newWebHooks(api *EventAPI) *WebHooks {
return &WebHooks{
api: api,
}
}
// Get returns all webhooks
func (q *WebHooks) Get() ([]model.WebHook, error) {
bts, err := q.api.get("webhooks/get", nil)
if err != nil {
return nil, err
}
var dest []model.WebHook
if err := json.Unmarshal(bts, &dest); err != nil {
return nil, err
}
return dest, nil
}
// Delete deletes webhooks
func (q *WebHooks) Delete(id int) error {
values := urlValues{
"id": id,
}
_, err := q.api.get("webhooks/delete", values)
return err
}
// Save saves webhooks and returns the IDs
func (q *WebHooks) Save(items []model.WebHook) ([]int, error) {
bts, err := q.api.post("webhooks/save", nil, items)
if err != nil {
return nil, err
}
return parseJsonIntArr(bts)
}