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

A few new features #43

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ tests/env

*.swo
*.swp
.idea/
80 changes: 76 additions & 4 deletions action.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ type Action struct {
client *Client
Id string `json:"id"`
IdMemberCreator string `json:"idMemberCreator"`
Data struct {
Data struct {
DateLastEdited string `json:"dateLastEdited"`
ListBefore struct {
ListBefore struct {
Id string `json:"id"`
Name string `json:"name"`
} `json:"listBefore"`
Expand Down Expand Up @@ -59,8 +59,8 @@ type Action struct {
} `json:"card"`
Text string `json:"text"`
} `json:"data"`
Type string `json:"type"`
Date string `json:"date"`
Type ActionType `json:"type"`
Date string `json:"date"`
MemberCreator struct {
Id string `json:"id"`
AvatarHash string `json:"avatarHash"`
Expand All @@ -69,3 +69,75 @@ type Action struct {
Username string `json:"username"`
} `json:"memberCreator"`
}

type ActionType string

const (
AddAdminToBoard ActionType = "addAdminToBoard"
AddAdminToOrganization ActionType = "addAdminToOrganization"
AddAttachmentToCard ActionType = "addAttachmentToCard"
AddBoardsPinnedToMember ActionType = "addBoardsPinnedToMember"
AddChecklistToCard ActionType = "addChecklistToCard"
AddLabelToCard ActionType = "addLabelToCard"
AddMemberToBoard ActionType = "addMemberToBoard"
AddMemberToCard ActionType = "addMemberToCard"
AddMemberToOrganization ActionType = "addMemberToOrganization"
AddToOrganizationBoard ActionType = "addToOrganizationBoard"
CommentCard ActionType = "commentCard"
ConvertToCardFromCheckItem ActionType = "convertToCardFromCheckItem"
CopyBoard ActionType = "copyBoard"
CopyCard ActionType = "copyCard"
CopyChecklist ActionType = "copyChecklist"
CreateLabel ActionType = "createLabel"
CopyCommentCard ActionType = "copyCommentCard"
CreateBoard ActionType = "createBoard"
CreateBoardInvitation ActionType = "createBoardInvitation"
CreateBoardPreference ActionType = "createBoardPreference"
CreateCard ActionType = "createCard"
CreateChecklist ActionType = "createChecklist"
CreateList ActionType = "createList"
CreateOrganization ActionType = "createOrganization"
CreateOrganizationInvitation ActionType = "createOrganizationInvitation"
DeleteAttachmentFromCard ActionType = "deleteAttachmentFromCard"
DeleteBoardInvitation ActionType = "deleteBoardInvitation"
DeleteCard ActionType = "deleteCard"
DeleteCheckItem ActionType = "deleteCheckItem"
DeleteLabel ActionType = "deleteLabel"
DeleteOrganizationInvitation ActionType = "deleteOrganizationInvitation"
DisablePlugin ActionType = "disablePlugin"
DisablePowerUp ActionType = "disablePowerUp"
EmailCard ActionType = "emailCard"
EnablePlugin ActionType = "enablePlugin"
EnablePowerUp ActionType = "enablePowerUp"
MakeAdminOfBoard ActionType = "makeAdminOfBoard"
MakeAdminOfOrganization ActionType = "makeAdminOfOrganization"
MakeNormalMemberOfBoard ActionType = "makeNormalMemberOfBoard"
MakeNormalMemberOfOrganization ActionType = "makeNormalMemberOfOrganization"
MakeObserverOfBoard ActionType = "makeObserverOfBoard"
MemberJoinedTrello ActionType = "memberJoinedTrello"
MoveCardFromBoard ActionType = "moveCardFromBoard"
MoveCardToBoard ActionType = "moveCardToBoard"
MoveListFromBoard ActionType = "moveListFromBoard"
MoveListToBoard ActionType = "moveListToBoard"
RemoveAdminFromBoard ActionType = "removeAdminFromBoard"
RemoveAdminFromOrganization ActionType = "removeAdminFromOrganization"
RemoveBoardsPinnedFromMember ActionType = "removeBoardsPinnedFromMember"
RemoveChecklistFromCard ActionType = "removeChecklistFromCard"
RemoveFromOrganizationBoard ActionType = "removeFromOrganizationBoard"
RemoveLabelFromCard ActionType = "removeLabelFromCard"
RemoveMemberFromBoard ActionType = "removeMemberFromBoard"
RemoveMemberFromCard ActionType = "removeMemberFromCard"
RemoveMemberFromOrganization ActionType = "removeMemberFromOrganization"
UnconfirmedBoardInvitation ActionType = "unconfirmedBoardInvitation"
UnconfirmedOrganizationInvitation ActionType = "unconfirmedOrganizationInvitation"
UpdateBoard ActionType = "updateBoard"
UpdateCard ActionType = "updateCard"
UpdateCheckItem ActionType = "updateCheckItem"
UpdateCheckItemStateOnCard ActionType = "updateCheckItemStateOnCard"
UpdateChecklist ActionType = "updateChecklist"
UpdateLabel ActionType = "updateLabel"
UpdateList ActionType = "updateList"
UpdateMember ActionType = "updateMember"
UpdateOrganization ActionType = "updateOrganization"
VoteOnCard ActionType = "voteOnCard"
)
61 changes: 60 additions & 1 deletion board.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ limitations under the License.

package trello

import "encoding/json"
import (
"encoding/json"
"net/url"
"strconv"
)

type Board struct {
client *Client
Expand Down Expand Up @@ -184,3 +188,58 @@ func (b *Board) Actions(arg ...*Argument) (actions []Action, err error) {
}
return
}

func (b *Board) AddList(opts List) (*List, error) {
opts.IdBoard = b.Id

payload := url.Values{}
payload.Set("name", opts.Name)
payload.Set("idBoard", opts.IdBoard)
payload.Set("pos", strconv.FormatFloat(float64(opts.Pos), 'g', -1, 32))

body, err := b.client.Post("/lists", payload)
if err != nil {
return nil, err
}

var list List
if err = json.Unmarshal(body, &list); err != nil {
return nil, err
}

list.client = b.client
return &list, nil
}

func (b *Board) Labels() ([]Label, error) {
body, err := b.client.Get("/boards/" + b.Id + "/labels")
if err != nil {
return nil, err
}

var labels []Label
if err = json.Unmarshal(body, &labels); err != nil {
return nil, err
}
return labels, nil
}

//Color can be an empty string
func (b *Board) AddLabel(name, color string) (*Label, error) {
payload := url.Values{}
payload.Set("name", name)
payload.Set("color", color)

body, err := b.client.Post("/boards/" + b.Id + "/labels", payload)
if err != nil {
return nil, err
}

var label Label
if err = json.Unmarshal(body, &label); err != nil {
return nil, err
}

label.client = b.client
return &label, nil
}
169 changes: 165 additions & 4 deletions card.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package trello
import (
"encoding/json"
"net/url"
"strconv"
)

type Card struct {
Expand Down Expand Up @@ -62,10 +63,7 @@ type Card struct {
Description bool `json:"description"`
Due string `json:"due"`
} `json:"badges"`
Labels []struct {
Color string `json:"color"`
Name string `json:"name"`
} `json:"labels"`
Labels []Label `json:"labels"`
}

func (c *Client) Card(CardId string) (card *Card, err error) {
Expand Down Expand Up @@ -111,6 +109,49 @@ func (c *Card) Members() (members []Member, err error) {
return
}

// Add a member to a card
// The AddMember function requires a member (pointer) to add
// It returns the resulting member-list
// https://developers.trello.com/v1.0/reference#cardsididmembers
func (c *Card) AddMember(member *Member) (members []Member, err error) {
payload := url.Values{}
payload.Set("value", member.Id)
body, err := c.client.Post("/cards/"+c.Id+"/idMembers", payload)
if err != nil {
return nil, err
}
if err = json.Unmarshal(body, &members); err != nil {
return nil, err
}

// To enable our members to execute operations using our client, we need to pass each our client object
for i := range members {
members[i].client = c.client
}
return members, nil
}

// Remove a member from a card
// The RemoveMember function requires a member (pointer) to delete
// It returns the resulting member-list
func (c *Card) RemoveMember(member *Member) (members []Member, err error) {
body, err := c.client.Delete("/cards/" + c.Id + "/idMembers/" + member.Id)
if err != nil {
return nil, err
}

err = json.Unmarshal(body, &members)
if err != nil {
return nil, err
}

// To enable our members to execute operations using our client, we need to pass each our client object
for i := range members {
members[i].client = c.client
}
return members, nil
}

func (c *Card) Attachments() (attachments []Attachment, err error) {
body, err := c.client.Get("/cards/" + c.Id + "/attachments")
if err != nil {
Expand Down Expand Up @@ -188,3 +229,123 @@ func (c *Card) AddComment(text string) (*Action, error) {
newAction.client = c.client
return newAction, nil
}

func (c *Card) MoveToList(dstList List) (*Card, error) {
payload := url.Values{}
payload.Set("value", dstList.Id)

body, err := c.client.Put("/cards/"+c.Id+"/idList", payload)
if err != nil {
return nil, err
}

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

//pos can be "bottom", "top" or a positive number
func (c *Card) Move(pos string) (*Card, error) {
payload := url.Values{}
payload.Set("value", pos)

body, err := c.client.Put("/cards/"+c.Id+"/pos", payload)
if err != nil {
return nil, err
}

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

func (c *Card) Delete() error {
_, err := c.client.Delete("/cards/" + c.Id)
return err
}

//If mode is true, card is archived, otherwise it's unarchived (returns to the board)
func (c *Card) Archive(mode bool) error {
payload := url.Values{}
payload.Set("value", strconv.FormatBool(mode))

_, err := c.client.Put("/cards/"+c.Id+"/closed", payload)
return err
}

func (c *Card) SetName(name string) (*Card, error) {
payload := url.Values{}
payload.Set("value", name)

body, err := c.client.Put("/cards/"+c.Id+"/name", payload)
if err != nil {
return nil, err
}

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

func (c *Card) SetDescription(desc string) (*Card, error) {
payload := url.Values{}
payload.Set("value", desc)

body, err := c.client.Put("/cards/"+c.Id+"/desc", payload)
if err != nil {
return nil, err
}

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

//Returns an array of cards labels ids
func (c *Card) AddLabel(id string) ([]string, error) {
payload := url.Values{}
payload.Set("value", id)

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

var ids []string
if err = json.Unmarshal(body, &ids); err != nil {
return nil, err
}

return ids, nil
}

func (c *Card) AddNewLabel(name, color string) (*Label, error) {
payload := url.Values{}
payload.Set("name", name)
payload.Set("color", color)

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

var label Label
if err = json.Unmarshal(body, &label); err != nil {
return nil, err
}

label.client = c.client
return &label, nil
}
Loading