-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcard.go
162 lines (134 loc) · 3.39 KB
/
card.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package trello
import (
"encoding/json"
"net/url"
"time"
)
const cardurl = "cards"
type Card struct {
// Badges
// CheckItemStates
Closed bool
DateLastActivity *time.Time
Desc string
// DescData
Due *time.Time
Id string
// IdAttachmentCover
IdBoard string
// IdChecklists
IdList string
IdMembers []string
IdMembersVoted []string
IdShort float64
// Labels []string
ManualCoverAttachment bool
Name string
Pos float64
ShortLink string
ShortUrl string
Subscribed bool
Url string
c *Client `json:"-"`
}
// CreateCard create a card with given name on a given board. Extra options can
// be passed through the extra parameter. For details on options, see
// https://trello.com/docs/api/card/index.html#post-1-cards
func (c *Client) CreateCard(name string, idList string, extra url.Values) (*Card, error) {
qp := url.Values{"name": {name}, "idList": {idList}}
for k, v := range extra {
qp[k] = v
}
//check required arguments 'urlSource'
if _, found := qp["urlSource"]; !found {
qp["urlSource"] = []string{"null"}
}
cardData, err := c.Request("POST", cardurl, nil, qp)
if err != nil {
return nil, err
}
card := Card{
c: c,
}
err = json.Unmarshal(cardData, &card)
if err != nil {
return nil, err
}
return &card, nil
}
// AddCard add a card with given name to a card. Extra options can
// be passedthrough the extra parameter. For details on options, see
// https://trello.com/docs/api/card/index.html#post-1-cards
func (l *List) AddCard(name string, extra url.Values) (*Card, error) {
return l.c.CreateCard(name, l.Id, extra)
}
// Card retrieves a trello card by ID
func (c *Client) Card(id string) (*Card, error) {
b, err := c.Request("GET", cardurl+"/"+id, nil, nil)
if err != nil {
return nil, err
}
card := Card{
c: c,
}
err = json.Unmarshal(b, &card)
if err != nil {
return nil, err
}
return &card, nil
}
func (c *Card) AddComment(comment string) error {
extra := url.Values{"text": {comment}}
_, err := c.c.Request("POST", cardurl+"/"+c.Id+"/actions/comments", nil, extra)
if err != nil {
return err
}
return nil
}
// AddChecklist created a new checklist on the card.
func (c *Card) AddChecklist(name string) (*Checklist, error) {
qp := url.Values{"name": {name}}
b, err := c.c.Request("POST", cardurl+"/"+c.Id+"/checklists", nil, qp)
if err != nil {
return nil, err
}
var cl *Checklist
err = json.Unmarshal(b, &cl)
return cl, err
}
// Checklists retrieves all checklists from a trello card
func (c *Card) Checklists() ([]*Checklist, error) {
b, err := c.c.Request("GET", cardurl+"/"+c.Id+"/checklists", nil, nil)
if err != nil {
return nil, err
}
var checklists []*Checklist
err = json.Unmarshal(b, &checklists)
if err != nil {
return nil, err
}
for _, checklist := range checklists {
checklist.c = c.c
for _, ci := range checklist.CheckItems {
ci.c = c.c
}
}
return checklists, nil
}
// Actions retrieves a list of all actions (e.g. events, activity)
// performed on a card
func (c *Card) Actions() ([]*Action, error) {
b, err := c.c.Request("GET", cardurl+"/"+c.Id+"/actions", nil, nil)
if err != nil {
return nil, err
}
var act []*Action
err = json.Unmarshal(b, &act)
if err != nil {
return nil, err
}
for _, a := range act {
a.c = c.c
}
return act, nil
}