forked from adlio/trello
-
Notifications
You must be signed in to change notification settings - Fork 0
/
checklist.go
97 lines (86 loc) · 2.99 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright © 2016 Aaron Longwell
//
// Use of this source code is governed by an MIT license.
// Details in the LICENSE file.
package trello
// Checklist represents Trello card's checklists.
// A card can have one zero or more checklists.
// https://developers.trello.com/reference/#checklist-object
type Checklist struct {
ID string `json:"id"`
Name string `json:"name"`
IDBoard string `json:"idBoard,omitempty"`
IDCard string `json:"idCard,omitempty"`
Pos float64 `json:"pos,omitempty"`
CheckItems []CheckItem `json:"checkItems,omitempty"`
client *Client
}
// CheckItem is a nested resource representing an item in Checklist.
type CheckItem struct {
ID string `json:"id"`
Name string `json:"name"`
State string `json:"state"`
IDChecklist string `json:"idChecklist,omitempty"`
Pos float64 `json:"pos,omitempty"`
}
// CheckItemState represents a CheckItem when it appears in CheckItemStates on a Card.
type CheckItemState struct {
IDCheckItem string `json:"idCheckItem"`
State string `json:"state"`
}
// CreateChecklist creates a checklist.
// Attribute currently supported as extra argument: pos.
// Attributes currently known to be unsupported: idChecklistSource.
//
// API Docs: https://developers.trello.com/reference#cardsidchecklists-1
func (c *Client) CreateChecklist(card *Card, name string, extraArgs Arguments) (checklist *Checklist, err error) {
path := "cards/" + card.ID + "/checklists"
args := Arguments{
"name": name,
"pos": "bottom",
}
if pos, ok := extraArgs["pos"]; ok {
args["pos"] = pos
}
checklist = &Checklist{}
err = c.Post(path, args, &checklist)
if err == nil {
checklist.client = c
checklist.IDCard = card.ID
card.Checklists = append(card.Checklists, checklist)
}
return
}
// CreateCheckItem creates a checkitem inside the checklist.
// Attribute currently supported as extra argument: pos.
// Attributes currently known to be unsupported: checked.
//
// API Docs: https://developers.trello.com/reference#checklistsidcheckitems
func (cl *Checklist) CreateCheckItem(name string, extraArgs Arguments) (item *CheckItem, err error) {
return cl.client.CreateCheckItem(cl, name, extraArgs)
}
// CreateCheckItem creates a checkitem inside the given checklist.
// Attribute currently supported as extra argument: pos.
// Attributes currently known to be unsupported: checked.
//
// API Docs: https://developers.trello.com/reference#checklistsidcheckitems
func (c *Client) CreateCheckItem(checklist *Checklist, name string, extraArgs Arguments) (item *CheckItem, err error) {
path := "checklists/" + checklist.ID + "/checkItems"
args := Arguments{
"name": name,
"pos": "bottom",
"checked": "false",
}
if pos, ok := extraArgs["pos"]; ok {
args["pos"] = pos
}
if checked, ok := extraArgs["checked"]; ok {
args["checked"] = checked
}
item = &CheckItem{}
err = c.Post(path, args, item)
if err == nil {
checklist.CheckItems = append(checklist.CheckItems, *item)
}
return
}