forked from adlio/trello
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboard.go
More file actions
167 lines (151 loc) · 5.32 KB
/
board.go
File metadata and controls
167 lines (151 loc) · 5.32 KB
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
// Copyright © 2016 Aaron Longwell
//
// Use of this source code is governed by an MIT licese.
// Details in the LICENSE file.
package trello
import (
"fmt"
"time"
)
// Board represents a Trello Board.
// https://developers.trello.com/reference/#boardsid
type Board struct {
client *Client
ID string `json:"id"`
Name string `json:"name"`
Desc string `json:"desc"`
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 []BackgroundImage `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 {
Black string `json:"black,omitempty"`
Blue string `json:"blue,omitempty"`
Green string `json:"green,omitempty"`
Lime string `json:"lime,omitempty"`
Orange string `json:"orange,omitempty"`
Pink string `json:"pink,omitempty"`
Purple string `json:"purple,omitempty"`
Red string `json:"red,omitempty"`
Sky string `json:"sky,omitempty"`
Yellow string `json:"yellow,omitempty"`
} `json:"labelNames"`
Lists []*List `json:"lists"`
Actions []*Action `json:"actions"`
Organization Organization `json:"organization"`
}
// NewBoard is a constructor that sets the default values
// for Prefs.SelfJoin and Prefs.CardCovers also set by the API.
func NewBoard(name string) Board {
b := Board{Name: name}
// default values in line with API POST
b.Prefs.SelfJoin = true
b.Prefs.CardCovers = true
return b
}
// BackgroundImage is a nested resource of Board.
type BackgroundImage struct {
Width int `json:"width"`
Height int `json:"height"`
URL string `json:"url"`
}
// CreatedAt returns a board's created-at attribute as time.Time.
func (b *Board) CreatedAt() time.Time {
t, _ := IDToTime(b.ID)
return t
}
// CreateBoard creates a board remote.
// Attribute currently supported as exra argument: powerUps.
// Attributes currently known to be unsupported: idBoardSource, keepFromSource.
//
// API Docs: https://developers.trello.com/reference/#boardsid
func (c *Client) CreateBoard(board *Board, extraArgs Arguments) error {
path := "boards"
args := Arguments{
"desc": board.Desc,
"name": board.Name,
"prefs_selfJoin": fmt.Sprintf("%t", board.Prefs.SelfJoin),
"prefs_cardCovers": fmt.Sprintf("%t", board.Prefs.CardCovers),
"idOrganization": board.IDOrganization,
}
if board.Prefs.Voting != "" {
args["prefs_voting"] = board.Prefs.Voting
}
if board.Prefs.PermissionLevel != "" {
args["prefs_permissionLevel"] = board.Prefs.PermissionLevel
}
if board.Prefs.Comments != "" {
args["prefs_comments"] = board.Prefs.Comments
}
if board.Prefs.Invitations != "" {
args["prefs_invitations"] = board.Prefs.Invitations
}
if board.Prefs.Background != "" {
args["prefs_background"] = board.Prefs.Background
}
if board.Prefs.CardAging != "" {
args["prefs_cardAging"] = board.Prefs.CardAging
}
// Expects one of "all", "calendar", "cardAging", "recap", or "voting".
if powerUps, ok := extraArgs["powerUps"]; ok {
args["powerUps"] = powerUps
}
err := c.Post(path, args, &board)
if err == nil {
board.client = c
}
return err
}
// Delete makes a DELETE call for the receiver Board.
func (b *Board) Delete(extraArgs Arguments) error {
path := fmt.Sprintf("boards/%s", b.ID)
return b.client.Delete(path, Arguments{}, b)
}
// GetBoard retrieves a Trello board by its ID.
func (c *Client) GetBoard(boardID string, args Arguments) (board *Board, err error) {
path := fmt.Sprintf("boards/%s", boardID)
err = c.Get(path, args, &board)
if board != nil {
board.client = c
}
return
}
// GetMyBoards returns a slice of all boards associated with the credentials set on the client.
func (c *Client) GetMyBoards(args Arguments) (boards []*Board, err error) {
path := "members/me/boards"
err = c.Get(path, args, &boards)
for i := range boards {
boards[i].client = c
}
return
}
// GetBoards returns a slice of all public boards of the receiver Member.
func (m *Member) GetBoards(args Arguments) (boards []*Board, err error) {
path := fmt.Sprintf("members/%s/boards", m.ID)
err = m.client.Get(path, args, &boards)
for i := range boards {
boards[i].client = m.client
}
return
}