-
Notifications
You must be signed in to change notification settings - Fork 2
/
dashboard.go
64 lines (57 loc) · 1.45 KB
/
dashboard.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
package adafruitio
type Dashboard struct {
Name string `json:"name"`
Description string `json:"description"`
Key string `json:"key"`
Blocks []Block `json:"blocks"`
}
func (c *Client) ListDashboards(u string) ([]Dashboard, error) {
var dashboards []Dashboard
resp, err := c.get("/" + u + "/dashboards")
if resp != nil {
defer resp.Body.Close()
}
if err != nil {
return dashboards, err
}
return dashboards, c.decodeJSON(resp, &dashboards)
}
func (c *Client) CreateDashboard(u string, d Dashboard) error {
resp, err := c.post("/"+u+"/dashboards", d)
if resp != nil {
defer resp.Body.Close()
}
return err
}
func (c *Client) DeleteDashboard(u, d string) error {
resp, err := c.delete("/" + u + "/dashboards/" + d)
if resp != nil {
defer resp.Body.Close()
}
return err
}
func (c *Client) GetDashboard(u, d string) (Dashboard, error) {
var dashboard Dashboard
resp, err := c.get("/" + u + "/dashboards/" + d)
if resp != nil {
defer resp.Body.Close()
}
if err != nil {
return dashboard, err
}
return dashboard, c.decodeJSON(resp, &dashboard)
}
func (c *Client) UpdateDashboard(u, d string, dashboard Dashboard) error {
resp, err := c.patch("/"+u+"/dashboards/"+d, dashboard)
if resp != nil {
defer resp.Body.Close()
}
return err
}
func (c *Client) ReplaceDashboard(u, d string, dashboard Dashboard) error {
resp, err := c.put("/"+u+"/dashboards/"+d, dashboard)
if resp != nil {
defer resp.Body.Close()
}
return err
}