Skip to content

Commit

Permalink
Merge branch 'master' of github.com:adlio/trello
Browse files Browse the repository at this point in the history
* 'master' of github.com:adlio/trello:
  [add and remove label]
  Label API support
  Set client on cards when getting lists
  • Loading branch information
adlio committed Sep 19, 2018
2 parents 724cd42 + 3be9ae5 commit 43d0dcd
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 0 deletions.
12 changes: 12 additions & 0 deletions card.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ func (c *Card) AddMemberID(memberID string) (member []*Member, err error) {
return member, err
}

func (c *Card) RemoveIDLabel(labelID string, label *Label) error {
path := fmt.Sprintf("cards/%s/idLabels/%s", c.ID, labelID)
return c.client.Delete(path, Defaults(), label)

}

func (c *Card) AddIDLabel(labelID string) error {
path := fmt.Sprintf("cards/%s/idLabels", c.ID)
err := c.client.Post(path, Arguments{"value": labelID}, &c.IDLabels)
return err
}

func (c *Card) MoveToTopOfList() error {
path := fmt.Sprintf("cards/%s", c.ID)
return c.client.Put(path, Arguments{"pos": "top"}, c)
Expand Down
14 changes: 14 additions & 0 deletions label.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,24 @@

package trello

import "fmt"

type Label struct {
ID string `json:"id"`
IDBoard string `json:"idBoard"`
Name string `json:"name"`
Color string `json:"color"`
Uses int `json:"uses"`
}

func (c *Client) GetLabel(labelID string, args Arguments) (label *Label, err error) {
path := fmt.Sprintf("labels/%s", labelID)
err = c.Get(path, args, &label)
return
}

func (b *Board) GetLabels(args Arguments) (labels []*Label, err error) {
path := fmt.Sprintf("boards/%s/labels", b.ID)
err = b.client.Get(path, args, &labels)
return
}
43 changes: 43 additions & 0 deletions label_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright © 2016 Aaron Longwell
//
// Use of this source code is governed by an MIT licese.
// Details in the LICENSE file.

package trello

import (
"testing"
)


func TestGetLabel(t *testing.T) {
label := testLabel(t)
if label.Name != "Visited" {
t.Errorf("Title incorrect. Got '%s'", label.Name)
}
}

func TestGetLabelsOnBoard(t *testing.T) {
board := testBoard(t)
board.client.BaseURL = mockResponse("labels", "board-labels-api-example.json").URL
lists, err := board.GetLabels(Defaults())
if err != nil {
t.Fatal(err)
}

if len(lists) != 3 {
t.Errorf("Expected 3 labels, got %d", len(lists))
}
}

// Utility function to get the standard case Client.GetList() response
//
func testLabel(t *testing.T) *Label {
c := testClient()
c.BaseURL = mockResponse("labels", "labels-api-example.json").URL
label, err := c.GetLabel("4eea4ff", Defaults())
if err != nil {
t.Fatal(err)
}
return label
}
6 changes: 6 additions & 0 deletions list.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ func (c *Client) GetList(listID string, args Arguments) (list *List, err error)
err = c.Get(path, args, &list)
if list != nil {
list.client = c
for i := range list.Cards {
list.Cards[i].client = c
}
}
return
}
Expand All @@ -40,6 +43,9 @@ func (b *Board) GetLists(args Arguments) (lists []*List, err error) {
err = b.client.Get(path, args, &lists)
for i := range lists {
lists[i].client = b.client
for j := range lists[i].Cards {
lists[i].Cards[j].client = b.client
}
}
return
}
32 changes: 32 additions & 0 deletions list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ func TestGetList(t *testing.T) {
}
}

func TestGetListWithCards(t *testing.T) {
c := testClient()
c.BaseURL = mockResponse("lists", "list-api-example.json").URL
list, err := c.GetList("4eea4ff", Defaults())
if err != nil {
t.Fatal(err)
}
if len(list.Cards) == 0 {
t.Fatal("cannot test cards as non was available in lists mock response")
}
if list.Cards[0].client == nil {
t.Fatal("client not set on cards")
}
}

func TestGetListsOnBoard(t *testing.T) {
board := testBoard(t)
board.client.BaseURL = mockResponse("lists", "board-lists-api-example.json").URL
Expand All @@ -41,6 +56,23 @@ func TestGetListsOnBoard(t *testing.T) {
}
}

func TestGetListsOnBoardWithCards(t *testing.T) {
board := testBoard(t)
board.client.BaseURL = mockResponse("lists", "board-lists-api-example.json").URL
lists, err := board.GetLists(Defaults())
if err != nil {
t.Fatal(err)
}
for i := range lists {
if len(lists[i].Cards) == 0 {
t.Fatal("cannot test cards as non was available in lists mock response")
}
if lists[i].Cards[0].client == nil {
t.Fatal("client not set on cards")
}
}
}

// Utility function to get the standard case Client.GetList() response
//
func testList(t *testing.T) *List {
Expand Down
17 changes: 17 additions & 0 deletions testdata/labels/board-labels-api-example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[
{
"id": "57a890c6504676888e1dd747",
"name": "Verified on branch",
"color": "yellow"
},
{
"id": "57a890c6504676888e1dd74a",
"name": "Regression",
"color": "purple"
},
{
"id": "57a890c6504676888e1dd74b",
"name": "Verified on staging",
"color": "blue"
}
]
6 changes: 6 additions & 0 deletions testdata/labels/labels-api-example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"id": "560bf42919ad3a5dc29f33c5",
"idBoard": "560bf4298b3dda300c18d09c",
"name": "Visited",
"color": "green"
}

0 comments on commit 43d0dcd

Please sign in to comment.