Skip to content
This repository has been archived by the owner on Apr 2, 2022. It is now read-only.

Commit

Permalink
NewCard and a wrapper for List.
Browse files Browse the repository at this point in the history
  • Loading branch information
fiatjaf committed Feb 24, 2016
1 parent 36cd0e2 commit 218ea40
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
27 changes: 26 additions & 1 deletion card.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package trello
import (
"encoding/json"
"net/url"
"strconv"
"strings"
)

type Card struct {
Expand All @@ -35,7 +37,7 @@ type Card struct {
IdMembersVoted []string `json:"idMembersVoted"`
ManualCoverAttachment bool `json:"manualCoverAttachment"`
Closed bool `json:"closed"`
Pos float32 `json:"pos"`
Pos int `json:"pos"`
ShortLink string `json:"shortLink"`
DateLastActivity string `json:"dateLastActivity"`
ShortUrl string `json:"shortUrl"`
Expand Down Expand Up @@ -79,6 +81,29 @@ func (c *Client) Card(CardId string) (card *Card, err error) {
return
}

// NewCard creates with the attributes of the supplied Card struct
// https://developers.trello.com/advanced-reference/card#post-1-cards
func (c *Client) NewCard(card Card) (_ *Card, err error) {
payload := url.Values{}
payload.Set("name", card.Name)
payload.Set("desc", card.Desc)
payload.Set("pos", strconv.Itoa(card.Pos))
payload.Set("due", card.Due)
payload.Set("idList", card.IdList)
payload.Set("idMembers", strings.Join(card.IdMembers, ","))

body, err := c.Post("/cards", payload)
if err != nil {
return nil, err
}

if err = json.Unmarshal(body, &card); err != nil {
return nil, err
}
card.client = c
return &card, nil
}

func (c *Card) Checklists() (checklists []Checklist, err error) {
body, err := c.client.Get("/card/" + c.Id + "/checklists")
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions list.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,9 @@ func (l *List) Actions() (actions []Action, err error) {
}
return
}

// AddCard is just a wrapper for Client.NewCard
func (l *List) AddCard(card Card) (*Card, error) {
card.IdList = l.Id
return l.client.NewCard(card)
}

0 comments on commit 218ea40

Please sign in to comment.