musala/cmd/trello2mail/trello.go

90 lines
1.6 KiB
Go
Raw Normal View History

2018-08-21 08:50:30 +00:00
package main
2018-08-21 08:57:59 +00:00
import (
2018-08-21 23:50:50 +00:00
// "errors"
// "fmt"
"github.com/adlio/trello"
// "github.com/davecgh/go-spew/spew"
// "log"
2018-08-21 08:57:59 +00:00
"os/exec"
2018-08-21 23:50:50 +00:00
// "strings"
)
const (
// FIXME: declare app to trello and get a real token for this app
APP_KEY string = "80dbcf6f88f62cc5639774e13342c20b"
2018-08-21 08:57:59 +00:00
)
type TrelloCtx struct {
2018-08-21 23:50:50 +00:00
Token string
Client *trello.Client
}
type TrelloItem struct {
Title string
}
type TrelloList struct {
Items []TrelloItem
}
type TrelloBoard struct {
Ctx TrelloCtx
Lists []TrelloList
}
2018-08-21 08:57:59 +00:00
func runcmd(command string) string {
shell := "/bin/sh"
flag := "-c"
out, err := exec.Command(shell, flag, command).Output()
if err != nil {
panic(err)
}
return string(out)
}
func NewTrello(token string) *TrelloCtx {
2018-08-21 23:50:50 +00:00
client := trello.NewClient(APP_KEY, token)
/*
spew.Dump(client)
if client == nil {
url := strings.Join([]string{
"https://trello.com/1/authorize?expiration=never",
"name=taskell",
"scope=read",
"response_type=token",
fmt.Sprintf("key=%s", APP_KEY),
}, "&")
text := strings.Join([]string{
"Wrong TRELLO_TOKEN value. Please visit:",
url,
"When you have your access token, set TRELLO_TOKEN=<your-token>",
}, "\n\n")
log.Panic(errors.New(text))
}
*/
ctx := TrelloCtx{}
ctx.Token = token
ctx.Client = client
return &ctx
}
func (ctx *TrelloCtx) GetBoard(boardUrl string) TrelloBoard {
return TrelloBoard{Ctx: *ctx}
}
func (*TrelloBoard) ExportToMarkdown() []string {
2018-08-21 23:50:50 +00:00
return []string{}
2018-08-21 08:50:30 +00:00
}
2018-08-21 23:50:50 +00:00
/*
2018-08-21 08:57:59 +00:00
func RunTaskell(boardUrl string) {
cmd := fmt.Sprintf("taskell -t %s -", boardUrl)
markdown := strings.TrimSpace(runcmd(cmd))
2018-08-21 23:50:50 +00:00
}*/