-
Notifications
You must be signed in to change notification settings - Fork 0
/
board.go
203 lines (153 loc) · 4.28 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
package ncdeck
import (
"fmt"
"io"
"net/http"
"strings"
)
type Boards []Board
type Board struct {
client *Client
Title string `json:"title"`
Owner interface{} `json:"owner"`
Color string `json:"color"`
Archived bool `json:"archived"`
Labels Labels `json:"labels"`
ACL []interface{} `json:"acl"`
Permissions struct {
PermissionRead bool `json:"PERMISSION_READ"`
PermissionEdit bool `json:"PERMISSION_EDIT"`
PermissionManage bool `json:"PERMISSION_MANAGE"`
PermissionShare bool `json:"PERMISSION_SHARE"`
} `json:"permissions"`
Users []interface{} `json:"users"`
Shared int `json:"shared"`
Stacks Stacks `json:"stacks"`
DeletedAt int `json:"deletedAt"`
LastModified interface{} `json:"lastModified"`
Settings interface{} `json:"settings"`
ID int `json:"id"`
ETag string `json:"ETag"`
}
// Create card
func (b Board) CreateCard(stackid int, title, description string, order int, duedate string) (Card, error) {
var stack = Stack{ID: stackid, client: b.client, BoardID: b.ID}
card, err := stack.CreateCard(title, description, order, duedate)
if err != nil {
return Card{}, err
}
return card, err
}
// Create a label
func (b Board) CreateLabel(title, color string) (Label, error) {
var (
url = b.client.BaseURL + fmt.Sprintf("/boards/%v/labels", b.ID)
reqBody = fmt.Sprintf(`{"title": "%v", "color": "%v"}`, title, color)
)
req, err := http.NewRequest("POST", url, nil)
if err != nil {
return Label{}, err
}
req.Body = io.NopCloser(strings.NewReader(reqBody))
var label Label
err = b.client.do(req, &label)
if err != nil {
return Label{}, err
}
label.client = b.client
b.Labels = append(b.Labels, label)
return label, nil
}
// Create a Stack
func (b Board) CreateStack(title string, order int) (Stack, error) {
var (
url = b.client.BaseURL + fmt.Sprintf("/boards/%v/stacks", b.ID)
reqBody = fmt.Sprintf(`{"title":"%v", "order": "%v"}`, title, order)
)
req, err := http.NewRequest("POST", url, nil)
if err != nil {
return Stack{}, err
}
req.Body = io.NopCloser(strings.NewReader(reqBody))
var stack Stack
err = b.client.do(req, &stack)
if err != nil {
return Stack{}, err
}
stack.client = b.client
b.Stacks = append(b.Stacks, stack)
return stack, nil
}
// Get all stacks of this board
func (b *Board) GetStacks() (Stacks, error) {
var url = b.client.BaseURL + fmt.Sprintf("/boards/%v/stacks", b.ID)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return Stacks{}, err
}
err = b.client.do(req, &b.Stacks)
if err != nil {
return Stacks{}, err
}
for _, stack := range b.Stacks {
stack.client = b.client
}
return b.Stacks, nil
}
// Get archived stacks
func (b *Board) GetStacksArchived() error {
var url = b.client.BaseURL + fmt.Sprintf("/boards/%v/stacks/archived", b.ID)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return err
}
err = b.client.do(req, &b.Stacks)
if err != nil {
return err
}
for _, stack := range b.Stacks {
stack.client = b.client
}
return nil
}
// Get information about this board
// useful if a board was updated by UI
func (b *Board) Get() error {
url := fmt.Sprintf("%v/boards/%v", b.client.BaseURL, b.ID)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return err
}
return b.client.do(req, &b)
}
// Delete this board
func (b *Board) Delete() error {
var url = fmt.Sprintf("%v/boards/%v", b.client.BaseURL, b.ID)
req, err := http.NewRequest("DELETE", url, nil)
if err != nil {
return err
}
return b.client.do(req, &b)
}
// Undo board deletion
func (b *Board) UndoDelete() error {
var url = fmt.Sprintf("%v/boards/%v/undo_delete", b.client.BaseURL, b.ID)
req, err := http.NewRequest("POST", url, nil)
if err != nil {
return err
}
return b.client.do(req, &b)
}
// Update informations about this board
func (b *Board) Update() error {
var (
url = fmt.Sprintf("%v/boards/%v", b.client.BaseURL, b.ID)
reqBody = fmt.Sprintf(`{"title":"%v","color": "%v","archived": %v}`, b.Title, b.Color, b.Archived)
)
req, err := http.NewRequest("PUT", url, nil)
if err != nil {
return err
}
req.Body = io.NopCloser(strings.NewReader(reqBody))
return b.client.do(req, &b)
}