forked from VojtechVitek/go-trello
-
Notifications
You must be signed in to change notification settings - Fork 0
/
board.go
207 lines (178 loc) · 5.26 KB
/
board.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
Copyright 2014 go-trello authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package trello
import "encoding/json"
import "net/url"
type Board struct {
client *Client
Id string `json:"id"`
Name string `json:"name"`
Desc string `json:"desc"`
DescData struct {
Emoji struct{} `json:"emoji"`
} `json:"descData"`
Closed bool `json:"closed"`
IdOrganization string `json:"idOrganization"`
Pinned bool `json:"pinned"`
Url string `json:"url"`
ShortUrl string `json:"shortUrl"`
Prefs struct {
PermissionLevel string `json:"permissionLevel"`
Voting string `json:"voting"`
Comments string `json:"comments"`
Invitations string `json:"invitations"`
SelfJoin bool `json:"selfjoin"`
CardCovers bool `json:"cardCovers"`
CardAging string `json:"cardAging"`
CalendarFeedEnabled bool `json:"calendarFeedEnabled"`
Background string `json:"background"`
BackgroundColor string `json:"backgroundColor"`
BackgroundImage string `json:"backgroundImage"`
BackgroundImageScaled []BoardBackground `json:"backgroundImageScaled"`
BackgroundTile bool `json:"backgroundTile"`
BackgroundBrightness string `json:"backgroundBrightness"`
CanBePublic bool `json:"canBePublic"`
CanBeOrg bool `json:"canBeOrg"`
CanBePrivate bool `json:"canBePrivate"`
CanInvite bool `json:"canInvite"`
} `json:"prefs"`
LabelNames struct {
Red string `json:"red"`
Orange string `json:"orange"`
Yellow string `json:"yellow"`
Green string `json:"green"`
Blue string `json:"blue"`
Purple string `json:"purple"`
} `json:"labelNames"`
}
type BoardBackground struct {
width int `json:"width"`
height int `json:"height"`
url string `json:"url"`
}
func (c *Client) Boards() (boards []Board, err error) {
body, err := c.Get("/boards/")
if err != nil {
return
}
err = json.Unmarshal(body, &boards)
for i := range boards {
boards[i].client = c
}
return
}
func (c *Client) Board(boardId string) (board *Board, err error) {
body, err := c.Get("/boards/" + boardId)
if err != nil {
return
}
err = json.Unmarshal(body, &board)
board.client = c
return
}
func (b *Board) Lists() (lists []List, err error) {
body, err := b.client.Get("/boards/" + b.Id + "/lists")
if err != nil {
return
}
err = json.Unmarshal(body, &lists)
for i := range lists {
lists[i].client = b.client
}
return
}
func (b *Board) Members() (members []Member, err error) {
body, err := b.client.Get("/boards/" + b.Id + "/members")
if err != nil {
return
}
err = json.Unmarshal(body, &members)
for i := range members {
members[i].client = b.client
}
return
}
func (b *Board) Cards() (cards []Card, err error) {
body, err := b.client.Get("/boards/" + b.Id + "/cards")
if err != nil {
return
}
err = json.Unmarshal(body, &cards)
for i := range cards {
cards[i].client = b.client
}
return
}
func (b *Board) Card(IdCard string) (card *Card, err error) {
body, err := b.client.Get("/boards/" + b.Id + "/cards/" + IdCard)
if err != nil {
return
}
err = json.Unmarshal(body, &card)
card.client = b.client
return
}
func (b *Board) Checklists() (checklists []Checklist, err error) {
body, err := b.client.Get("/boards/" + b.Id + "/checklists")
if err != nil {
return
}
err = json.Unmarshal(body, &checklists)
for i := range checklists {
checklists[i].client = b.client
}
return
}
func (b *Board) MemberCards(IdMember string) (cards []Card, err error) {
body, err := b.client.Get("/boards/" + b.Id + "/members/" + IdMember + "/cards")
if err != nil {
return
}
err = json.Unmarshal(body, &cards)
for i := range cards {
cards[i].client = b.client
}
return
}
func (b *Board) Actions(arg ...*Argument) (actions []Action, err error) {
ep := "/boards/" + b.Id + "/actions"
if query := EncodeArgs(arg); query != "" {
ep += "?" + query
}
body, err := b.client.Get(ep)
if err != nil {
return
}
err = json.Unmarshal(body, &actions)
for i := range actions {
actions[i].client = b.client
}
return
}
// AddList creates list
// https://developers.trello.com/advanced-reference/board#post-1-boards-board-id-lists
func (b *Board) AddList(name string) (*List, error) {
payload := url.Values{}
payload.Set("name", name)
payload.Set("pos", "bottom")
body, err := b.client.Post("/boards/"+b.Id+"/lists", payload)
if err != nil {
return nil, err
}
var list List
if err = json.Unmarshal(body, &list); err != nil {
return nil, err
}
list.client = b.client
return &list, nil
}