Categorygithub.com/glenux/contrib-trello
modulepackage
0.0.0-20201205174556-59811d0e2f92
Repository: https://github.com/glenux/contrib-trello.git
Documentation: pkg.go.dev

# README

Go Trello API

Trello Logo

GoDoc Build Status Coverage Status

A #golang package to access the Trello API. Nearly 100% of the read-only surface area of the API is covered, as is creation and modification of Cards. Low-level infrastructure for features to modify Lists and Boards are easy to add... just not done yet.

Pull requests are welcome for missing features.

My current development focus is documentation, especially enhancing this README.md with more example use cases.

Installation

The Go Trello API has been Tested compatible with Go 1.7 on up. Its only dependency is the github.com/pkg/errors package. It otherwise relies only on the Go standard library.

go get github.com/adlio/trello

Basic Usage

All interaction starts with a trello.Client. Create one with your appKey and token:

client := trello.NewClient(appKey, token)

All API requests accept a trello.Arguments object. This object is a simple map[string]string, converted to query string arguments in the API call. Trello has sane defaults on API calls. We have a trello.Defaults() utility function which can be used when you desire the default Trello arguments. Internally, trello.Defaults() is an empty map, which translates to an empty query string.

board, err := client.GetBoard("bOaRdID", trello.Defaults())
if err != nil {
  // Handle error
}

Client Longevity

When getting Lists from Boards or Cards from Lists, the original trello.Client pointer is carried along in returned child objects. It's important to realize that this enables you to make additional API calls via functions invoked on the objects you receive:

client := trello.NewClient(appKey, token)
board, err := client.GetBoard("ID", trello.Defaults())

// GetLists makes an API call to /boards/:id/lists using credentials from `client`
lists, err := board.GetLists(trello.Defaults())

for _, list := range lists {
  // GetCards makes an API call to /lists/:id/cards using credentials from `client`
  cards, err := list.GetCards(trello.Defaults())
}

Get Trello Boards for a User

Boards can be retrieved directly by their ID (see example above), or by asking for all boards for a member:

member, err := client.GetMember("usernameOrId", trello.Defaults())
if err != nil {
  // Handle error
}

boards, err := member.GetBoards(trello.Defaults())
if err != nil {
  // Handle error
}

Get Trello Lists on a Board

board, err := client.GetBoard("bOaRdID", trello.Defaults())
if err != nil {
  // Handle error
}

lists, err := board.GetLists(trello.Defaults())
if err != nil {
  // Handle error
}

Get Trello Cards on a Board

board, err := client.GetBoard("bOaRdID", trello.Defaults())
if err != nil {
  // Handle error
}

cards, err := board.GetCards(trello.Defaults())
if err != nil {
  // Handle error
}

Get Trello Cards on a List

list, err := client.GetList("lIsTID", trello.Defaults())
if err != nil {
  // Handle error
}

cards, err := list.GetCards(trello.Defaults())
if err != nil {
  // Handle error
}

Creating and deleting a Board

A board can be created or deleted on the Board struct for the user whose credentials are being used.

  board := trello.NewBoard("My bucket list")

  // POST
  err := client.CreateBoard(&board, trello.Defaults())

  // DELETE
  err := board.Delete(trello.Defaults())
  if err != nil {
    fmt.Println(err)
  }
}

Adding a new Member to the Board

  board, err := client.GetBoard("bOaRdID", trello.Defaults())
  if err != nil {
    // Handle error
  }

  member := Member{Email: "[email protected]"}
  _, err := board.AddMember(&member, trello.Defaults()) 

  if err != nil {
    // Handle error
  }

Archiving, Unarchiving & Deleting a Card

// archive
err := card.Archive()

// unarchive
err := card.Unarchive()

// delete
err := card.Delete()

Creating a Card

The API provides several mechanisms for creating new cards.

Creating Cards from Scratch on the Client

This approach requires the most input data on the card:

card := trello.Card{
  Name: "Card Name",
  Desc: "Card description",
  Pos: 12345.678,
  IDList: "iDOfaLiSt",
  IDLabels: []string{"labelID1", "labelID2"},
}
err := client.CreateCard(card, trello.Defaults())

Creating Cards On a List

list, err := client.GetList("lIsTID", trello.Defaults())
list.AddCard(&trello.Card{ Name: "Card Name", Desc: "Card description" }, trello.Defaults())

Creating a Card by Copying Another Card

err := card.CopyToList("listIdNUmber", trello.Defaults())

Get Actions on a Board

board, err := client.GetBoard("bOaRdID", trello.Defaults())
if err != nil {
  // Handle error
}

