@@ -19,6 +19,7 @@ package trello
1919import (
2020 "encoding/json"
2121 "net/url"
22+ "strconv"
2223)
2324
2425type Card struct {
@@ -172,12 +173,94 @@ func (c *Card) AddChecklist(name string) (*Checklist, error) {
172173
173174// AddComment will add a new comment to the card
174175// https://developers.trello.com/advanced-reference/card#post-1-cards-card-id-or-shortlink-actions-comments
175- func (c * Card ) AddComment (text string ) ([] byte , error ) {
176+ func (c * Card ) AddComment (text string ) (* Action , error ) {
176177 payload := url.Values {}
177178 payload .Set ("text" , text )
178179
179180 body , err := c .client .Post ("/cards/" + c .Id + "/actions/comments" , payload )
180- return body , err
181+ if err != nil {
182+ return nil , err
183+ }
184+
185+ var newAction * Action
186+ if err = json .Unmarshal (body , newAction ); err != nil {
187+ return nil , err
188+ }
189+ newAction .client = c .client
190+ return newAction , nil
191+ }
192+
193+ // Archive will archive the card
194+ // https://developers.trello.com/advanced-reference/card#put-1-cards-card-id-or-shortlink-closed
195+ func (c * Card ) Archive () (* Card , error ) {
196+ payload := url.Values {}
197+ payload .Set ("value" , "true" )
198+
199+ body , err := c .client .Put ("/cards/" + c .Id + "/closed" , payload )
200+ if err != nil {
201+ return nil , err
202+ }
203+
204+ var newCard * Card
205+ if err = json .Unmarshal (body , newCard ); err != nil {
206+ return nil , err
207+ }
208+ newCard .client = c .client
209+ return newCard , nil
210+ }
211+
212+ // SendToBoard will dearchive the card, or send the card to the board back from archive
213+ // https://developers.trello.com/advanced-reference/card#put-1-cards-card-id-or-shortlink-closed
214+ func (c * Card ) SendToBoard () (* Card , error ) {
215+ payload := url.Values {}
216+ payload .Set ("value" , "false" )
217+
218+ body , err := c .client .Put ("/cards/" + c .Id + "/closed" , payload )
219+ if err != nil {
220+ return nil , err
221+ }
222+ var newCard * Card
223+ if err = json .Unmarshal (body , newCard ); err != nil {
224+ return nil , err
225+ }
226+ newCard .client = c .client
227+ return newCard , nil
228+ }
229+
230+ // MoveToList will move the card to another list
231+ // https://developers.trello.com/advanced-reference/card#put-1-cards-card-id-or-shortlink-idlist
232+ func (c * Card ) MoveToList (listId string ) (* Card , error ) {
233+ payload := url.Values {}
234+ payload .Set ("value" , listId )
235+
236+ body , err := c .client .Put ("/cards/" + c .Id + "/idList" , payload )
237+ if err != nil {
238+ return nil , err
239+ }
240+ var newCard * Card
241+ if err = json .Unmarshal (body , newCard ); err != nil {
242+ return nil , err
243+ }
244+ newCard .client = c .client
245+ return newCard , nil
246+ }
247+
248+ // MoveToPos will move card to the specified position
249+ // https://developers.trello.com/advanced-reference/card#put-1-cards-card-id-or-shortlink-pos
250+ func (c * Card ) MoveToPos (pos int ) (* Card , error ) {
251+ payload := url.Values {}
252+ payload .Set ("value" , strconv .Itoa (pos ))
253+
254+ body , err := c .client .Put ("/cards/" + c .Id + "/pos" , payload )
255+ if err != nil {
256+ return nil , err
257+ }
258+ var newCard * Card
259+ if err = json .Unmarshal (body , newCard ); err != nil {
260+ return nil , err
261+ }
262+ newCard .client = c .client
263+ return newCard , nil
181264}
182265
183266// Archive will archive the card
0 commit comments