diff --git a/.travis.yml b/.travis.yml index e128e44..5729be2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,14 +2,15 @@ sudo: false language: go go: + - "1.5" - 1.4.3 - - 1.2 + - "1.2" - tip install: - go get 'github.com/franela/goblin' - go get 'github.com/onsi/gomega' - - go get 'github.com/VojtechVitek/go-trello' + - go get 'github.com/TJM/go-trello' script: - go test ./tests/... diff --git a/README.md b/README.md index fa58663..041399a 100644 --- a/README.md +++ b/README.md @@ -1,100 +1,104 @@ -Golang Trello API client ------------------------- +# Golang Trello API client + go-trello is a [Go](http://golang.org/) client package for accessing the [Trello](http://www.trello.com/) [API](http://trello.com/api). Go package -[![GoDoc](https://godoc.org/github.com/VojtechVitek/go-trello?status.png)](https://godoc.org/github.com/VojtechVitek/go-trello) -[![Travis](https://travis-ci.org/VojtechVitek/go-trello.svg?branch=master)](https://travis-ci.org/VojtechVitek/go-trello) +[![GoDoc](https://godoc.org/github.com/TJM/go-trello?status.png)](https://godoc.org/github.com/TJM/go-trello) +[![Travis](https://travis-ci.org/TJM/go-trello.svg?branch=master)](https://travis-ci.org/TJM/go-trello) + +## Example + +Prerequisites: -Example -------- +* Retrieve your `appKey`: (NOTE: This identifies "you" as the developer of the application) +* Retrieve your (temporary) `token`: ```go package main import ( - "fmt" - "log" + "fmt" + "log" - "github.com/VojtechVitek/go-trello" + "github.com/TJM/go-trello" ) func main() { - // New Trello Client - appKey := "application-key" - token := "token" - trello, err := trello.NewAuthClient(appKey, &token) - if err != nil { - log.Fatal(err) - } - - // User @trello - user, err := trello.Member("trello") - if err != nil { - log.Fatal(err) - } - fmt.Println(user.FullName) - - // @trello Boards - boards, err := user.Boards() - if err != nil { - log.Fatal(err) - } - - if len(boards) > 0 { - board := boards[0] - fmt.Printf("* %v (%v)\n", board.Name, board.ShortUrl) - - // @trello Board Lists - lists, err := board.Lists() - if err != nil { - log.Fatal(err) - } - - for _, list := range lists { - fmt.Println(" - ", list.Name) - - // @trello Board List Cards - cards, _ := list.Cards() - for _, card := range cards { - fmt.Println(" + ", card.Name) - } - } - } + // New Trello Client + appKey := "application-key" + token := "token" + trello, err := trello.NewAuthClient(appKey, &token) + if err != nil { + log.Fatal(err) + } + + // User @trello + user, err := trello.Member("trello") + if err != nil { + log.Fatal(err) + } + fmt.Println(user.FullName) + + // @trello Boards + boards, err := user.Boards() + if err != nil { + log.Fatal(err) + } + + if len(boards) > 0 { + board := boards[0] + fmt.Printf("* %v (%v)\n", board.Name, board.ShortURL) + + // @trello Board Lists + lists, err := board.Lists() + if err != nil { + log.Fatal(err) + } + + for _, list := range lists { + fmt.Println(" - ", list.Name) + + // @trello Board List Cards + cards, _ := list.Cards() + for _, card := range cards { + fmt.Println(" + ", card.Name) + } + } + } } ``` prints -``` +```console Trello -* How to Use Trello for Android (https://trello.com/b/9dnaRkNt) - - Getting Started - + Welcome to Trello! This is a card. - + Tap on a card to open it up. - + Color-coded labels can be used to classify cards. - + Create as many cards as you want. We've got an unlimited supply! - + Here is a picture of Taco, our Siberian Husky. - - Diving In - + Tap and hold this card to drag it to another list. - + Tap on the board name to view other sections. - + Make as many lists and boards as you need. We'll make more! - - Mastering Trello - + Finished with a card? Drag it to the top of the board to archive it. - + You can reorder lists too. - + Invite team members to collaborate on this board. - - More Info - + Want updates on new features? - + You can also view your boards on trello.com +* Bucket List (https://trello.com/b/Nl2oG77n) + - Goals + + How To Use This Board + + Do volunteer work + - Up Next + + Solve a Rubik’s Cube! + + Visit Japan + - Underway + + Improve writing skills + - Done! + + Learn to sail ``` -Influenced by -------------- -- [fsouza/go-dockerclient](https://github.com/fsouza/go-dockerclient) -- [jeremytregunna/ruby-trello](https://github.com/jeremytregunna/ruby-trello) +## Acknowledgements + +Forked From: + +* [VojtechVitek/go-trello](https://github.com/VojtechVitek/go-trello) +* [aQaTL/go-trello](https://github.com/aQaTL/go-trello) + +(previously) Influenced by: + +* [fsouza/go-dockerclient](https://github.com/fsouza/go-dockerclient) +* [jeremytregunna/ruby-trello](https://github.com/jeremytregunna/ruby-trello) + +## License -License -------- Licensed under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0). diff --git a/action.go b/action.go index 2a8526b..d7aa226 100644 --- a/action.go +++ b/action.go @@ -16,53 +16,54 @@ limitations under the License. package trello +// Action struct type Action struct { client *Client - Id string `json:"id"` - IdMemberCreator string `json:"idMemberCreator"` - Data struct { + ID string `json:"id"` + IDMemberCreator string `json:"idMemberCreator"` + Data struct { DateLastEdited string `json:"dateLastEdited"` - ListBefore struct { - Id string `json:"id"` + ListBefore struct { + ID string `json:"id"` Name string `json:"name"` } `json:"listBefore"` ListAfter struct { - Id string `json:"id"` + ID string `json:"id"` Name string `json:"name"` } `json:"listAfter"` CheckItem struct { - Id string `json:"id"` + ID string `json:"id"` State string `json:"state"` Name string `json:"name"` } `json:"checkItem"` CheckList struct { - Id string `json:"id"` + ID string `json:"id"` Name string `json:"name"` } `json:"checklist"` List struct { - Id string `json:"id"` + ID string `json:"id"` Name string `json:"name"` } `json:"list"` TextData struct { Emoji struct{} `json:"emoji"` } `json:"textData"` Board struct { - Id string `json:"id"` + ID string `json:"id"` Name string `json:"name"` ShortLink string `json:"shortLink"` } `json:"board"` Card struct { - Id string `json:"id"` + ID string `json:"id"` Name string `json:"name"` ShortLink string `json:"shortLink"` - IdShort int `json:"idShort"` + IDShort int `json:"idShort"` } `json:"card"` Text string `json:"text"` } `json:"data"` - Type ActionType `json:"type"` - Date string `json:"date"` + Type ActionType `json:"type"` + Date string `json:"date"` MemberCreator struct { - Id string `json:"id"` + ID string `json:"id"` AvatarHash string `json:"avatarHash"` FullName string `json:"fullName"` Initials string `json:"initials"` @@ -70,8 +71,10 @@ type Action struct { } `json:"memberCreator"` } +// ActionType Action String type ActionType string +// Actions const ( AddAdminToBoard ActionType = "addAdminToBoard" AddAdminToOrganization ActionType = "addAdminToOrganization" diff --git a/arg.go b/arg.go index 6404885..3252afc 100644 --- a/arg.go +++ b/arg.go @@ -18,11 +18,13 @@ package trello import "net/url" +// Argument struct type Argument struct { Name string Value string } +// NewArgument creates a new argument type from name and value strings func NewArgument(name, value string) *Argument { return &Argument{ Name: name, @@ -30,6 +32,7 @@ func NewArgument(name, value string) *Argument { } } +// EncodeArgs URL encodes a list of arguments func EncodeArgs(args []*Argument) string { v := url.Values{} for _, arg := range args { diff --git a/attachment.go b/attachment.go index 5fcfe42..dcc1943 100644 --- a/attachment.go +++ b/attachment.go @@ -16,23 +16,24 @@ limitations under the License. package trello +// Attachment - Type type Attachment struct { client *Client - Id string `json:"id"` + ID string `json:"id"` Bytes int `json:"bytes"` Date string `json:"date"` EdgeColor string `json:"edgeColor"` - IdMember string `json:"idMember"` + IDMember string `json:"idMember"` IsUpload bool `json:"isUpload"` MimeType string `json:"mimeType"` Name string `json:"name"` Previews []struct { Width int `json:"width"` Height int `json:"height"` - Url string `json:"url"` + URL string `json:"url"` Bytes int `json:"bytes"` - Id string `json:"_id"` + ID string `json:"_id"` Scaled bool `json:"scaled"` } `json:"previews"` - Url string `json:"url"` + URL string `json:"url"` } diff --git a/board.go b/board.go index c2b2baf..dcea596 100644 --- a/board.go +++ b/board.go @@ -22,19 +22,20 @@ import ( "strconv" ) +// Board Type for Trello Board type Board struct { client *Client - Id string `json:"id"` + ID string `json:"id"` Name string `json:"name"` Desc string `json:"desc"` DescData struct { Emoji struct{} `json:"emoji"` } `json:"descData"` Closed bool `json:"closed"` - IdOrganization string `json:"idOrganization"` + IDOrganization string `json:"idOrganization"` Pinned bool `json:"pinned"` - Url string `json:"url"` - ShortUrl string `json:"shortUrl"` + URL string `json:"url"` + ShortURL string `json:"shortUrl"` Prefs struct { PermissionLevel string `json:"permissionLevel"` Voting string `json:"voting"` @@ -65,12 +66,15 @@ type Board struct { } `json:"labelNames"` } +// BoardBackground Type type BoardBackground struct { - width int `json:"width"` - height int `json:"height"` - url string `json:"url"` + Width int `json:"width"` + Height int `json:"height"` + URL string `json:"url"` } +// Boards - retrieves list of all boards +// - URL Link? func (c *Client) Boards() (boards []Board, err error) { body, err := c.Get("/boards/") if err != nil { @@ -84,8 +88,10 @@ func (c *Client) Boards() (boards []Board, err error) { return } -func (c *Client) Board(boardId string) (board *Board, err error) { - body, err := c.Get("/boards/" + boardId) +// Board - retrieves board by boardID +// - https://developer.atlassian.com/cloud/trello/rest/api-group-boards/#api-boards-id-get +func (c *Client) Board(boardID string) (board *Board, err error) { + body, err := c.Get("/boards/" + boardID) if err != nil { return } @@ -95,8 +101,10 @@ func (c *Client) Board(boardId string) (board *Board, err error) { return } +// Lists - Get lists on a board +// - https://developer.atlassian.com/cloud/trello/rest/api-group-boards/#api-boards-id-lists-get func (b *Board) Lists() (lists []List, err error) { - body, err := b.client.Get("/boards/" + b.Id + "/lists") + body, err := b.client.Get("/boards/" + b.ID + "/lists") if err != nil { return } @@ -108,8 +116,10 @@ func (b *Board) Lists() (lists []List, err error) { return } +// Members - Get the members of a board +// - https://developer.atlassian.com/cloud/trello/rest/api-group-boards/#api-boards-id-members-get func (b *Board) Members() (members []Member, err error) { - body, err := b.client.Get("/boards/" + b.Id + "/members") + body, err := b.client.Get("/boards/" + b.ID + "/members") if err != nil { return } @@ -121,8 +131,10 @@ func (b *Board) Members() (members []Member, err error) { return } +// Cards - Get cards on a board +// - https://developer.atlassian.com/cloud/trello/rest/api-group-boards/#api-boards-id-cards-get func (b *Board) Cards() (cards []Card, err error) { - body, err := b.client.Get("/boards/" + b.Id + "/cards") + body, err := b.client.Get("/boards/" + b.ID + "/cards") if err != nil { return } @@ -134,8 +146,10 @@ func (b *Board) Cards() (cards []Card, err error) { return } -func (b *Board) Card(IdCard string) (card *Card, err error) { - body, err := b.client.Get("/boards/" + b.Id + "/cards/" + IdCard) +// Card - Get a card on a board +// - https://developer.atlassian.com/cloud/trello/rest/api-group-boards/#api-boards-id-cards-idcard-get +func (b *Board) Card(IDCard string) (card *Card, err error) { + body, err := b.client.Get("/boards/" + b.ID + "/cards/" + IDCard) if err != nil { return } @@ -145,8 +159,10 @@ func (b *Board) Card(IdCard string) (card *Card, err error) { return } +// Checklists - Get checklists on a board +// - https://developer.atlassian.com/cloud/trello/rest/api-group-boards/#api-boards-id-checklists-get func (b *Board) Checklists() (checklists []Checklist, err error) { - body, err := b.client.Get("/boards/" + b.Id + "/checklists") + body, err := b.client.Get("/boards/" + b.ID + "/checklists") if err != nil { return } @@ -158,8 +174,10 @@ func (b *Board) Checklists() (checklists []Checklist, err error) { return } -func (b *Board) MemberCards(IdMember string) (cards []Card, err error) { - body, err := b.client.Get("/boards/" + b.Id + "/members/" + IdMember + "/cards") +// MemberCards - Get cards for a member ID (string) on a board? +// - URL Link? +func (b *Board) MemberCards(IDMember string) (cards []Card, err error) { + body, err := b.client.Get("/boards/" + b.ID + "/members/" + IDMember + "/cards") if err != nil { return } @@ -171,8 +189,10 @@ func (b *Board) MemberCards(IdMember string) (cards []Card, err error) { return } +// Actions - Get Actions for a Board +// - URL LINK? func (b *Board) Actions(arg ...*Argument) (actions []Action, err error) { - ep := "/boards/" + b.Id + "/actions" + ep := "/boards/" + b.ID + "/actions" if query := EncodeArgs(arg); query != "" { ep += "?" + query } @@ -189,12 +209,13 @@ func (b *Board) Actions(arg ...*Argument) (actions []Action, err error) { return } +// AddList - Add a List to a Board func (b *Board) AddList(opts List) (*List, error) { - opts.IdBoard = b.Id + opts.IDBoard = b.ID payload := url.Values{} payload.Set("name", opts.Name) - payload.Set("idBoard", opts.IdBoard) + payload.Set("idBoard", opts.IDBoard) payload.Set("pos", strconv.FormatFloat(float64(opts.Pos), 'g', -1, 32)) body, err := b.client.Post("/lists", payload) @@ -211,8 +232,10 @@ func (b *Board) AddList(opts List) (*List, error) { return &list, nil } +// Labels - Get Labels on a Board +// - https://developer.atlassian.com/cloud/trello/rest/api-group-boards/#api-boards-id-labels-get func (b *Board) Labels() ([]Label, error) { - body, err := b.client.Get("/boards/" + b.Id + "/labels") + body, err := b.client.Get("/boards/" + b.ID + "/labels") if err != nil { return nil, err } @@ -224,13 +247,15 @@ func (b *Board) Labels() ([]Label, error) { return labels, nil } -//Color can be an empty string +// AddLabel - Create a Label on a board +// - https://developer.atlassian.com/cloud/trello/rest/api-group-boards/#api-boards-id-labels-post +// NOTE: 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) + body, err := b.client.Post("/boards/"+b.ID+"/labels", payload) if err != nil { return nil, err } diff --git a/card.go b/card.go index 6311475..7756070 100644 --- a/card.go +++ b/card.go @@ -22,33 +22,34 @@ import ( "strconv" ) +// Card - Trello Card Type type Card struct { client *Client - Id string `json:"id"` + ID string `json:"id"` Name string `json:"name"` Email string `json:"email"` - IdShort int `json:"idShort"` - IdAttachmentCover string `json:"idAttachmentCover"` - IdCheckLists []string `json:"idCheckLists"` - IdBoard string `json:"idBoard"` - IdList string `json:"idList"` - IdMembers []string `json:"idMembers"` - IdMembersVoted []string `json:"idMembersVoted"` + IDShort int `json:"idShort"` + IDAttachmentCover string `json:"idAttachmentCover"` + IDCheckLists []string `json:"idCheckLists"` + IDBoard string `json:"idBoard"` + IDList string `json:"idList"` + IDMembers []string `json:"idMembers"` + IDMembersVoted []string `json:"idMembersVoted"` ManualCoverAttachment bool `json:"manualCoverAttachment"` Closed bool `json:"closed"` Pos float64 `json:"pos"` ShortLink string `json:"shortLink"` DateLastActivity string `json:"dateLastActivity"` - ShortUrl string `json:"shortUrl"` + ShortURL string `json:"shortUrl"` Subscribed bool `json:"subscribed"` - Url string `json:"url"` + URL string `json:"url"` Due string `json:"due"` Desc string `json:"desc"` DescData struct { Emoji struct{} `json:"emoji"` } `json:"descData"` CheckItemStates []struct { - IdCheckItem string `json:"idCheckItem"` + IDCheckItem string `json:"idCheckItem"` State string `json:"state"` } `json:"checkItemStates"` Badges struct { @@ -66,8 +67,10 @@ type Card struct { Labels []Label `json:"labels"` } -func (c *Client) Card(CardId string) (card *Card, err error) { - body, err := c.Get("/card/" + CardId) +// Card - Retrieve card by card ID +// - https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-get +func (c *Client) Card(CardID string) (card *Card, err error) { + body, err := c.Get("/card/" + CardID) if err != nil { return } @@ -77,8 +80,10 @@ func (c *Client) Card(CardId string) (card *Card, err error) { return } +// Checklists - Get Checklists on a Card +// - https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-checklists-get func (c *Card) Checklists() (checklists []Checklist, err error) { - body, err := c.client.Get("/card/" + c.Id + "/checklists") + body, err := c.client.Get("/card/" + c.ID + "/checklists") if err != nil { return } @@ -90,14 +95,16 @@ func (c *Card) Checklists() (checklists []Checklist, err error) { for i := range list.CheckItems { item := &list.CheckItems[i] item.client = c.client - item.listID = list.Id + item.listID = list.ID } } return } +// Members - Get the Members of a card +// - https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-members-get func (c *Card) Members() (members []Member, err error) { - body, err := c.client.Get("/cards/" + c.Id + "/members") + body, err := c.client.Get("/cards/" + c.ID + "/members") if err != nil { return } @@ -109,14 +116,15 @@ func (c *Card) Members() (members []Member, err error) { return } -// Add a member to a card +// AddMember - Add a member to a card +// - https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-idmembers-post // 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) + payload.Set("value", member.ID) + body, err := c.client.Post("/cards/"+c.ID+"/idMembers", payload) if err != nil { return nil, err } @@ -131,11 +139,12 @@ func (c *Card) AddMember(member *Member) (members []Member, err error) { return members, nil } -// Remove a member from a card +// RemoveMember - Remove a member from a card +// - https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-idmembers-idmember-delete // 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) + body, err := c.client.Delete("/cards/" + c.ID + "/idMembers/" + member.ID) if err != nil { return nil, err } @@ -152,8 +161,10 @@ func (c *Card) RemoveMember(member *Member) (members []Member, err error) { return members, nil } +// Attachments - Get Attachments on a Card +// - https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-attachments-get func (c *Card) Attachments() (attachments []Attachment, err error) { - body, err := c.client.Get("/cards/" + c.Id + "/attachments") + body, err := c.client.Get("/cards/" + c.ID + "/attachments") if err != nil { return } @@ -166,9 +177,10 @@ func (c *Card) Attachments() (attachments []Attachment, err error) { } // Attachment will return the specified attachment on the card +// - https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-attachments-idattachment-get // https://developers.trello.com/advanced-reference/card#get-1-cards-card-id-or-shortlink-attachments-idattachment -func (c *Card) Attachment(attachmentId string) (*Attachment, error) { - body, err := c.client.Get("/cards/" + c.Id + "/attachments/" + attachmentId) +func (c *Card) Attachment(attachmentID string) (*Attachment, error) { + body, err := c.client.Get("/cards/" + c.ID + "/attachments/" + attachmentID) if err != nil { return nil, err } @@ -179,8 +191,10 @@ func (c *Card) Attachment(attachmentId string) (*Attachment, error) { return attachment, err } +// Actions - Get Actions on a card +// - https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-actions-get func (c *Card) Actions() (actions []Action, err error) { - body, err := c.client.Get("/cards/" + c.Id + "/actions") + body, err := c.client.Get("/cards/" + c.ID + "/actions") if err != nil { return } @@ -192,6 +206,8 @@ func (c *Card) Actions() (actions []Action, err error) { return } +// AddChecklist - Create a Checklist on a Card +// - https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-checklists-post // AddChecklist will add a checklist to the card. // https://developers.trello.com/advanced-reference/card#post-1-cards-card-id-or-shortlink-checklists func (c *Card) AddChecklist(name string) (*Checklist, error) { @@ -199,7 +215,7 @@ func (c *Card) AddChecklist(name string) (*Checklist, error) { payload := url.Values{} payload.Set("name", name) - body, err := c.client.Post("/cards/"+c.Id+"/checklists", payload) + body, err := c.client.Post("/cards/"+c.ID+"/checklists", payload) if err != nil { return nil, err } @@ -219,7 +235,7 @@ func (c *Card) AddComment(text string) (*Action, error) { payload := url.Values{} payload.Set("text", text) - body, err := c.client.Post("/cards/"+c.Id+"/actions/comments", payload) + body, err := c.client.Post("/cards/"+c.ID+"/actions/comments", payload) if err != nil { return nil, err } @@ -230,11 +246,12 @@ func (c *Card) AddComment(text string) (*Action, error) { return newAction, nil } +// MoveToList - Move a card to a list func (c *Card) MoveToList(dstList List) (*Card, error) { payload := url.Values{} - payload.Set("value", dstList.Id) + payload.Set("value", dstList.ID) - body, err := c.client.Put("/cards/"+c.Id+"/idList", payload) + body, err := c.client.Put("/cards/"+c.ID+"/idList", payload) if err != nil { return nil, err } @@ -247,12 +264,14 @@ func (c *Card) MoveToList(dstList List) (*Card, error) { return &card, nil } +// Move - Move Card Position (Update a Card) +// - https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-put //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) + body, err := c.client.Put("/cards/"+c.ID+"/pos", payload) if err != nil { return nil, err } @@ -265,25 +284,31 @@ func (c *Card) Move(pos string) (*Card, error) { return &card, nil } +// Delete - Delete a Card +// - https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-delete func (c *Card) Delete() error { - _, err := c.client.Delete("/cards/" + c.Id) + _, err := c.client.Delete("/cards/" + c.ID) return err } +// Archive - Archive a Card +// - URL Link? //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) + _, err := c.client.Put("/cards/"+c.ID+"/closed", payload) return err } +// SetName - Set Name on Card (Update a Card) +// - https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-put 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) + body, err := c.client.Put("/cards/"+c.ID+"/name", payload) if err != nil { return nil, err } @@ -296,11 +321,13 @@ func (c *Card) SetName(name string) (*Card, error) { return &card, nil } +// SetDescription - Set Description on Card (Update a Card) +// - https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-put 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) + body, err := c.client.Put("/cards/"+c.ID+"/desc", payload) if err != nil { return nil, err } @@ -313,12 +340,14 @@ func (c *Card) SetDescription(desc string) (*Card, error) { return &card, nil } -//Returns an array of cards labels ids +// AddLabel - Add Label to a Card +// - https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-idlabels-post +// 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) + body, err := c.client.Post("/cards/"+c.ID+"/idLabels", payload) if err != nil { return nil, err } @@ -331,12 +360,14 @@ func (c *Card) AddLabel(id string) ([]string, error) { return ids, nil } +// AddNewLabel - Add a Label to a Card +// - https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-idlabels-post 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) + body, err := c.client.Post("/cards/"+c.ID+"/labels", payload) if err != nil { return nil, err } diff --git a/checklist.go b/checklist.go index 41c5e3a..135176d 100644 --- a/checklist.go +++ b/checklist.go @@ -23,11 +23,12 @@ import ( "strconv" ) +// ChecklistItem - Trello Checklist Item (member of Checklist) type ChecklistItem struct { client *Client - listID string // back pointer to the parent Id + listID string // back pointer to the parent ID State string `json:"state"` - Id string `json:"id"` + ID string `json:"id"` Name string `json:"name"` NameData struct { Emoji struct{} `json:"emoji"` @@ -35,8 +36,10 @@ type ChecklistItem struct { Pos int `json:"pos"` } +// Delete - Delete a ChecklistItem from Checklist +// - https://developer.atlassian.com/cloud/trello/rest/api-group-checklists/#api-checklists-id-checkitems-idcheckitem-delete func (i *ChecklistItem) Delete() error { - _, err := i.client.Delete("/checklists/" + i.listID + "/checkItems/" + i.Id) + _, err := i.client.Delete("/checklists/" + i.listID + "/checkItems/" + i.ID) return err } @@ -44,10 +47,10 @@ func (i *ChecklistItem) Delete() error { // https://developers.trello.com/advanced-reference/checklist type Checklist struct { client *Client - Id string `json:"id"` + ID string `json:"id"` Name string `json:"name"` - IdBoard string `json:"idBoard"` - IdCard string `json:"idCard"` + IDBoard string `json:"idBoard"` + IDCard string `json:"idCard"` Pos float32 `json:"pos"` CheckItems []ChecklistItem `json:"checkItems"` } @@ -55,7 +58,7 @@ type Checklist struct { // Delete will delete the checklist // https://developers.trello.com/advanced-reference/checklist#delete-1-checklists-idchecklist func (c *Checklist) Delete() error { - _, err := c.client.Delete("/checklists/" + c.Id) + _, err := c.client.Delete("/checklists/" + c.ID) return err } @@ -85,7 +88,7 @@ func (c *Checklist) AddItem(name string, pos *string, checked *bool) (*Checklist if checked != nil { payload.Set("checked", strconv.FormatBool(*checked)) } - body, err := c.client.Post("/checklist/"+c.Id+"/checkItems", payload) + body, err := c.client.Post("/checklist/"+c.ID+"/checkItems", payload) if err != nil { return nil, err } @@ -95,7 +98,7 @@ func (c *Checklist) AddItem(name string, pos *string, checked *bool) (*Checklist return nil, err } item.client = c.client - item.listID = c.Id + item.listID = c.ID return item, err } diff --git a/client.go b/client.go index 6af9682..b2dd707 100644 --- a/client.go +++ b/client.go @@ -24,6 +24,7 @@ import ( "strings" ) +// Client - Trello Client Type type Client struct { client *http.Client endpoint string @@ -48,6 +49,7 @@ func (c *Client) do(req *http.Request) ([]byte, error) { return body, nil } +// Get - HTTP GET func (c *Client) Get(resource string) ([]byte, error) { req, err := http.NewRequest("GET", c.endpoint+resource, nil) if err != nil { @@ -56,6 +58,7 @@ func (c *Client) Get(resource string) ([]byte, error) { return c.do(req) } +// Post - HTTP POST func (c *Client) Post(resource string, data url.Values) ([]byte, error) { req, err := http.NewRequest("POST", c.endpoint+resource, strings.NewReader(data.Encode())) if err != nil { @@ -66,6 +69,7 @@ func (c *Client) Post(resource string, data url.Values) ([]byte, error) { return c.do(req) } +// Put - HTTP PUT func (c *Client) Put(resource string, data url.Values) ([]byte, error) { req, err := http.NewRequest("PUT", c.endpoint+resource, strings.NewReader(data.Encode())) if err != nil { @@ -76,6 +80,7 @@ func (c *Client) Put(resource string, data url.Values) ([]byte, error) { return c.do(req) } +// Delete - HTTP DELETE func (c *Client) Delete(resource string) ([]byte, error) { req, err := http.NewRequest("DELETE", c.endpoint+resource, nil) if err != nil { @@ -85,13 +90,15 @@ func (c *Client) Delete(resource string) ([]byte, error) { return c.do(req) } -type bearerRoundTripper struct { +// BearerRoundTripper Type +type BearerRoundTripper struct { Delegate http.RoundTripper key string token *string } -func (b *bearerRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) { +// RoundTrip encodes key and token +func (b *BearerRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) { if b.Delegate == nil { b.Delegate = http.DefaultTransport } @@ -108,8 +115,8 @@ func (b *bearerRoundTripper) RoundTrip(req *http.Request) (*http.Response, error // See https://trello.com/app-key to get your applicationKey // See https://trello.com/1/connect?key=MYKEYFROMABOVE&name=MYAPPNAME&response_type=token&scope=read,write&expiration=1d // to get a read/write token good for 1 day -func NewBearerTokenTransport(applicationKey string, token *string) *bearerRoundTripper { - return &bearerRoundTripper{ +func NewBearerTokenTransport(applicationKey string, token *string) *BearerRoundTripper { + return &BearerRoundTripper{ key: applicationKey, token: token, } diff --git a/label.go b/label.go index 8505169..4aa1065 100644 --- a/label.go +++ b/label.go @@ -1,44 +1,51 @@ package trello import ( - "net/url" "encoding/json" + "net/url" ) +// Label - Label Type type Label struct { client *Client - Id string `json:"id"` - IdBoard string `json:"idBoard"` - Name string `json:"name"` - Color string `json:"color"` - Uses int `json:"uses"` + ID string `json:"id"` + IDBoard string `json:"idBoard"` + Name string `json:"name"` + Color string `json:"color"` + Uses int `json:"uses"` } +// UpdateName - Update Name on a Label (Update a Label) +// - https://developer.atlassian.com/cloud/trello/rest/api-group-labels/#api-labels-id-put func (l *Label) UpdateName(name string) (err error) { payload := url.Values{} payload.Set("value", name) - body, err := l.client.Put("/labels/" + l.Id + "/name", payload) + body, err := l.client.Put("/labels/"+l.ID+"/name", payload) if err != nil { return } return json.Unmarshal(body, l) } -//Color can be null +// UpdateColor - Update Color for Label (Update a Label) +// - https://developer.atlassian.com/cloud/trello/rest/api-group-labels/#api-labels-id-put +// Color can be null func (l *Label) UpdateColor(color string) (err error) { payload := url.Values{} payload.Set("value", color) - body, err := l.client.Put("/labels/" + l.Id + "/color", payload) + body, err := l.client.Put("/labels/"+l.ID+"/color", payload) if err != nil { return } return json.Unmarshal(body, l) } +// DeleteLabel - Delete a Label +// - https://developer.atlassian.com/cloud/trello/rest/api-group-labels/#api-labels-id-delete func (l *Label) DeleteLabel() error { - _, err := l.client.Delete("/labels/" + l.Id) + _, err := l.client.Delete("/labels/" + l.ID) return err } diff --git a/list.go b/list.go index 2c11870..b32acf4 100644 --- a/list.go +++ b/list.go @@ -23,18 +23,21 @@ import ( "strings" ) +// List - Trello List Type type List struct { client *Client - Id string `json:"id"` + ID string `json:"id"` Name string `json:"name"` Closed bool `json:"closed"` - IdBoard string `json:"idBoard"` + IDBoard string `json:"idBoard"` Pos float32 `json:"pos"` cards []Card } -func (c *Client) List(listId string) (list *List, err error) { - body, err := c.Get("/lists/" + listId) +// List - Get List by listID (string) +// - https://developer.atlassian.com/cloud/trello/rest/api-group-lists/#api-lists-id-get +func (c *Client) List(listID string) (list *List, err error) { + body, err := c.Get("/lists/" + listID) if err != nil { return } @@ -44,11 +47,13 @@ func (c *Client) List(listId string) (list *List, err error) { return } +// Cards - Get Cards in a List +// - https://developer.atlassian.com/cloud/trello/rest/api-group-lists/#api-lists-id-cards-get func (l *List) Cards() (cards []Card, err error) { if l.cards != nil { return l.cards, nil } - body, err := l.client.Get("/lists/" + l.Id + "/cards") + body, err := l.client.Get("/lists/" + l.ID + "/cards") if err != nil { return } @@ -64,13 +69,16 @@ func (l *List) Cards() (cards []Card, err error) { return } +// FreshCards - nil cards? func (l *List) FreshCards() (cards []Card, err error) { l.cards = nil return l.Cards() } +// Actions - Get Actions for a List +// - https://developer.atlassian.com/cloud/trello/rest/api-group-lists/#api-lists-id-actions-get func (l *List) Actions() (actions []Action, err error) { - body, err := l.client.Get("/lists/" + l.Id + "/actions") + body, err := l.client.Get("/lists/" + l.ID + "/actions") if err != nil { return } @@ -85,7 +93,7 @@ func (l *List) Actions() (actions []Action, err error) { // AddCard creates with the attributes of the supplied Card struct // https://developers.trello.com/advanced-reference/card#post-1-cards func (l *List) AddCard(opts Card) (*Card, error) { - opts.IdList = l.Id + opts.IDList = l.ID payload := url.Values{} payload.Set("name", opts.Name) @@ -96,8 +104,8 @@ func (l *List) AddCard(opts Card) (*Card, error) { payload.Set("pos", strconv.FormatFloat(opts.Pos, 'g', -1, 64)) } payload.Set("due", opts.Due) - payload.Set("idList", opts.IdList) - payload.Set("idMembers", strings.Join(opts.IdMembers, ",")) + payload.Set("idList", opts.IDList) + payload.Set("idMembers", strings.Join(opts.IDMembers, ",")) body, err := l.client.Post("/cards", payload) if err != nil { @@ -112,21 +120,24 @@ func (l *List) AddCard(opts Card) (*Card, error) { return &card, nil } +// Archive - Archive List //If mode is true, list is archived, otherwise it's unarchived (returns to the board) func (l *List) Archive(mode bool) error { payload := url.Values{} payload.Set("value", strconv.FormatBool(mode)) - _, err := l.client.Put("/lists/"+l.Id+"/closed", payload) + _, err := l.client.Put("/lists/"+l.ID+"/closed", payload) return err } +// Move - Move a List (Update a List) +// - https://developer.atlassian.com/cloud/trello/rest/api-group-lists/#api-lists-id-put //pos can be "bottom", "top" or a positive number func (l *List) Move(pos string) (*List, error) { payload := url.Values{} payload.Set("value", pos) - body, err := l.client.Put("/lists/"+l.Id+"/pos", payload) + body, err := l.client.Put("/lists/"+l.ID+"/pos", payload) if err != nil { return nil, err } diff --git a/member.go b/member.go index a1f9eff..0db86b0 100644 --- a/member.go +++ b/member.go @@ -22,9 +22,10 @@ import ( "strings" ) +// Member tello member struct type Member struct { client *Client - Id string `json:"id"` + ID string `json:"id"` AvatarHash string `json:"avatarHash"` Bio string `json:"bio"` BioData struct { @@ -32,19 +33,19 @@ type Member struct { } `json:"bioData"` Confirmed bool `json:"confirmed"` FullName string `json:"fullName"` - IdPremOrgsAdmin []string `json:"idPremOrgsAdmin"` + IDPremOrgsAdmin []string `json:"idPremOrgsAdmin"` Initials string `json:"initials"` MemberType string `json:"memberType"` Products []int `json:"products"` Status string `json:"status"` - Url string `json:"url"` + URL string `json:"url"` Username string `json:"username"` AvatarSource string `json:"avatarSource"` Email string `json:"email"` GravatarHash string `json:"gravatarHash"` - IdBoards []string `json:"idBoards"` - IdBoardsPinned []string `json:"idBoardsPinned"` - IdOrganizations []string `json:"idOrganizations"` + IDBoards []string `json:"idBoards"` + IDBoardsPinned []string `json:"idBoardsPinned"` + IDOrganizations []string `json:"idOrganizations"` LoginTypes []string `json:"loginTypes"` NewEmail string `json:"newEmail"` OneTimeMessagesDismissed []string `json:"oneTimeMessagesDismissed"` @@ -60,6 +61,8 @@ type Member struct { PremiumFeatures []string `json:"premiumFeatures"` } +// Member returns a member (NOTE: "me" defaults to yourself) +// - https://developer.atlassian.com/cloud/trello/rest/api-group-members/#api-members-id-get func (c *Client) Member(nick string) (member *Member, err error) { body, err := c.Get("/members/" + nick) if err != nil { @@ -71,6 +74,8 @@ func (c *Client) Member(nick string) (member *Member, err error) { return } +// Boards returns members boards +// - https://developer.atlassian.com/cloud/trello/rest/api-group-members/#api-members-id-boards-get func (m *Member) Boards(field ...string) (boards []Board, err error) { fields := "" if len(field) == 0 { @@ -79,7 +84,7 @@ func (m *Member) Boards(field ...string) (boards []Board, err error) { fields = strings.Join(field, ",") } - body, err := m.client.Get("/members/" + m.Id + "/boards?fields=" + fields) + body, err := m.client.Get("/members/" + m.ID + "/boards?fields=" + fields) if err != nil { return } @@ -92,6 +97,7 @@ func (m *Member) Boards(field ...string) (boards []Board, err error) { } // AddBoard creates a new Board +// - https://developer.atlassian.com/cloud/trello/rest/api-group-boards/#api-boards-post func (m *Member) AddBoard(name string) (*Board, error) { payload := url.Values{} @@ -110,8 +116,9 @@ func (m *Member) AddBoard(name string) (*Board, error) { return &board, nil } +// Notifications - https://developer.atlassian.com/cloud/trello/rest/api-group-members/#api-members-id-notifications-get func (m *Member) Notifications() (notifications []Notification, err error) { - body, err := m.client.Get("/members/" + m.Id + "/notifications") + body, err := m.client.Get("/members/" + m.ID + "/notifications") if err != nil { return } @@ -123,7 +130,8 @@ func (m *Member) Notifications() (notifications []Notification, err error) { return } +// AvatarURL returns avatar URL for member // TODO: Avatar sizes [170, 30] -func (m *Member) AvatarUrl() string { +func (m *Member) AvatarURL() string { return "https://trello-avatars.s3.amazonaws.com/" + m.AvatarHash + "/170.png" } diff --git a/notification.go b/notification.go index ddcdfe8..fcc1f84 100644 --- a/notification.go +++ b/notification.go @@ -18,39 +18,40 @@ package trello import "encoding/json" +// Notification - Trello Notification Type type Notification struct { client *Client - Id string `json:"id"` + ID string `json:"id"` Unread bool `json:"unread"` Type string `json:"type"` Date string `json:"date"` Data struct { ListBefore struct { - Id string `json:"id"` + ID string `json:"id"` Name string `json:"name"` } `json:"listBefore"` ListAfter struct { - Id string `json:"id"` + ID string `json:"id"` Name string `json:"name"` } `json:"listAfter"` Board struct { - Id string `json:"id"` + ID string `json:"id"` Name string `json:"name"` ShortLink string `json:"shortLink"` } `json:"board"` Card struct { - Id string `json:"id"` + ID string `json:"id"` Name string `json:"name"` ShortLink string `json:"shortLink"` - IdShort int `json:"idShort"` + IDShort int `json:"idShort"` } `json:"card"` Old struct { - IdList string `json:"idList"` + IDList string `json:"idList"` } `json:"old"` } `json:"data"` - IdMemberCreator string `json:"idMemberCreator"` + IDMemberCreator string `json:"idMemberCreator"` MemberCreator struct { - Id string `json:"id"` + ID string `json:"id"` AvatarHash string `json:"avatarHash"` FullName string `json:"fullName"` Initials string `json:"initials"` @@ -58,8 +59,10 @@ type Notification struct { } `json:"memberCreator"` } -func (c *Client) Notification(notificationId string) (notification *Notification, err error) { - body, err := c.Get("/notifications/" + notificationId) +// Notification - Get Notification by notificationId (string) +// - https://developer.atlassian.com/cloud/trello/rest/api-group-notifications/#api-notifications-id-get +func (c *Client) Notification(notificationID string) (notification *Notification, err error) { + body, err := c.Get("/notifications/" + notificationID) if err != nil { return } diff --git a/organization.go b/organization.go index 989cd74..9c2dbf3 100644 --- a/organization.go +++ b/organization.go @@ -21,22 +21,25 @@ import ( "net/url" ) +// Organization - Trello Organization Type type Organization struct { client *Client - Id string `json:"id"` + ID string `json:"id"` Name string `json:"name"` DisplayName string `json:"displayName"` Desc string `json:"desc"` DescData string `json:"descData"` - Url string `json:"url"` + URL string `json:"url"` Website string `json:"website"` LogoHash string `json:"logoHash"` Products []string `json:"products"` PowerUps []string `json:"powerUps"` } -func (c *Client) Organization(orgId string) (organization *Organization, err error) { - body, err := c.Get("/organization/" + orgId) +// Organization - Get Organization by orgId (string) +// - https://developer.atlassian.com/cloud/trello/rest/api-group-organizations/#api-organizations-id-get +func (c *Client) Organization(orgID string) (organization *Organization, err error) { + body, err := c.Get("/organization/" + orgID) if err != nil { return } @@ -46,8 +49,10 @@ func (c *Client) Organization(orgId string) (organization *Organization, err err return } +// Members - Get the Members of an Organization +// - https://developer.atlassian.com/cloud/trello/rest/api-group-organizations/#api-organizations-id-members-get func (o *Organization) Members() (members []Member, err error) { - body, err := o.client.Get("/organization/" + o.Id + "/members") + body, err := o.client.Get("/organization/" + o.ID + "/members") if err != nil { return } @@ -59,8 +64,10 @@ func (o *Organization) Members() (members []Member, err error) { return } +// Boards - Get Boards in an Organization +// - https://developer.atlassian.com/cloud/trello/rest/api-group-organizations/#api-organizations-id-boards-get func (o *Organization) Boards() (boards []Board, err error) { - body, err := o.client.Get("/organizations/" + o.Id + "/boards") + body, err := o.client.Get("/organizations/" + o.ID + "/boards") if err != nil { return } @@ -72,12 +79,13 @@ func (o *Organization) Boards() (boards []Board, err error) { return } -// AddBoard creates a new Board +// AddBoard - Create a new Board in the organization +// - https://developer.atlassian.com/cloud/trello/rest/api-group-boards/#api-boards-post func (o *Organization) AddBoard(name string) (*Board, error) { payload := url.Values{} payload.Set("name", name) - payload.Set("idOrganization", o.Id) + payload.Set("idOrganization", o.ID) body, err := o.client.Post("/boards", payload) if err != nil { diff --git a/tests/client_test.go b/tests/client_test.go index 858afd4..5de324f 100644 --- a/tests/client_test.go +++ b/tests/client_test.go @@ -20,7 +20,7 @@ import ( "os" "testing" - "github.com/VojtechVitek/go-trello" + "github.com/TJM/go-trello" . "github.com/franela/goblin" . "github.com/onsi/gomega" diff --git a/version.go b/version.go index c916470..9acd315 100644 --- a/version.go +++ b/version.go @@ -16,6 +16,7 @@ limitations under the License. package trello +// Version - Trello API Version func (c *Client) Version() string { return c.version } diff --git a/webhook.go b/webhook.go index 82b2208..ba348f5 100644 --- a/webhook.go +++ b/webhook.go @@ -6,6 +6,7 @@ import ( "net/url" ) +// Webhook - Trello Webhook Type type Webhook struct { ID string `json:"id"` Description string `json:"description"` @@ -14,6 +15,8 @@ type Webhook struct { Active bool `json:"active"` } +// Webhooks - Get Webhooks for a token (string) +// https://developer.atlassian.com/cloud/trello/rest/api-group-tokens/#api-tokens-token-webhooks-get func (c *Client) Webhooks(token string) (webhooks []Webhook, err error) { body, err := c.Get(webhookURL(token)) @@ -24,6 +27,8 @@ func (c *Client) Webhooks(token string) (webhooks []Webhook, err error) { return } +// CreateWebhook - Create a Webhook +// - https://developer.atlassian.com/cloud/trello/rest/api-group-webhooks/#api-webhooks-post func (c *Client) CreateWebhook(hook Webhook) (webhook Webhook, err error) { payload := url.Values{} @@ -38,6 +43,8 @@ func (c *Client) CreateWebhook(hook Webhook) (webhook Webhook, err error) { return } +// Webhook - Get Webhook by id (string) +// - https://developer.atlassian.com/cloud/trello/rest/api-group-webhooks/#api-webhooks-id-get func (c *Client) Webhook(webhookID string) (webhook Webhook, err error) { url := fmt.Sprintf("/webhooks/%s/", webhookID) @@ -49,6 +56,8 @@ func (c *Client) Webhook(webhookID string) (webhook Webhook, err error) { return } +// DeleteWebhook - Delete a Webhook by id (string) +// - https://developer.atlassian.com/cloud/trello/rest/api-group-webhooks/#api-webhooks-id-delete func (c *Client) DeleteWebhook(webhookID string) (err error) { url := fmt.Sprintf("/webhooks/%s/", webhookID)