actions, err := board.GetActions(trello.Defaults())
if err != nil {
  // Handle error
}

Get Actions on a Card

card, err := client.GetCard("cArDID", trello.Defaults())
if err != nil {
  // Handle error
}

actions, err := card.GetActions(trello.Defaults())
if err != nil {
  // Handle error
}

Rearrange Cards Within a List

err := card.MoveToTopOfList()
err = card.MoveToBottomOfList()
err = card.SetPos(12345.6789)

Moving a Card to Another List

err := card.MoveToList("listIdNUmber", trello.Defaults())

Card Ancestry

Trello provides ancestry tracking when cards are created as copies of other cards. This package provides functions for working with this data:


// ancestors will hold a slice of *trello.Cards, with the first
// being the card's parent, and the last being parent's parent's parent...
ancestors, err := card.GetAncestorCards(trello.Defaults())

// GetOriginatingCard() is an alias for the last element in the slice
// of ancestor cards.
ultimateParentCard, err := card.GetOriginatingCard(trello.Defaults())

Debug Logging

If you'd like to see all API calls logged, you can attach a .Logger (implementing Debugf(string, ...interface{})) to your client. The interface for the logger mimics logrus. Example usage:

logger := logrus.New()
logger.SetLevel(logrus.DebugLevel)
client := trello.NewClient(appKey, token)
client.Logger = logger

# Functions

Defaults is a constructor for default Arguments.
GetBoardWebhookRequest takes a http.Request and returns the decoded body as BoardWebhookRequest or an error.
GetCardWebhookRequest takes a http.Request and returns the decoded Body as CardWebhookRequest or an error.
GetListWebhookRequest takes a http.Request and returns the decoded Body as ListWebhookRequest or an error.
IDToTime is a convenience function.
IsNotFound takes an error and returns true exactly if the error is a not-found error.
IsPermissionDenied takes an error and returns true exactly if the error is a permission-denied error.
IsRateLimit takes an error and returns true exactly if the error is a rate-limit error.
ListAfterAction calculates which List the card ended up in after this action completed.
NewBoard is a constructor that sets the default values for Prefs.SelfJoin and Prefs.CardCovers also set by the API.
NewClient is a constructor for the Client.
NewCustomFieldValue the custom field constructor.

# Constants

DefaultBaseURL is the default API base url used by Client to send requests to Trello.

# Structs

Action represents Trello API actions Actions are immutable event traces generated whenever an action occurs in Trello.
ActionData represent the nested data of actions.
ActionDataCard represent the nested 'card' data attribute of actions.
AddedMembersResponse represents a response after adding a new member.
Attachment represent the attachments of cards.
AttachmentPreview is a nested attribute of Attachment.
BackgroundImage is a nested resource of Board.
Board represents a Trello Board.
BoardWebhookRequest is the object sent by Trello to a Webhook for Board-triggered webhooks.
Card represents the card resource.
CardWebhookRequest is the object sent by Trello to a Webhook for Card-triggered webhooks.
CheckItem is a nested resource representing an item in Checklist.
CheckItemState represents a CheckItem when it appears in CheckItemStates on a Card.
Checklist represents Trello card's checklists.
Client is the central object for making API calls.
CustomField represents Trello's custom fields: "extra bits of structured data attached to cards when our users need a bit more than what Trello provides." https://developers.trello.com/reference/#custom-fields.
CustomFieldItem represents the custom field items of Trello a trello card.
CustomFieldOption are nested resources of CustomFields.
CustomFieldValue represents the custom field value struct.
Label represents a Trello label.
List represents Trello lists.
ListDuration represents the time a Card has been or was in list.
ListWebhookRequest is the object sent by Trello to a Webhook for List-triggered webhooks.
Member represents a Trello member.
MemberDuration is used to track the periods of time which a user (member) is attached to a card.
Membership represents a Trello membership.
Notification represents a Trello Notification.
NotificationData represents the 'notificaiton.data'.
NotificationDataBoard represents the 'notification.data.board'.
NotificationDataCard represents the 'notification.data.card'.
Organization represents a Trello organization or team, i.e.
Permission represent a Token's permissions.
SearchModifier is wrapper for a search string.
SearchOptions contains options for search requests.
SearchResult represents a search result as collections of various types returned by a search, e.g.
SearchTerm is a string that may be negated in a search query.
Token represents Trello tokens.
Webhook is the Go representation of a webhook registered in Trello's systems.

# Type aliases

ActionCollection is an alias of []*Action, which sorts by the Action's ID.
Arguments are used for passing URL parameters to the client for making API calls.
ByFirstEntered is a slice of ListDurations.
ByLongestDuration is a slice of *MemberDuration.