-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathchecklist.go
82 lines (65 loc) · 1.46 KB
/
checklist.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package trello
import (
"encoding/json"
"net/url"
)
const checklisturl = "checklists"
type CheckItem struct {
Id string
Name string
//nameData
Pos float64
State string
c *Client `json:"-"`
}
type Checklist struct {
Id string
IdCard string
IdBoard string
Pos float64
Name string
CheckItems []*CheckItem
c *Client `json:"-"`
}
// Checklist retrieves a checklist by id
func (c *Client) Checklist(id string) (*Checklist, error) {
b, err := c.Request("GET", checklisturl+"/"+id, nil, nil)
if err != nil {
return nil, err
}
checklist := Checklist{
c: c,
}
err = json.Unmarshal(b, &checklist)
if err != nil {
return nil, err
}
for _, ci := range checklist.CheckItems {
ci.c = c
}
return &checklist, nil
}
func (c *Checklist) AddItem(name string) (*CheckItem, error) {
extra := url.Values{"name": {name}}
b, err := c.c.Request("POST", checklisturl+"/"+c.Id+"/checkItems", nil, extra)
if err != nil {
return nil, err
}
var ci *CheckItem
err = json.Unmarshal(b, &ci)
return ci, err
}
// CheckItem changes whether a checklist item id is marked as complete or not.
func (c *Checklist) CheckItem(id string, checked bool) error {
extra := url.Values{}
if checked {
extra.Add("value", "complete")
} else {
extra.Add("value", "incomplete")
}
_, err := c.c.Request("PUT", cardurl+"/"+c.IdCard+"/checklist/"+c.Id+"/checkItem/"+id+"/state", nil, extra)
if err != nil {
return err
}
return nil
}