-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhooks.go
49 lines (45 loc) · 1.16 KB
/
hooks.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
package parse
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
)
type HookFunction struct {
FunctionName string `json:"functionName,omitempty"`
URL string `json:"url,omitempty"`
}
func (c *Client) GetHookFunctions() ([]*HookFunction, error) {
uri := fmt.Sprintf("/1/hooks/functions")
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 {
HookFunctions []*HookFunction `json:"results"`
}
c.trace("GetHookFunctions", uri, string(body))
return result.HookFunctions, json.Unmarshal(body, &result)
}
func (c *Client) CreateHookFunction(fn *HookFunction) error {
payload, err := json.Marshal(fn)
c.trace("CreateHookFunction >", "/1/hooks/functions", string(payload))
resp, err := c.doWithBody("POST", "/1/hooks/functions", 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("CreateUser <", "/1/hooks/functions", string(body))
return err
}