1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Vendoring dependencies

This commit is contained in:
Chris Cummer
2019-07-15 09:06:49 -07:00
parent 122ea31e45
commit 2b19ccea1c
1980 changed files with 805966 additions and 0 deletions

28
vendor/github.com/adlio/trello/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,28 @@
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so
# Folders
_obj
_test
# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out
*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*
_testmain.go
*.exe
*.test
*.prof
coverage.sh
coverage.out
coverage.html

33
vendor/github.com/adlio/trello/.travis.yml generated vendored Normal file
View File

@@ -0,0 +1,33 @@
language: go
sudo: false
go:
- 1.7
- 1.8
- 1.9
- '1.10'
- 1.11.x
- master
install:
- go get github.com/pkg/errors
# golint is no longer available for go versions 1.7 and 1.8
- |
INSTALLED_GO_VERSION=`go version | sed 's/go version go\(.*\) .*/\1/'`
echo $INSTALLED_GO_VERSION
if [ "$INSTALLED_GO_VERSION" != "1.7" ] && [ "$INSTALLED_GO_VERSION" != "1.8" ]; then
go get golang.org/x/lint/golint
fi
before_script:
- |
which golint;
if [ $? == 0 ]; then
golint ./...
fi
go vet
script:
- go test -v -race -coverprofile=coverage.txt -covermode=atomic
after_success:
- bash <(curl -s https://codecov.io/bash)

21
vendor/github.com/adlio/trello/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2016 Aaron Longwell
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

250
vendor/github.com/adlio/trello/README.md generated vendored Normal file
View File

@@ -0,0 +1,250 @@
Go Trello API
================
[![Trello Logo](https://raw.githubusercontent.com/adlio/trello/master/trello-logo.png)](https://www.trello.com)
[![GoDoc](https://godoc.org/github.com/adlio/trello?status.svg)](http://godoc.org/github.com/adlio/trello)
[![Build Status](https://travis-ci.org/adlio/trello.svg)](https://travis-ci.org/adlio/trello)
[![Coverage Status](https://coveralls.io/repos/github/adlio/trello/badge.svg?branch=master)](https://coveralls.io/github/adlio/trello?branch=master)
A #golang package to access the [Trello API](https://developers.trello.com/v1.0/reference). 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:
```Go
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.
```Go
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:
```Go
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:
```Go
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
```Go
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
```Go
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
```Go
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.
```Go
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)
}
}
```
## 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:
```Go
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
```Go
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
```Go
err := card.CopyToList("listIdNUmber", trello.Defaults())
```
## Get Actions on a Board
```Go
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
```Go
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
```Go
err := card.MoveToTopOfList()
err = card.MoveToBottomOfList()
err = card.SetPos(12345.6789)
```
## Moving a Card to Another List
```Go
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:
```Go
// 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:
```Go
logger := logrus.New()
logger.SetLevel(logrus.DebugLevel)
client := trello.NewClient(appKey, token)
client.Logger = logger
```

5
vendor/github.com/adlio/trello/TODO.txt generated vendored Normal file
View File

@@ -0,0 +1,5 @@
- Create List
- Delete Card
- Archive Card
- Reorder Cards in List

62
vendor/github.com/adlio/trello/action-collection.go generated vendored Normal file
View File

@@ -0,0 +1,62 @@
package trello
import (
"sort"
)
// ActionCollection is an alias of []*Action, which sorts by the Action's ID.
// Which is the same as sorting by the Action's time of occurrence
type ActionCollection []*Action
func (c ActionCollection) Len() int { return len(c) }
func (c ActionCollection) Swap(i, j int) { c[i], c[j] = c[j], c[i] }
func (c ActionCollection) Less(i, j int) bool { return c[i].ID < c[j].ID }
// FirstCardCreateAction returns first card-create action
func (c ActionCollection) FirstCardCreateAction() *Action {
sort.Sort(c)
for _, action := range c {
if action.DidCreateCard() {
return action
}
}
return nil
}
// ContainsCardCreation returns true if collection contains a card-create action
func (c ActionCollection) ContainsCardCreation() bool {
return c.FirstCardCreateAction() != nil
}
// FilterToCardCreationActions returns this collection's card-create actions
func (c ActionCollection) FilterToCardCreationActions() ActionCollection {
newSlice := make(ActionCollection, 0, len(c))
for _, action := range c {
if action.DidCreateCard() {
newSlice = append(newSlice, action)
}
}
return newSlice
}
// FilterToListChangeActions returns card-change-list actions
func (c ActionCollection) FilterToListChangeActions() ActionCollection {
newSlice := make(ActionCollection, 0, len(c))
for _, action := range c {
if action.DidChangeListForCard() {
newSlice = append(newSlice, action)
}
}
return newSlice
}
// FilterToCardMembershipChangeActions returns the collection's card-change, archive and unarchive actions
func (c ActionCollection) FilterToCardMembershipChangeActions() ActionCollection {
newSlice := make(ActionCollection, 0, len(c))
for _, action := range c {
if action.DidChangeCardMembership() || action.DidArchiveCard() || action.DidUnarchiveCard() {
newSlice = append(newSlice, action)
}
}
return newSlice
}

169
vendor/github.com/adlio/trello/action.go generated vendored Normal file
View File

@@ -0,0 +1,169 @@
// Copyright © 2016 Aaron Longwell
//
// Use of this source code is governed by an MIT licese.
// Details in the LICENSE file.
package trello
import (
"fmt"
"time"
)
// Action represents Trello API actions
// Actions are immutable event traces generated whenever an action occurs in Trello.
// See https://developers.trello.com/reference/#actions.
type Action struct {
ID string `json:"id"`
IDMemberCreator string `json:"idMemberCreator"`
Type string `json:"type"`
Date time.Time `json:"date"`
Data *ActionData `json:"data,omitempty"`
MemberCreator *Member `json:"memberCreator,omitempty"`
Member *Member `json:"member,omitempty"`
}
// ActionData represent the nested data of actions
type ActionData struct {
Text string `json:"text,omitempty"`
List *List `json:"list,omitempty"`
Card *ActionDataCard `json:"card,omitempty"`
CardSource *ActionDataCard `json:"cardSource,omitempty"`
Board *Board `json:"board,omitempty"`
Old *ActionDataCard `json:"old,omitempty"`
ListBefore *List `json:"listBefore,omitempty"`
ListAfter *List `json:"listAfter,omitempty"`
DateLastEdited time.Time `json:"dateLastEdited"`
CheckItem *CheckItem `json:"checkItem"`
Checklist *Checklist `json:"checklist"`
}
// ActionDataCard represent the nested 'card' data attribute of actions
type ActionDataCard struct {
ID string `json:"id"`
Name string `json:"name"`
IDShort int `json:"idShort"`
ShortLink string `json:"shortLink"`
Pos float64 `json:"pos"`
Closed bool `json:"closed"`
}
// GetActions make a GET call for a board's actions
func (b *Board) GetActions(args Arguments) (actions ActionCollection, err error) {
path := fmt.Sprintf("boards/%s/actions", b.ID)
err = b.client.Get(path, args, &actions)
return
}
// GetActions makes a GET call for a list's actions
func (l *List) GetActions(args Arguments) (actions ActionCollection, err error) {
path := fmt.Sprintf("lists/%s/actions", l.ID)
err = l.client.Get(path, args, &actions)
return
}
// GetActions makes a GET for a card's actions
func (c *Card) GetActions(args Arguments) (actions ActionCollection, err error) {
path := fmt.Sprintf("cards/%s/actions", c.ID)
err = c.client.Get(path, args, &actions)
return
}
// GetListChangeActions retrieves a slice of Actions which resulted in changes
// to the card's active List. This includes the createCard and copyCard action (which
// place the card in its first list), and the updateCard:closed action (which remove it
// from its last list).
//
// This function is just an alias for:
// card.GetActions(Arguments{"filter": "createCard,copyCard,updateCard:idList,updateCard:closed", "limit": "1000"})
//
func (c *Card) GetListChangeActions() (actions ActionCollection, err error) {
return c.GetActions(Arguments{"filter": "createCard,copyCard,updateCard:idList,updateCard:closed"})
}
// GetMembershipChangeActions makes a GET call for a card's membership-change actions
func (c *Card) GetMembershipChangeActions() (actions ActionCollection, err error) {
// We include updateCard:closed as if the member is implicitly removed from the card when it's closed.
// This allows us to "close out" the duration length.
return c.GetActions(Arguments{"filter": "addMemberToCard,removeMemberFromCard,updateCard:closed"})
}
// DidCreateCard returns true if this action created a card, false otherwise.
func (a *Action) DidCreateCard() bool {
switch a.Type {
case "createCard", "emailCard", "copyCard", "convertToCardFromCheckItem":
return true
case "moveCardToBoard":
return true // Unsure about this one
default:
return false
}
}
// DidArchiveCard returns true if the card was updated
func (a *Action) DidArchiveCard() bool {
return (a.Type == "updateCard") && a.Data != nil && a.Data.Card != nil && a.Data.Card.Closed
}
// DidUnarchiveCard returns true if the card was unarchived
func (a *Action) DidUnarchiveCard() bool {
return (a.Type == "updateCard") && a.Data != nil && a.Data.Old != nil && a.Data.Old.Closed
}
// DidChangeListForCard returns true if this action created the card (in which case it
// caused it to enter its first list), archived the card (in which case it caused it to
// leave its last List), or was an updateCard action involving a change to the list. This
// is supporting functionality for ListDuration.
//
func (a *Action) DidChangeListForCard() bool {
if a.DidCreateCard() {
return true
}
if a.DidArchiveCard() {
return true
}
if a.DidUnarchiveCard() {
return true
}
if a.Type == "updateCard" {
if a.Data != nil && a.Data.ListAfter != nil {
return true
}
}
return false
}
// DidChangeCardMembership returns true if card's membership was changed
func (a *Action) DidChangeCardMembership() bool {
switch a.Type {
case "addMemberToCard":
return true
case "removeMemberFromCard":
return true
default:
return false
}
}
// ListAfterAction calculates which List the card ended up in after this action
// completed. Returns nil when the action resulted in the card being archived (in
// which case we consider it to not be in a list anymore), or when the action isn't
// related to a list at all (in which case this is a nonsensical question to ask).
//
func ListAfterAction(a *Action) *List {
switch a.Type {
case "createCard", "copyCard", "emailCard", "convertToCardFromCheckItem":
return a.Data.List
case "updateCard":
if a.DidArchiveCard() {
return nil
} else if a.DidUnarchiveCard() {
return a.Data.List
}
if a.Data.ListAfter != nil {
return a.Data.ListAfter
}
}
return nil
}

27
vendor/github.com/adlio/trello/arguments.go generated vendored Normal file
View File

@@ -0,0 +1,27 @@
// Copyright © 2016 Aaron Longwell
//
// Use of this source code is governed by an MIT licese.
// Details in the LICENSE file.
package trello
import (
"net/url"
)
// Arguments are used for passing URL parameters to the client for making API calls.
type Arguments map[string]string
// Defaults is a constructor for default Arguments.
func Defaults() Arguments {
return make(Arguments)
}
// ToURLValues returns the argument's URL value representation.
func (args Arguments) ToURLValues() url.Values {
v := url.Values{}
for key, value := range args {
v.Set(key, value)
}
return v
}

32
vendor/github.com/adlio/trello/attachment.go generated vendored Normal file
View File

@@ -0,0 +1,32 @@
// Copyright © 2016 Aaron Longwell
//
// Use of this source code is governed by an MIT licese.
// Details in the LICENSE file.
package trello
// Attachment represent the attachments of cards. This is a nested resource of Card.
// https://developers.trello.com/reference/#attachments
type Attachment struct {
ID string `json:"id"`
Name string `json:"name"`
Pos float32 `json:"pos"`
Bytes int `json:"int"`
Date string `json:"date"`
EdgeColor string `json:"edgeColor"`
IDMember string `json:"idMember"`
IsUpload bool `json:"isUpload"`
MimeType string `json:"mimeType"`
Previews []AttachmentPreview `json:"previews"`
URL string `json:"url"`
}
// AttachmentPreview is a nested attribute of Attachment.
type AttachmentPreview struct {
ID string `json:"_id"`
URL string `json:"url"`
Width int `json:"width"`
Height int `json:"height"`
Bytes int `json:"bytes"`
Scaled bool `json:"scaled"`
}

167
vendor/github.com/adlio/trello/board.go generated vendored Normal file
View File

@@ -0,0 +1,167 @@
// Copyright © 2016 Aaron Longwell
//
// Use of this source code is governed by an MIT licese.
// Details in the LICENSE file.
package trello
import (
"fmt"
"time"
)
// Board represents a Trello Board.
// https://developers.trello.com/reference/#boardsid
type Board struct {
client *Client
ID string `json:"id"`
Name string `json:"name"`
Desc string `json:"desc"`
Closed bool `json:"closed"`
IDOrganization string `json:"idOrganization"`
Pinned bool `json:"pinned"`
URL string `json:"url"`
ShortURL string `json:"shortUrl"`
Prefs struct {
PermissionLevel string `json:"permissionLevel"`
Voting string `json:"voting"`
Comments string `json:"comments"`
Invitations string `json:"invitations"`
SelfJoin bool `json:"selfjoin"`
CardCovers bool `json:"cardCovers"`
CardAging string `json:"cardAging"`
CalendarFeedEnabled bool `json:"calendarFeedEnabled"`
Background string `json:"background"`
BackgroundColor string `json:"backgroundColor"`
BackgroundImage string `json:"backgroundImage"`
BackgroundImageScaled []BackgroundImage `json:"backgroundImageScaled"`
BackgroundTile bool `json:"backgroundTile"`
BackgroundBrightness string `json:"backgroundBrightness"`
CanBePublic bool `json:"canBePublic"`
CanBeOrg bool `json:"canBeOrg"`
CanBePrivate bool `json:"canBePrivate"`
CanInvite bool `json:"canInvite"`
} `json:"prefs"`
LabelNames struct {
Black string `json:"black,omitempty"`
Blue string `json:"blue,omitempty"`
Green string `json:"green,omitempty"`
Lime string `json:"lime,omitempty"`
Orange string `json:"orange,omitempty"`
Pink string `json:"pink,omitempty"`
Purple string `json:"purple,omitempty"`
Red string `json:"red,omitempty"`
Sky string `json:"sky,omitempty"`
Yellow string `json:"yellow,omitempty"`
} `json:"labelNames"`
Lists []*List `json:"lists"`
Actions []*Action `json:"actions"`
Organization Organization `json:"organization"`
}
// NewBoard is a constructor that sets the default values
// for Prefs.SelfJoin and Prefs.CardCovers also set by the API.
func NewBoard(name string) Board {
b := Board{Name: name}
// default values in line with API POST
b.Prefs.SelfJoin = true
b.Prefs.CardCovers = true
return b
}
// BackgroundImage is a nested resource of Board.
type BackgroundImage struct {
Width int `json:"width"`
Height int `json:"height"`
URL string `json:"url"`
}
// CreatedAt returns a board's created-at attribute as time.Time.
func (b *Board) CreatedAt() time.Time {
t, _ := IDToTime(b.ID)
return t
}
// CreateBoard creates a board remote.
// Attribute currently supported as exra argument: powerUps.
// Attributes currently known to be unsupported: idBoardSource, keepFromSource.
//
// API Docs: https://developers.trello.com/reference/#boardsid
func (c *Client) CreateBoard(board *Board, extraArgs Arguments) error {
path := "boards"
args := Arguments{
"desc": board.Desc,
"name": board.Name,
"prefs_selfJoin": fmt.Sprintf("%t", board.Prefs.SelfJoin),
"prefs_cardCovers": fmt.Sprintf("%t", board.Prefs.CardCovers),
"idOrganization": board.IDOrganization,
}
if board.Prefs.Voting != "" {
args["prefs_voting"] = board.Prefs.Voting
}
if board.Prefs.PermissionLevel != "" {
args["prefs_permissionLevel"] = board.Prefs.PermissionLevel
}
if board.Prefs.Comments != "" {
args["prefs_comments"] = board.Prefs.Comments
}
if board.Prefs.Invitations != "" {
args["prefs_invitations"] = board.Prefs.Invitations
}
if board.Prefs.Background != "" {
args["prefs_background"] = board.Prefs.Background
}
if board.Prefs.CardAging != "" {
args["prefs_cardAging"] = board.Prefs.CardAging
}
// Expects one of "all", "calendar", "cardAging", "recap", or "voting".
if powerUps, ok := extraArgs["powerUps"]; ok {
args["powerUps"] = powerUps
}
err := c.Post(path, args, &board)
if err == nil {
board.client = c
}
return err
}
// Delete makes a DELETE call for the receiver Board.
func (b *Board) Delete(extraArgs Arguments) error {
path := fmt.Sprintf("boards/%s", b.ID)
return b.client.Delete(path, Arguments{}, b)
}
// GetBoard retrieves a Trello board by its ID.
func (c *Client) GetBoard(boardID string, args Arguments) (board *Board, err error) {
path := fmt.Sprintf("boards/%s", boardID)
err = c.Get(path, args, &board)
if board != nil {
board.client = c
}
return
}
// GetMyBoards returns a slice of all boards associated with the credentials set on the client.
func (c *Client) GetMyBoards(args Arguments) (boards []*Board, err error) {
path := "members/me/boards"
err = c.Get(path, args, &boards)
for i := range boards {
boards[i].client = c
}
return
}
// GetBoards returns a slice of all public boards of the receiver Member.
func (m *Member) GetBoards(args Arguments) (boards []*Board, err error) {
path := fmt.Sprintf("members/%s/boards", m.ID)
err = m.client.Get(path, args, &boards)
for i := range boards {
boards[i].client = m.client
}
return
}

487
vendor/github.com/adlio/trello/card.go generated vendored Normal file
View File

@@ -0,0 +1,487 @@
// Copyright © 2016 Aaron Longwell
//
// Use of this source code is governed by an MIT licese.
// Details in the LICENSE file.
package trello
import (
"fmt"
"strconv"
"strings"
"time"
"github.com/pkg/errors"
)
// Card represents the card resource.
// https://developers.trello.com/reference/#card-object
type Card struct {
client *Client
// Key metadata
ID string `json:"id"`
IDShort int `json:"idShort"`
Name string `json:"name"`
Pos float64 `json:"pos"`
Email string `json:"email"`
ShortLink string `json:"shortLink"`
ShortURL string `json:"shortUrl"`
URL string `json:"url"`
Desc string `json:"desc"`
Due *time.Time `json:"due"`
DueComplete bool `json:"dueComplete"`
Closed bool `json:"closed"`
Subscribed bool `json:"subscribed"`
DateLastActivity *time.Time `json:"dateLastActivity"`
// Board
Board *Board
IDBoard string `json:"idBoard"`
// List
List *List
IDList string `json:"idList"`
// Badges
Badges struct {
Votes int `json:"votes"`
ViewingMemberVoted bool `json:"viewingMemberVoted"`
Subscribed bool `json:"subscribed"`
Fogbugz string `json:"fogbugz,omitempty"`
CheckItems int `json:"checkItems"`
CheckItemsChecked int `json:"checkItemsChecked"`
Comments int `json:"comments"`
Attachments int `json:"attachments"`
Description bool `json:"description"`
Due *time.Time `json:"due,omitempty"`
} `json:"badges"`
// Actions
Actions ActionCollection `json:"actions,omitempty"`
// Checklists
IDCheckLists []string `json:"idCheckLists"`
Checklists []*Checklist `json:"checklists,omitempty"`
CheckItemStates []*CheckItemState `json:"checkItemStates,omitempty"`
// Members
IDMembers []string `json:"idMembers,omitempty"`
IDMembersVoted []string `json:"idMembersVoted,omitempty"`
Members []*Member `json:"members,omitempty"`
// Attachments
IDAttachmentCover string `json:"idAttachmentCover"`
ManualCoverAttachment bool `json:"manualCoverAttachment"`
Attachments []*Attachment `json:"attachments,omitempty"`
// Labels
IDLabels []string `json:"idLabels,omitempty"`
Labels []*Label `json:"labels,omitempty"`
// Custom Fields
CustomFieldItems []*CustomFieldItem `json:"customFieldItems,omitempty"`
customFieldMap *map[string]interface{}
}
// CreatedAt returns the receiver card's created-at attribute as time.Time.
func (c *Card) CreatedAt() time.Time {
t, _ := IDToTime(c.ID)
return t
}
// CustomFields returns the card's custom fields.
func (c *Card) CustomFields(boardCustomFields []*CustomField) map[string]interface{} {
cfm := c.customFieldMap
if cfm == nil {
cfm = &(map[string]interface{}{})
// bcfOptionNames[CustomField ID] = Custom Field Name
bcfOptionNames := map[string]string{}
// bcfOptionsMap[CustomField ID][ID of the option] = Value of the option
bcfOptionsMap := map[string]map[string]interface{}{}
for _, bcf := range boardCustomFields {
bcfOptionNames[bcf.ID] = bcf.Name
for _, cf := range bcf.Options {
// create 2nd level map when not available yet
map2, ok := bcfOptionsMap[cf.IDCustomField]
if !ok {
map2 = map[string]interface{}{}
bcfOptionsMap[bcf.ID] = map2
}
bcfOptionsMap[bcf.ID][cf.ID] = cf.Value.Text
}
}
for _, cf := range c.CustomFieldItems {
name := bcfOptionNames[cf.IDCustomField]
// create 2nd level map when not available yet
map2, ok := bcfOptionsMap[cf.IDCustomField]
if !ok {
continue
}
value, ok := map2[cf.IDValue]
if ok {
(*cfm)[name] = value
}
}
c.customFieldMap = cfm
}
return *cfm
}
// MoveToList moves a card to a list given by listID.
func (c *Card) MoveToList(listID string, args Arguments) error {
path := fmt.Sprintf("cards/%s", c.ID)
args["idList"] = listID
return c.client.Put(path, args, &c)
}
// SetPos sets a card's new position.
func (c *Card) SetPos(newPos float64) error {
path := fmt.Sprintf("cards/%s", c.ID)
return c.client.Put(path, Arguments{"pos": fmt.Sprintf("%f", newPos)}, c)
}
// RemoveMember receives the id of a member and removes the corresponding member from the card.
func (c *Card) RemoveMember(memberID string) error {
path := fmt.Sprintf("cards/%s/idMembers/%s", c.ID, memberID)
return c.client.Delete(path, Defaults(), nil)
}
// AddMemberID receives a member id and adds the corresponding member to the card.
// Returns a list of the card's members or an error.
func (c *Card) AddMemberID(memberID string) (member []*Member, err error) {
path := fmt.Sprintf("cards/%s/idMembers", c.ID)
err = c.client.Post(path, Arguments{"value": memberID}, &member)
return member, err
}
// RemoveIDLabel removes a label id from the card.
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)
}
// AddIDLabel receives a label id and adds the corresponding label or returns an error.
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
}
// MoveToTopOfList moves the card to the top of it's list.
func (c *Card) MoveToTopOfList() error {
path := fmt.Sprintf("cards/%s", c.ID)
return c.client.Put(path, Arguments{"pos": "top"}, c)
}
// MoveToBottomOfList moves the card to the bottom of its list.
func (c *Card) MoveToBottomOfList() error {
path := fmt.Sprintf("cards/%s", c.ID)
return c.client.Put(path, Arguments{"pos": "bottom"}, c)
}
// Update UPDATEs the card's attributes.
func (c *Card) Update(args Arguments) error {
path := fmt.Sprintf("cards/%s", c.ID)
return c.client.Put(path, args, c)
}
// CreateCard takes a Card and Arguments and POSTs the card.
func (c *Client) CreateCard(card *Card, extraArgs Arguments) error {
path := "cards"
args := Arguments{
"name": card.Name,
"desc": card.Desc,
"pos": strconv.FormatFloat(card.Pos, 'g', -1, 64),
"idList": card.IDList,
"idMembers": strings.Join(card.IDMembers, ","),
"idLabels": strings.Join(card.IDLabels, ","),
}
if card.Due != nil {
args["due"] = card.Due.Format(time.RFC3339)
}
// Allow overriding the creation position with 'top' or 'botttom'
if pos, ok := extraArgs["pos"]; ok {
args["pos"] = pos
}
err := c.Post(path, args, &card)
if err == nil {
card.client = c
}
return err
}
// AddCard takes a Card and Arguments and adds the card to the receiver list.
func (l *List) AddCard(card *Card, extraArgs Arguments) error {
path := fmt.Sprintf("lists/%s/cards", l.ID)
args := Arguments{
"name": card.Name,
"desc": card.Desc,
"idMembers": strings.Join(card.IDMembers, ","),
"idLabels": strings.Join(card.IDLabels, ","),
}
if card.Due != nil {
args["due"] = card.Due.Format(time.RFC3339)
}
// Allow overwriting the creation position with 'top' or 'bottom'
if pos, ok := extraArgs["pos"]; ok {
args["pos"] = pos
}
err := l.client.Post(path, args, &card)
if err == nil {
card.client = l.client
} else {
err = errors.Wrapf(err, "Error adding card to list %s", l.ID)
}
return err
}
// CopyToList takes a list id and Arguments and returns the matching Card.
// The following Arguments are supported.
//
// Arguments["keepFromSource"] = "all"
// Arguments["keepFromSource"] = "none"
// Arguments["keepFromSource"] = "attachments,checklists,comments"
func (c *Card) CopyToList(listID string, args Arguments) (*Card, error) {
path := "cards"
args["idList"] = listID
args["idCardSource"] = c.ID
newCard := Card{}
err := c.client.Post(path, args, &newCard)
if err == nil {
newCard.client = c.client
} else {
err = errors.Wrapf(err, "Error copying card '%s' to list '%s'.", c.ID, listID)
}
return &newCard, err
}
// AddComment takes a comment string and Arguments and adds the comment to the card.
func (c *Card) AddComment(comment string, args Arguments) (*Action, error) {
path := fmt.Sprintf("cards/%s/actions/comments", c.ID)
args["text"] = comment
action := Action{}
err := c.client.Post(path, args, &action)
if err != nil {
err = errors.Wrapf(err, "Error commenting on card %s", c.ID)
}
return &action, err
}
// AddURLAttachment takes an Attachment and adds it to the card.
func (c *Card) AddURLAttachment(attachment *Attachment) error {
path := fmt.Sprintf("cards/%s/attachments", c.ID)
args := Arguments{
"url": attachment.URL,
"name": attachment.Name,
}
err := c.client.Post(path, args, &attachment)
if err != nil {
err = errors.Wrapf(err, "Error adding attachment to card %s", c.ID)
}
return err
}
// GetParentCard retrieves the originating Card if the Card was created
// from a copy of another Card. Returns an error only when a low-level failure occurred.
// If this Card has no parent, a nil card and nil error are returned. In other words, the
// non-existence of a parent is not treated as an error.
func (c *Card) GetParentCard(args Arguments) (*Card, error) {
// Hopefully the card came pre-loaded with Actions including the card creation
action := c.Actions.FirstCardCreateAction()
if action == nil {
// No luck. Go get copyCard actions for this card.
c.client.log("Creation action wasn't supplied before GetParentCard() on '%s'. Getting copyCard actions.", c.ID)
actions, err := c.GetActions(Arguments{"filter": "copyCard"})
if err != nil {
err = errors.Wrapf(err, "GetParentCard() failed to GetActions() for card '%s'", c.ID)
return nil, err
}
action = actions.FirstCardCreateAction()
}
if action != nil && action.Data != nil && action.Data.CardSource != nil {
card, err := c.client.GetCard(action.Data.CardSource.ID, args)
return card, err
}
return nil, nil
}
// GetAncestorCards takes Arguments, GETs the card's ancestors and returns them as a slice.
func (c *Card) GetAncestorCards(args Arguments) (ancestors []*Card, err error) {
// Get the first parent
parent, err := c.GetParentCard(args)
if IsNotFound(err) || IsPermissionDenied(err) {
c.client.log("[trello] Can't get details about the parent of card '%s' due to lack of permissions or card deleted.", c.ID)
return ancestors, nil
}
for parent != nil {
ancestors = append(ancestors, parent)
parent, err = parent.GetParentCard(args)
if IsNotFound(err) || IsPermissionDenied(err) {
c.client.log("[trello] Can't get details about the parent of card '%s' due to lack of permissions or card deleted.", c.ID)
return ancestors, nil
} else if err != nil {
return ancestors, err
}
}
return ancestors, err
}
// GetOriginatingCard takes Arguments, GETs ancestors and returns most recent ancestor card of the Card.
func (c *Card) GetOriginatingCard(args Arguments) (*Card, error) {
ancestors, err := c.GetAncestorCards(args)
if err != nil {
return c, err
}
if len(ancestors) > 0 {
return ancestors[len(ancestors)-1], nil
}
return c, nil
}
// CreatorMember returns the member of the card who created it or and error.
// The creator is the member who is associated with the card's first action.
func (c *Card) CreatorMember() (*Member, error) {
var actions ActionCollection
var err error
if len(c.Actions) == 0 {
c.Actions, err = c.GetActions(Arguments{"filter": "all", "limit": "1000", "memberCreator_fields": "all"})
if err != nil {
err = errors.Wrapf(err, "GetActions() call failed.")
return nil, err
}
}
actions = c.Actions.FilterToCardCreationActions()
if len(actions) > 0 {
return actions[0].MemberCreator, nil
}
return nil, errors.Errorf("No card creation actions on Card %s with a .MemberCreator", c.ID)
}
// CreatorMemberID returns as string the id of the member who created the card or an error.
// The creator is the member who is associated with the card's first action.
func (c *Card) CreatorMemberID() (string, error) {
var actions ActionCollection
var err error
if len(c.Actions) == 0 {
c.client.log("[trello] CreatorMemberID() called on card '%s' without any Card.Actions. Fetching fresh.", c.ID)
c.Actions, err = c.GetActions(Defaults())
if err != nil {
err = errors.Wrapf(err, "GetActions() call failed.")
}
}
actions = c.Actions.FilterToCardCreationActions()
if len(actions) > 0 {
if actions[0].IDMemberCreator != "" {
return actions[0].IDMemberCreator, err
}
}
return "", errors.Wrapf(err, "No Actions on card '%s' could be used to find its creator.", c.ID)
}
// ContainsCopyOfCard accepts a card id and Arguments and returns true
// if the receiver Board contains a Card with the id.
func (b *Board) ContainsCopyOfCard(cardID string, args Arguments) (bool, error) {
args["filter"] = "copyCard"
actions, err := b.GetActions(args)
if err != nil {
err := errors.Wrapf(err, "GetCards() failed inside ContainsCopyOf() for board '%s' and card '%s'.", b.ID, cardID)
return false, err
}
for _, action := range actions {
if action.Data != nil && action.Data.CardSource != nil && action.Data.CardSource.ID == cardID {
return true, nil
}
}
return false, nil
}
// GetCard receives a card id and Arguments and returns the card if found
// with the credentials given for the receiver Client. Returns an error
// otherwise.
func (c *Client) GetCard(cardID string, args Arguments) (card *Card, err error) {
path := fmt.Sprintf("cards/%s", cardID)
err = c.Get(path, args, &card)
if card != nil {
card.client = c
}
return card, err
}
// GetCards takes Arguments and retrieves all Cards on a Board as slice or returns error.
func (b *Board) GetCards(args Arguments) (cards []*Card, err error) {
path := fmt.Sprintf("boards/%s/cards", b.ID)
err = b.client.Get(path, args, &cards)
// Naive implementation would return here. To make sure we get all
// cards, we begin
if len(cards) > 0 {
moreCards := true
for moreCards == true {
nextCardBatch := make([]*Card, 0)
args["before"] = earliestCardID(cards)
err = b.client.Get(path, args, &nextCardBatch)
if len(nextCardBatch) > 0 {
cards = append(cards, nextCardBatch...)
} else {
moreCards = false
}
}
}
for i := range cards {
cards[i].client = b.client
}
return
}
// GetCards retrieves all Cards in a List or an error if something goes wrong.
func (l *List) GetCards(args Arguments) (cards []*Card, err error) {
path := fmt.Sprintf("lists/%s/cards", l.ID)
err = l.client.Get(path, args, &cards)
for i := range cards {
cards[i].client = l.client
}
return
}
func earliestCardID(cards []*Card) string {
if len(cards) == 0 {
return ""
}
earliest := cards[0].ID
for _, card := range cards {
if card.ID < earliest {
earliest = card.ID
}
}
return earliest
}

97
vendor/github.com/adlio/trello/checklist.go generated vendored Normal file
View File

@@ -0,0 +1,97 @@
// Copyright © 2016 Aaron Longwell
//
// Use of this source code is governed by an MIT licese.
// Details in the LICENSE file.
package trello
// Checklist represents Trello card's checklists.
// A card can have one zero or more checklists.
// https://developers.trello.com/reference/#checklist-object
type Checklist struct {
ID string `json:"id"`
Name string `json:"name"`
IDBoard string `json:"idBoard,omitempty"`
IDCard string `json:"idCard,omitempty"`
Pos float64 `json:"pos,omitempty"`
CheckItems []CheckItem `json:"checkItems,omitempty"`
client *Client
}
// CheckItem is a nested resource representing an item in Checklist.
type CheckItem struct {
ID string `json:"id"`
Name string `json:"name"`
State string `json:"state"`
IDChecklist string `json:"idChecklist,omitempty"`
Pos float64 `json:"pos,omitempty"`
}
// CheckItemState represents a CheckItem when it appears in CheckItemStates on a Card.
type CheckItemState struct {
IDCheckItem string `json:"idCheckItem"`
State string `json:"state"`
}
// CreateChecklist creates a checklist.
// Attribute currently supported as extra argument: pos.
// Attributes currently known to be unsupported: idChecklistSource.
//
// API Docs: https://developers.trello.com/reference#cardsidchecklists-1
func (c *Client) CreateChecklist(card *Card, name string, extraArgs Arguments) (checklist *Checklist, err error) {
path := "cards/" + card.ID + "/checklists"
args := Arguments{
"name": name,
"pos": "bottom",
}
if pos, ok := extraArgs["pos"]; ok{
args["pos"] = pos
}
checklist = &Checklist{}
err = c.Post(path, args, &checklist)
if err == nil {
checklist.client = c
checklist.IDCard = card.ID
card.Checklists = append(card.Checklists, checklist)
}
return
}
// CreateCheckItem creates a checkitem inside the checklist.
// Attribute currently supported as extra argument: pos.
// Attributes currently known to be unsupported: checked.
//
// API Docs: https://developers.trello.com/reference#checklistsidcheckitems
func (cl *Checklist) CreateCheckItem(name string, extraArgs Arguments) (item *CheckItem, err error) {
return cl.client.CreateCheckItem(cl, name, extraArgs)
}
// CreateCheckItem creates a checkitem inside the given checklist.
// Attribute currently supported as extra argument: pos.
// Attributes currently known to be unsupported: checked.
//
// API Docs: https://developers.trello.com/reference#checklistsidcheckitems
func (c *Client) CreateCheckItem(checklist *Checklist, name string, extraArgs Arguments) (item *CheckItem, err error) {
path := "checklists/" + checklist.ID + "/checkItems"
args := Arguments {
"name": name,
"pos": "bottom",
"checked": "false",
}
if pos, ok := extraArgs["pos"]; ok{
args["pos"] = pos
}
if checked, ok := extraArgs["checked"]; ok {
args["checked"] = checked
}
item = &CheckItem{}
err = c.Post(path, args, item)
if err == nil {
checklist.CheckItems = append(checklist.CheckItems, *item)
}
return
}

263
vendor/github.com/adlio/trello/client.go generated vendored Normal file
View File

@@ -0,0 +1,263 @@
// Copyright © 2016 Aaron Longwell
//
// Use of this source code is governed by an MIT licese.
// Details in the LICENSE file.
package trello
import (
"bytes"
"context"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"time"
"github.com/pkg/errors"
)
// DefaultBaseURL is the default API base url used by Client to send requests to Trello.
const DefaultBaseURL = "https://api.trello.com/1"
// Client is the central object for making API calls. It wraps a http client,
// context, logger and identity configuration (Key and Token) of the Trello member.
type Client struct {
Client *http.Client
Logger logger
BaseURL string
Key string
Token string
throttle <-chan time.Time
testMode bool
ctx context.Context
}
type logger interface {
Debugf(string, ...interface{})
}
// NewClient is a constructor for the Client. It takes the key and token credentials
// of a Trello member to authenticate and authorise requests with.
func NewClient(key, token string) *Client {
return &Client{
Client: http.DefaultClient,
BaseURL: DefaultBaseURL,
Key: key,
Token: token,
throttle: time.Tick(time.Second / 8), // Actually 10/second, but we're extra cautious
testMode: false,
ctx: context.Background(),
}
}
// WithContext takes a context.Context, sets it as context on the client and returns
// a Client pointer.
func (c *Client) WithContext(ctx context.Context) *Client {
newC := *c
newC.ctx = ctx
return &newC
}
// Throttle starts receiving throttles from throttle channel each ticker period.
func (c *Client) Throttle() {
if !c.testMode {
<-c.throttle
}
}
// Get takes a path, Arguments, and a target interface (e.g. Board or Card).
// It runs a GET request on the Trello API endpoint and the path and uses the
// Arguments as URL parameters. Then it returns either the target interface
// updated from the response or an error.
func (c *Client) Get(path string, args Arguments, target interface{}) error {
// Trello prohibits more than 10 seconds/second per token
c.Throttle()
params := args.ToURLValues()
c.log("[trello] GET %s?%s", path, params.Encode())
if c.Key != "" {
params.Set("key", c.Key)
}
if c.Token != "" {
params.Set("token", c.Token)
}
url := fmt.Sprintf("%s/%s", c.BaseURL, path)
urlWithParams := fmt.Sprintf("%s?%s", url, params.Encode())
req, err := http.NewRequest("GET", urlWithParams, nil)
if err != nil {
return errors.Wrapf(err, "Invalid GET request %s", url)
}
req = req.WithContext(c.ctx)
resp, err := c.Client.Do(req)
if err != nil {
return errors.Wrapf(err, "HTTP request failure on %s", url)
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return makeHTTPClientError(url, resp)
}
decoder := json.NewDecoder(resp.Body)
err = decoder.Decode(target)
if err != nil {
return errors.Wrapf(err, "JSON decode failed on %s", url)
}
return nil
}
// Put takes a path, Arguments, and a target interface (e.g. Board or Card).
// It runs a PUT request on the Trello API endpoint with the path and uses
// the Arguments as URL parameters. Then it returns either the target interface
// updated from the response or an error.
func (c *Client) Put(path string, args Arguments, target interface{}) error {
// Trello prohibits more than 10 seconds/second per token
c.Throttle()
params := args.ToURLValues()
c.log("[trello] PUT %s?%s", path, params.Encode())
if c.Key != "" {
params.Set("key", c.Key)
}
if c.Token != "" {
params.Set("token", c.Token)
}
url := fmt.Sprintf("%s/%s", c.BaseURL, path)
urlWithParams := fmt.Sprintf("%s?%s", url, params.Encode())
req, err := http.NewRequest("PUT", urlWithParams, nil)
if err != nil {
return errors.Wrapf(err, "Invalid PUT request %s", url)
}
resp, err := c.Client.Do(req)
if err != nil {
return errors.Wrapf(err, "HTTP request failure on %s", url)
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return makeHTTPClientError(url, resp)
}
decoder := json.NewDecoder(resp.Body)
err = decoder.Decode(target)
if err != nil {
return errors.Wrapf(err, "JSON decode failed on %s", url)
}
return nil
}
// Post takes a path, Arguments, and a target interface (e.g. Board or Card).
// It runs a POST request on the Trello API endpoint with the path and uses
// the Arguments as URL parameters. Then it returns either the target interface
// updated from the response or an error.
func (c *Client) Post(path string, args Arguments, target interface{}) error {
// Trello prohibits more than 10 seconds/second per token
c.Throttle()
params := args.ToURLValues()
c.log("[trello] POST %s?%s", path, params.Encode())
if c.Key != "" {
params.Set("key", c.Key)
}
if c.Token != "" {
params.Set("token", c.Token)
}
url := fmt.Sprintf("%s/%s", c.BaseURL, path)
urlWithParams := fmt.Sprintf("%s?%s", url, params.Encode())
req, err := http.NewRequest("POST", urlWithParams, nil)
if err != nil {
return errors.Wrapf(err, "Invalid POST request %s", url)
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
resp, err := c.Client.Do(req)
if err != nil {
return errors.Wrapf(err, "HTTP request failure on %s", url)
}
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
return errors.Wrapf(err, "HTTP Read error on response for %s", url)
}
decoder := json.NewDecoder(bytes.NewBuffer(b))
err = decoder.Decode(target)
if err != nil {
return errors.Wrapf(err, "JSON decode failed on %s:\n%s", url, string(b))
}
return nil
}
// Delete takes a path, Arguments, and a target interface (e.g. Board or Card).
// It runs a DELETE request on the Trello API endpoint with the path and uses
// the Arguments as URL parameters. Then it returns either the target interface
// updated from the response or an error.
func (c *Client) Delete(path string, args Arguments, target interface{}) error {
c.Throttle()
params := args.ToURLValues()
c.log("[trello] DELETE %s?%s", path, params.Encode())
if c.Key != "" {
params.Set("key", c.Key)
}
if c.Token != "" {
params.Set("token", c.Token)
}
url := fmt.Sprintf("%s/%s", c.BaseURL, path)
urlWithParams := fmt.Sprintf("%s?%s", url, params.Encode())
req, err := http.NewRequest("DELETE", urlWithParams, nil)
if err != nil {
return errors.Wrapf(err, "Invalid DELETE request %s", url)
}
resp, err := c.Client.Do(req)
if err != nil {
return errors.Wrapf(err, "HTTP request failure on %s", url)
}
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
return errors.Wrapf(err, "HTTP Read error on response for %s", url)
}
decoder := json.NewDecoder(bytes.NewBuffer(b))
err = decoder.Decode(target)
if err != nil {
return errors.Wrapf(err, "JSON decode failed on %s:\n%s", url, string(b))
}
return nil
}
func (c *Client) log(format string, args ...interface{}) {
if c.Logger != nil {
c.Logger.Debugf(format, args...)
}
}

54
vendor/github.com/adlio/trello/custom-fields.go generated vendored Normal file
View File

@@ -0,0 +1,54 @@
package trello
import "fmt"
// CustomFieldItem represents the custom field items of Trello a trello card.
type CustomFieldItem struct {
ID string `json:"id"`
IDValue string `json:"idValue"`
IDCustomField string `json:"idCustomField"`
IDModel string `json:"idModel"`
IDModelType string `json:"modelType,omitempty"`
}
// 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
type CustomField struct {
ID string `json:"id"`
IDModel string `json:"idModel"`
IDModelType string `json:"modelType,omitempty"`
FieldGroup string `json:"fieldGroup"`
Name string `json:"name"`
Pos int `json:"pos"`
Display struct {
CardFront bool `json:"cardfront"`
} `json:"display"`
Type string `json:"type"`
Options []*CustomFieldOption `json:"options"`
}
// CustomFieldOption are nested resources of CustomFields
type CustomFieldOption struct {
ID string `json:"id"`
IDCustomField string `json:"idCustomField"`
Value struct {
Text string `json:"text"`
} `json:"value"`
Color string `json:"color,omitempty"`
Pos int `json:"pos"`
}
// GetCustomField takes a field id string and Arguments and returns the matching custom Field.
func (c *Client) GetCustomField(fieldID string, args Arguments) (customField *CustomField, err error) {
path := fmt.Sprintf("customFields/%s", fieldID)
err = c.Get(path, args, &customField)
return
}
// GetCustomFields returns a slice of all receiver board's custom fields.
func (b *Board) GetCustomFields(args Arguments) (customFields []*CustomField, err error) {
path := fmt.Sprintf("boards/%s/customFields", b.ID)
err = b.client.Get(path, args, &customFields)
return
}

59
vendor/github.com/adlio/trello/errors.go generated vendored Normal file
View File

@@ -0,0 +1,59 @@
package trello
import (
"fmt"
"io/ioutil"
"net/http"
)
type notFoundError interface {
IsNotFound() bool
}
type rateLimitError interface {
IsRateLimit() bool
}
type permissionDeniedError interface {
IsPermissionDenied() bool
}
type httpClientError struct {
msg string
code int
}
func makeHTTPClientError(url string, resp *http.Response) error {
body, _ := ioutil.ReadAll(resp.Body)
msg := fmt.Sprintf("HTTP request failure on %s:\n%d: %s", url, resp.StatusCode, string(body))
return &httpClientError{
msg: msg,
code: resp.StatusCode,
}
}
func (e *httpClientError) Error() string { return e.msg }
func (e *httpClientError) IsRateLimit() bool { return e.code == 429 }
func (e *httpClientError) IsNotFound() bool { return e.code == 404 }
func (e *httpClientError) IsPermissionDenied() bool { return e.code == 401 }
// IsRateLimit takes an error and returns true exactly if the error is a rate-limit error.
func IsRateLimit(err error) bool {
re, ok := err.(rateLimitError)
return ok && re.IsRateLimit()
}
// IsNotFound takes an error and returns true exactly if the error is a not-found error.
func IsNotFound(err error) bool {
nf, ok := err.(notFoundError)
return ok && nf.IsNotFound()
}
// IsPermissionDenied takes an error and returns true exactly if the error is a
// permission-denied error.
func IsPermissionDenied(err error) bool {
pd, ok := err.(permissionDeniedError)
return ok && pd.IsPermissionDenied()
}

5
vendor/github.com/adlio/trello/go.mod generated vendored Normal file
View File

@@ -0,0 +1,5 @@
module github.com/adlio/trello
go 1.12
require github.com/pkg/errors v0.8.1

2
vendor/github.com/adlio/trello/go.sum generated vendored Normal file
View File

@@ -0,0 +1,2 @@
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=

34
vendor/github.com/adlio/trello/label.go generated vendored Normal file
View File

@@ -0,0 +1,34 @@
// Copyright © 2016 Aaron Longwell
//
// Use of this source code is governed by an MIT licese.
// Details in the LICENSE file.
package trello
import "fmt"
// Label represents a Trello label.
// Labels are defined per board, and can be applied to the cards on that board.
// https://developers.trello.com/reference/#label-object
type Label struct {
ID string `json:"id"`
IDBoard string `json:"idBoard"`
Name string `json:"name"`
Color string `json:"color"`
Uses int `json:"uses"`
}
// GetLabel takes a label id and Arguments and returns the matching label (per Trello member)
// or an error.
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
}
// GetLabels takes Arguments and returns a slice containing all labels of the receiver board or an error.
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
}

16
vendor/github.com/adlio/trello/list-duration-sort.go generated vendored Normal file
View File

@@ -0,0 +1,16 @@
package trello
// ByFirstEntered is a slice of ListDurations
type ByFirstEntered []*ListDuration
// ByFirstEntered returns the length of the receiver.
func (durs ByFirstEntered) Len() int { return len(durs) }
// Less takes two indexes i and j and returns true exactly if the ListDuration
// at i was entered before j.
func (durs ByFirstEntered) Less(i, j int) bool {
return durs[i].FirstEntered.Before(durs[j].FirstEntered)
}
// Swap takes two indexes i and j and swaps the ListDurations at the indexes.
func (durs ByFirstEntered) Swap(i, j int) { durs[i], durs[j] = durs[j], durs[i] }

87
vendor/github.com/adlio/trello/list-duration.go generated vendored Normal file
View File

@@ -0,0 +1,87 @@
package trello
import (
"sort"
"time"
"github.com/pkg/errors"
)
// ListDuration represents the time a Card has been or was in list.
type ListDuration struct {
ListID string
ListName string
Duration time.Duration
FirstEntered time.Time
TimesInList int
}
// AddDuration takes a duration and adds it to the ListDuration's Duration.
// Also increments TimesInList.
func (l *ListDuration) AddDuration(d time.Duration) {
l.Duration = l.Duration + d
l.TimesInList++
}
// GetListDurations analyses a Card's actions to figure out how long it was in each List.
// It returns a slice of the ListDurations, one Duration per list, or an error.
func (c *Card) GetListDurations() (durations []*ListDuration, err error) {
var actions ActionCollection
if len(c.Actions) == 0 {
// Get all actions which affected the Card's List
c.client.log("[trello] GetListDurations() called on card '%s' without any Card.Actions. Fetching fresh.", c.ID)
actions, err = c.GetListChangeActions()
if err != nil {
err = errors.Wrap(err, "GetListChangeActions() call failed.")
return
}
} else {
actions = c.Actions.FilterToListChangeActions()
}
return actions.GetListDurations()
}
// GetListDurations returns a slice of ListDurations based on the receiver Actions.
func (actions ActionCollection) GetListDurations() (durations []*ListDuration, err error) {
sort.Sort(actions)
var prevTime time.Time
var prevList *List
durs := make(map[string]*ListDuration)
for _, action := range actions {
if action.DidChangeListForCard() {
if prevList != nil {
duration := action.Date.Sub(prevTime)
_, durExists := durs[prevList.ID]
if !durExists {
durs[prevList.ID] = &ListDuration{ListID: prevList.ID, ListName: prevList.Name, Duration: duration, TimesInList: 1, FirstEntered: prevTime}
} else {
durs[prevList.ID].AddDuration(duration)
}
}
prevList = ListAfterAction(action)
prevTime = action.Date
}
}
if prevList != nil {
duration := time.Now().Sub(prevTime)
_, durExists := durs[prevList.ID]
if !durExists {
durs[prevList.ID] = &ListDuration{ListID: prevList.ID, ListName: prevList.Name, Duration: duration, TimesInList: 1, FirstEntered: prevTime}
} else {
durs[prevList.ID].AddDuration(duration)
}
}
durations = make([]*ListDuration, 0, len(durs))
for _, ld := range durs {
durations = append(durations, ld)
}
sort.Sort(ByFirstEntered(durations))
return durations, nil
}

91
vendor/github.com/adlio/trello/list.go generated vendored Normal file
View File

@@ -0,0 +1,91 @@
// Copyright © 2016 Aaron Longwell
//
// Use of this source code is governed by an MIT licese.
// Details in the LICENSE file.
package trello
import (
"fmt"
"time"
)
// List represents Trello lists.
// https://developers.trello.com/reference/#list-object
type List struct {
client *Client
ID string `json:"id"`
Name string `json:"name"`
IDBoard string `json:"idBoard,omitempty"`
Closed bool `json:"closed"`
Pos float32 `json:"pos,omitempty"`
Board *Board `json:"board,omitempty"`
Cards []*Card `json:"cards,omitempty"`
}
// CreatedAt returns the time.Time from the list's id.
func (l *List) CreatedAt() time.Time {
t, _ := IDToTime(l.ID)
return t
}
// GetList takes a list's id and Arguments and returns the matching list.
func (c *Client) GetList(listID string, args Arguments) (list *List, err error) {
path := fmt.Sprintf("lists/%s", listID)
err = c.Get(path, args, &list)
if list != nil {
list.client = c
for i := range list.Cards {
list.Cards[i].client = c
}
}
return
}
// GetLists takes Arguments and returns the lists of the receiver Board.
func (b *Board) GetLists(args Arguments) (lists []*List, err error) {
path := fmt.Sprintf("boards/%s/lists", b.ID)
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
}
// CreateList creates a list.
// Attribute currently supported as extra argument: pos.
// Attributes currently known to be unsupported: idListSource.
//
// API Docs: https://developers.trello.com/reference/#lists-1
func (c *Client) CreateList(onBoard *Board, name string, extraArgs Arguments) (list *List, err error) {
path := "lists"
args := Arguments{
"name": name,
"pos": "top",
"idBoard": onBoard.ID,
}
if pos, ok := extraArgs["pos"]; ok{
args["pos"] = pos
}
list = &List{}
err = c.Post(path, args, &list)
if err == nil {
list.client = c
}
return
}
// CreateList creates a list.
// Attribute currently supported as extra argument: pos.
// Attributes currently known to be unsupported: idListSource.
//
// API Docs: https://developers.trello.com/reference/#lists-1
func (b *Board) CreateList(name string, extraArgs Arguments) (list *List, err error) {
return b.client.CreateList(b, name, extraArgs)
}

122
vendor/github.com/adlio/trello/member-duration.go generated vendored Normal file
View File

@@ -0,0 +1,122 @@
package trello
import (
"sort"
"time"
"github.com/pkg/errors"
)
// MemberDuration is used to track the periods of time which a user (member) is attached to a card.
type MemberDuration struct {
MemberID string
MemberName string
FirstAdded time.Time
Duration time.Duration
active bool
lastAdded time.Time
}
// ByLongestDuration is a slice of *MemberDuration
type ByLongestDuration []*MemberDuration
// Len returns the length of the ByLongestDuration slice.
func (d ByLongestDuration) Len() int { return len(d) }
// Less takes two indexes i and j and returns true exactly if the Duration
// at i is larger than the Duration at j.
func (d ByLongestDuration) Less(i, j int) bool { return d[i].Duration > d[j].Duration }
func (d ByLongestDuration) Swap(i, j int) { d[i], d[j] = d[j], d[i] }
func (d *MemberDuration) addAsOf(t time.Time) {
d.active = true
if d.FirstAdded.IsZero() {
d.FirstAdded = t
}
d.startTimerAsOf(t)
}
func (d *MemberDuration) startTimerAsOf(t time.Time) {
if d.active {
d.lastAdded = t
}
}
func (d *MemberDuration) removeAsOf(t time.Time) {
d.stopTimerAsOf(t)
d.active = false
d.lastAdded = time.Time{}
}
func (d *MemberDuration) stopTimerAsOf(t time.Time) {
if d.active {
d.Duration = d.Duration + t.Sub(d.lastAdded)
}
}
// GetMemberDurations returns a slice containing all durations of a card.
func (c *Card) GetMemberDurations() (durations []*MemberDuration, err error) {
var actions ActionCollection
if len(c.Actions) == 0 {
c.client.log("[trello] GetMemberDurations() called on card '%s' without any Card.Actions. Fetching fresh.", c.ID)
actions, err = c.GetMembershipChangeActions()
if err != nil {
err = errors.Wrap(err, "GetMembershipChangeActions() call failed.")
return
}
} else {
actions = c.Actions.FilterToCardMembershipChangeActions()
}
return actions.GetMemberDurations()
}
// GetMemberDurations is similar to GetListDurations. It returns a slice of MemberDuration objects,
// which describes the length of time each member was attached to this card. Durations are
// calculated such that being added to a card starts a timer for that member, and being removed
// starts it again (so that if a person is added and removed multiple times, the duration
// captures only the times which they were attached). Archiving the card also stops the timer.
func (actions ActionCollection) GetMemberDurations() (durations []*MemberDuration, err error) {
sort.Sort(actions)
durs := make(map[string]*MemberDuration)
for _, action := range actions {
if action.DidChangeCardMembership() {
_, durExists := durs[action.Member.ID]
if !durExists {
switch action.Type {
case "addMemberToCard":
durs[action.Member.ID] = &MemberDuration{MemberID: action.Member.ID, MemberName: action.Member.FullName}
durs[action.Member.ID].addAsOf(action.Date)
case "removeMemberFromCard":
// Surprisingly, this is possible. If a card was copied, and members were preserved, those
// members exist on the card without a corresponding addMemberToCard action.
t, _ := IDToTime(action.Data.Card.ID)
durs[action.Member.ID] = &MemberDuration{MemberID: action.Member.ID, MemberName: action.Member.FullName, lastAdded: t}
durs[action.Member.ID].removeAsOf(action.Date)
}
} else {
switch action.Type {
case "addMemberToCard":
durs[action.Member.ID].addAsOf(action.Date)
case "removeMemberFromCard":
durs[action.Member.ID].removeAsOf(action.Date)
}
}
} else if action.DidArchiveCard() {
for id := range durs {
durs[id].stopTimerAsOf(action.Date)
}
} else if action.DidUnarchiveCard() {
for id := range durs {
durs[id].startTimerAsOf(action.Date)
}
}
}
durations = make([]*MemberDuration, 0, len(durs))
for _, md := range durs {
durations = append(durations, md)
}
// sort.Sort(ByLongestDuration(durations))
return durations, nil
}

62
vendor/github.com/adlio/trello/member.go generated vendored Normal file
View File

@@ -0,0 +1,62 @@
// Copyright © 2016 Aaron Longwell
//
// Use of this source code is governed by an MIT licese.
// Details in the LICENSE file.
package trello
import (
"fmt"
)
// Member represents a Trello member.
// https://developers.trello.com/reference/#member-object
type Member struct {
client *Client
ID string `json:"id"`
Username string `json:"username"`
FullName string `json:"fullName"`
Initials string `json:"initials"`
AvatarHash string `json:"avatarHash"`
Email string `json:"email"`
}
// GetMember takes a member id and Arguments and returns a Member or an error.
func (c *Client) GetMember(memberID string, args Arguments) (member *Member, err error) {
path := fmt.Sprintf("members/%s", memberID)
err = c.Get(path, args, &member)
if err == nil {
member.client = c
}
return
}
// GetMembers takes Arguments and returns a slice of all members of the organization or an error.
func (o *Organization) GetMembers(args Arguments) (members []*Member, err error) {
path := fmt.Sprintf("organizations/%s/members", o.ID)
err = o.client.Get(path, args, &members)
for i := range members {
members[i].client = o.client
}
return
}
// GetMembers takes Arguments and returns a slice of all members of the Board or an error.
func (b *Board) GetMembers(args Arguments) (members []*Member, err error) {
path := fmt.Sprintf("boards/%s/members", b.ID)
err = b.client.Get(path, args, &members)
for i := range members {
members[i].client = b.client
}
return
}
// GetMembers takes Arguments and returns a slice of all members of the Card or an error.
func (c *Card) GetMembers(args Arguments) (members []*Member, err error) {
path := fmt.Sprintf("cards/%s/members", c.ID)
err = c.client.Get(path, args, &members)
for i := range members {
members[i].client = c.client
}
return
}

53
vendor/github.com/adlio/trello/notification.go generated vendored Normal file
View File

@@ -0,0 +1,53 @@
package trello
import (
"time"
)
// Notification represents a Trello Notification.
// https://developers.trello.com/reference/#notifications
type Notification struct {
client *Client
ID string `json:"id"`
IDAction string `json:"idAction"`
Unread bool `json:"unread"`
Type string `json:"type"`
IDMemberCreator string `json:"idMemberCreator"`
Date time.Time `json:"date"`
DateRead time.Time `json:"dataRead"`
Data NotificationData `json:"data,omitempty"`
MemberCreator *Member `json:"memberCreator,omitempty"`
}
// NotificationData represents the 'notificaiton.data'
type NotificationData struct {
Text string `json:"text"`
Card *NotificationDataCard `json:"card,omitempty"`
Board *NotificationDataBoard `json:"board,omitempty"`
}
// NotificationDataBoard represents the 'notification.data.board'
type NotificationDataBoard struct {
ID string `json:"id"`
ShortLink string `json:"shortLink"`
Name string `json:"name"`
}
// NotificationDataCard represents the 'notification.data.card'
type NotificationDataCard struct {
ID string `json:"id"`
IDShort int `json:"idShort"`
Name string `json:"name"`
ShortLink string `json:"shortLink"`
}
// GetMyNotifications returns the notifications of the authenticated user
func (c *Client) GetMyNotifications(args Arguments) (notifications []*Notification, err error) {
path := "members/me/notifications"
err = c.Get(path, args, &notifications)
for i := range notifications {
notifications[i].client = c
}
return
}

35
vendor/github.com/adlio/trello/organization.go generated vendored Normal file
View File

@@ -0,0 +1,35 @@
// Copyright © 2016 Aaron Longwell
//
// Use of this source code is governed by an MIT licese.
// Details in the LICENSE file.
package trello
import (
"fmt"
)
// Organization represents a Trello organization or team, i.e. a collection of members and boards.
// https://developers.trello.com/reference/#organizations
type Organization struct {
client *Client
ID string `json:"id"`
Name string `json:"name"`
DisplayName string `json:"displayName"`
Desc string `json:"desc"`
URL string `json:"url"`
Website string `json:"website"`
Products []string `json:"products"`
PowerUps []string `json:"powerUps"`
}
// GetOrganization takes an organization id and Arguments and either
// GETs returns an Organization, or an error.
func (c *Client) GetOrganization(orgID string, args Arguments) (organization *Organization, err error) {
path := fmt.Sprintf("organizations/%s", orgID)
err = c.Get(path, args, &organization)
if organization != nil {
organization.client = c
}
return
}

65
vendor/github.com/adlio/trello/search.go generated vendored Normal file
View File

@@ -0,0 +1,65 @@
// Copyright © 2016 Aaron Longwell
//
// Use of this source code is governed by an MIT licese.
// Details in the LICENSE file.
package trello
// SearchResult represents a search result as collections of various
// types returned by a search, e.g. Cards or Boards.
type SearchResult struct {
Options SearchOptions `json:"options"`
Actions []*Action `json:"actions,omitempty"`
Cards []*Card `json:"cards,omitempty"`
Boards []*Board `json:"boards,omitempty"`
Members []*Member `json:"members,omitempty"`
}
// SearchOptions contains options for search requests.
type SearchOptions struct {
Terms []SearchTerm `json:"terms"`
Modifiers []SearchModifier `json:"modifiers,omitempty"`
ModelTypes []string `json:"modelTypes,omitempty"`
Partial bool `json:"partial"`
}
// SearchModifier is wrapper for a search string.
type SearchModifier struct {
Text string `json:"text"`
}
// SearchTerm is a string that may be negated in a search query.
type SearchTerm struct {
Text string `json:"text"`
Negated bool `json:"negated,omitempty"`
}
// SearchCards takes a query string and Arguments and returns a slice of Cards or an error.
func (c *Client) SearchCards(query string, args Arguments) (cards []*Card, err error) {
args["query"] = query
args["modelTypes"] = "cards"
res := SearchResult{}
err = c.Get("search", args, &res)
cards = res.Cards
return
}
// SearchBoards takes a query string and Arguments and returns a slice of Boards or an error.
func (c *Client) SearchBoards(query string, args Arguments) (boards []*Board, err error) {
args["query"] = query
args["modelTypes"] = "boards"
res := SearchResult{}
err = c.Get("search", args, &res)
boards = res.Boards
for _, board := range boards {
board.client = c
}
return
}
// SearchMembers takes a query string and Arguments and returns a slice of Members or an error.
func (c *Client) SearchMembers(query string, args Arguments) (members []*Member, err error) {
args["query"] = query
err = c.Get("search/members", args, &members)
return
}

41
vendor/github.com/adlio/trello/token.go generated vendored Normal file
View File

@@ -0,0 +1,41 @@
// Copyright © 2016 Aaron Longwell
//
// Use of this source code is governed by an MIT licese.
// Details in the LICENSE file.
package trello
import (
"fmt"
"time"
)
// Token represents Trello tokens. Tokens can be used for setting up Webhooks among other things.
// https://developers.trello.com/reference/#tokens
type Token struct {
client *Client
ID string `json:"id"`
DateCreated time.Time `json:"dateCreated"`
DateExpires *time.Time `json:"dateExpires"`
IDMember string `json:"idMember"`
Identifier string `json:"identifier"`
Permissions []Permission `json:"permissions"`
}
// Permission represent a Token's permissions.
type Permission struct {
IDModel string `json:"idModel"`
ModelType string `json:"modelType"`
Read bool `json:"read"`
Write bool `json:"write"`
}
// GetToken takes a token id and Arguments and GETs and returns the Token or an error.
func (c *Client) GetToken(tokenID string, args Arguments) (token *Token, err error) {
path := fmt.Sprintf("tokens/%s", tokenID)
err = c.Get(path, args, &token)
if token != nil {
token.client = c
}
return
}

BIN
vendor/github.com/adlio/trello/trello-logo.png generated vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

29
vendor/github.com/adlio/trello/trello.go generated vendored Normal file
View File

@@ -0,0 +1,29 @@
// Copyright © 2016 Aaron Longwell
//
// Use of this source code is governed by an MIT licese.
// Details in the LICENSE file.
package trello
import (
"strconv"
"time"
"github.com/pkg/errors"
)
// IDToTime is a convenience function. It takes a Trello ID string and
// extracts the encoded create time as time.Time or an error.
func IDToTime(id string) (t time.Time, err error) {
if id == "" {
return time.Time{}, nil
}
// The first 8 characters in the object ID are a Unix timestamp
ts, err := strconv.ParseUint(id[:8], 16, 64)
if err != nil {
err = errors.Wrapf(err, "ID '%s' failed to convert to timestamp.", id)
} else {
t = time.Unix(int64(ts), 0)
}
return
}

129
vendor/github.com/adlio/trello/webhook.go generated vendored Normal file
View File

@@ -0,0 +1,129 @@
// Copyright © 2016 Aaron Longwell
//
// Use of this source code is governed by an MIT licese.
// Details in the LICENSE file.
package trello
import (
"encoding/json"
"fmt"
"net/http"
"github.com/pkg/errors"
)
// Webhook is the Go representation of a webhook registered in Trello's systems.
// Used when creating, modifying or deleting webhooks.
// https://developers.trello.com/reference/#webhook-object
//
type Webhook struct {
client *Client
ID string `json:"id,omitempty"`
IDModel string `json:"idModel"`
Description string `json:"description"`
CallbackURL string `json:"callbackURL"`
Active bool `json:"active"`
}
// BoardWebhookRequest is the object sent by Trello to a Webhook for Board-triggered
// webhooks.
//
type BoardWebhookRequest struct {
Model *Board
Action *Action
}
// ListWebhookRequest is the object sent by Trello to a Webhook for List-triggered
// webhooks.
//
type ListWebhookRequest struct {
Model *List
Action *Action
}
// CardWebhookRequest is the object sent by Trello to a Webhook for Card-triggered
// webhooks.
//
type CardWebhookRequest struct {
Model *Card
Action *Action
}
// CreateWebhook takes a Webhook, POSTs it and returns an error object.
func (c *Client) CreateWebhook(webhook *Webhook) error {
path := "webhooks"
args := Arguments{"idModel": webhook.IDModel, "description": webhook.Description, "callbackURL": webhook.CallbackURL}
err := c.Post(path, args, webhook)
if err == nil {
webhook.client = c
}
return err
}
// DeleteWebhook takes a webhook and deletes it
func (w *Webhook) Delete(args Arguments) error {
path := fmt.Sprintf("webhooks/%s", w.ID)
return w.client.Delete(path, Arguments{}, w)
}
// GetWebhook takes a webhook id and Arguments, GETs the matching Webhook and returns it or an error.
func (c *Client) GetWebhook(webhookID string, args Arguments) (webhook *Webhook, err error) {
path := fmt.Sprintf("webhooks/%s", webhookID)
err = c.Get(path, args, &webhook)
if webhook != nil {
webhook.client = c
}
return
}
// GetWebhooks takes Arguments and returns a list of all Webhooks for the receiver Token or an error.
func (t *Token) GetWebhooks(args Arguments) (webhooks []*Webhook, err error) {
path := fmt.Sprintf("tokens/%s/webhooks", t.client.Token)
err = t.client.Get(path, args, &webhooks)
if err == nil {
for _, webhook := range webhooks {
webhook.client = t.client
}
}
return
}
// GetBoardWebhookRequest takes a http.Request and returns the decoded body as BoardWebhookRequest or an error.
func GetBoardWebhookRequest(r *http.Request) (whr *BoardWebhookRequest, err error) {
if r.Method == "HEAD" {
return &BoardWebhookRequest{}, nil
}
decoder := json.NewDecoder(r.Body)
err = decoder.Decode(&whr)
if err != nil {
err = errors.Wrapf(err, "GetBoardWebhookRequest() failed to decode '%s'.", r.URL)
}
return
}
// GetListWebhookRequest takes a http.Request and returns the decoded Body as ListWebhookRequest or an error.
func GetListWebhookRequest(r *http.Request) (whr *ListWebhookRequest, err error) {
if r.Method == "HEAD" {
return &ListWebhookRequest{}, nil
}
decoder := json.NewDecoder(r.Body)
err = decoder.Decode(&whr)
if err != nil {
err = errors.Wrapf(err, "GetListWebhookRequest() failed to decode '%s'.", r.URL)
}
return
}
// GetCardWebhookRequest takes a http.Request and returns the decoded Body as CardWebhookRequest or an error.
func GetCardWebhookRequest(r *http.Request) (whr *CardWebhookRequest, err error) {
if r.Method == "HEAD" {
return &CardWebhookRequest{}, nil
}
decoder := json.NewDecoder(r.Body)
err = decoder.Decode(&whr)
if err != nil {
err = errors.Wrapf(err, "GetCardWebhookRequest() failed to decode '%s'.", r.URL)
}
return
}