Start adding DSL
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
package asana
|
package asanaclient
|
||||||
|
|
||||||
import "bytes"
|
import "bytes"
|
||||||
import "encoding/json"
|
import "encoding/json"
|
||||||
59
asanarules/rules.go
Normal file
59
asanarules/rules.go
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
package asanarules
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
type periodic struct {
|
||||||
|
duration time.Duration
|
||||||
|
done chan bool
|
||||||
|
}
|
||||||
|
|
||||||
|
var periodics = []*periodic{}
|
||||||
|
|
||||||
|
func Every(d time.Duration) *periodic {
|
||||||
|
ret := &periodic{
|
||||||
|
duration: d,
|
||||||
|
done: make(chan bool),
|
||||||
|
}
|
||||||
|
|
||||||
|
periodics = append(periodics, ret)
|
||||||
|
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
func Loop() {
|
||||||
|
for _, periodic := range periodics {
|
||||||
|
periodic.start()
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, periodic := range periodics {
|
||||||
|
periodic.wait()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *periodic) MyTasks() *periodic {
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *periodic) start() {
|
||||||
|
go p.loop()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *periodic) wait() {
|
||||||
|
<-p.done
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *periodic) loop() {
|
||||||
|
ticker := time.NewTicker(p.duration)
|
||||||
|
|
||||||
|
for {
|
||||||
|
<-ticker.C
|
||||||
|
p.exec()
|
||||||
|
}
|
||||||
|
|
||||||
|
close(p.done)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *periodic) exec() {
|
||||||
|
fmt.Printf("exec\n")
|
||||||
|
}
|
||||||
105
main.go
105
main.go
@@ -1,61 +1,70 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "fmt"
|
// import "fmt"
|
||||||
|
import "time"
|
||||||
|
|
||||||
import "github.com/firestuff/asana-rules/asana"
|
import . "github.com/firestuff/asana-rules/asanarules"
|
||||||
|
|
||||||
|
// import "github.com/firestuff/asana-rules/asanaclient"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
a := asana.NewClientFromEnv()
|
Every(5 * time.Second).
|
||||||
|
MyTasks()
|
||||||
|
|
||||||
me, err := a.GetMe()
|
Loop()
|
||||||
if err != nil {
|
/*
|
||||||
panic(err)
|
a := asana.NewClientFromEnv()
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("User: %s\n", me)
|
me, err := a.GetMe()
|
||||||
|
|
||||||
wrk, err := a.GetWorkspace()
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("Workspace: %s\n", wrk)
|
|
||||||
|
|
||||||
utl, err := a.GetUserTaskList(me, wrk)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("User Task List: %s\n", utl)
|
|
||||||
|
|
||||||
secs, err := a.GetSections(utl)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("Sections:\n")
|
|
||||||
for _, sec := range secs {
|
|
||||||
fmt.Printf("\t%s\n", sec)
|
|
||||||
|
|
||||||
if sec.Name != "Recently Assigned" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
q := &asana.SearchQuery{
|
|
||||||
SectionsAny: []*asana.Section{sec},
|
|
||||||
Completed: asana.FALSE,
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks, err := a.Search(wrk, q)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, task := range tasks {
|
fmt.Printf("User: %s\n", me)
|
||||||
fmt.Printf("\t\t%s\n", task)
|
|
||||||
a.AddTaskToSection(task, &asana.Section{
|
wrk, err := a.GetWorkspace()
|
||||||
GID: "1200372179004456",
|
if err != nil {
|
||||||
})
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
fmt.Printf("Workspace: %s\n", wrk)
|
||||||
|
|
||||||
|
utl, err := a.GetUserTaskList(me, wrk)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("User Task List: %s\n", utl)
|
||||||
|
|
||||||
|
secs, err := a.GetSections(utl)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("Sections:\n")
|
||||||
|
for _, sec := range secs {
|
||||||
|
fmt.Printf("\t%s\n", sec)
|
||||||
|
|
||||||
|
if sec.Name != "Recently Assigned" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
q := &asana.SearchQuery{
|
||||||
|
SectionsAny: []*asana.Section{sec},
|
||||||
|
Completed: asana.FALSE,
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks, err := a.Search(wrk, q)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, task := range tasks {
|
||||||
|
fmt.Printf("\t\t%s\n", task)
|
||||||
|
a.AddTaskToSection(task, &asana.Section{
|
||||||
|
GID: "1200372179004456",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user