Initial commit

This commit is contained in:
Ian Gulliver
2021-09-05 20:18:11 +00:00
commit 45b805d290
3 changed files with 54 additions and 0 deletions

44
asana/client.go Normal file
View File

@@ -0,0 +1,44 @@
package asana
import "fmt"
import "net/http"
import "os"
type withHeader struct {
Header http.Header
rt http.RoundTripper
}
func WithHeader(rt http.RoundTripper) withHeader {
if rt == nil {
rt = http.DefaultTransport
}
return withHeader{
Header: make(http.Header),
rt: rt,
}
}
func (h withHeader) RoundTrip(req *http.Request) (*http.Response, error) {
for k, v := range h.Header {
req.Header[k] = v
}
return h.rt.RoundTrip(req)
}
func Fetch() {
c := &http.Client{}
rt := WithHeader(c.Transport)
rt.Header.Set("Authorization", fmt.Sprintf("Bearer %s", os.Getenv("ASANA_TOKEN")))
c.Transport = rt
resp, err := c.Get("https://app.asana.com/api/1.0/users/me")
if err != nil {
panic(err)
}
fmt.Printf("%#v\n", resp)
}

3
go.mod Normal file
View File

@@ -0,0 +1,3 @@
module github.com/firestuff/asana-rules
go 1.13

7
main.go Normal file
View File

@@ -0,0 +1,7 @@
package main
import "github.com/firestuff/asana-rules/asana"
func main() {
asana.Fetch()
}