-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtriggers.go
50 lines (46 loc) · 1.24 KB
/
triggers.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
package parse
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
)
type TriggerFunction struct {
ClassName string `json:"className,omitempty"`
TriggerName string `json:"triggerName,omitempty"`
URL string `json:"url,omitempty"`
}
func (c *Client) GetTriggerFunctions() ([]*TriggerFunction, error) {
uri := fmt.Sprintf("/1/hooks/triggers")
resp, err := c.doSimple("GET", uri)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
var result struct {
TriggerFunctions []*TriggerFunction `json:"results"`
}
c.trace("GetTriggerFunctions", uri, string(body))
return result.TriggerFunctions, json.Unmarshal(body, &result)
}
func (c *Client) CreateTriggerFunction(fn *TriggerFunction) error {
payload, err := json.Marshal(fn)
c.trace("CreateTriggerFunction >", "/1/hooks/triggers", string(payload))
resp, err := c.doWithBody("POST", "/1/hooks/triggers", bytes.NewReader(payload))
if err != nil {
return err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
var response interface{}
err = json.Unmarshal(body, &response)
c.trace("CreateTriggerFunction <", "/1/hooks/triggers", string(body))
return err
}