From b58c0ea2123c72b5f36e9b61a2025ec3be6ffcb4 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Wed, 4 Apr 2018 08:58:17 -0700 Subject: [PATCH] Url added to BambooHR config --- bamboohr/bamboohr.go | 21 +++++++++++---------- bamboohr/client.go | 4 ++-- bamboohr/widget.go | 6 +++++- config.yml | 1 + wtf/utils.go | 6 ++++++ 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/bamboohr/bamboohr.go b/bamboohr/bamboohr.go index c186d220..6f936b70 100644 --- a/bamboohr/bamboohr.go +++ b/bamboohr/bamboohr.go @@ -1,17 +1,18 @@ package bamboohr import ( - "time" +//"time" ) -func Fetch() []Item { - client := NewClient() - result := client.Away("timeOff", today(), today()) +// TODO Move this into the client. Why is it separate? +//func Fetch() []Item { +//client := NewClient() +//result := client.Away("timeOff", today(), today()) - return result -} +//return result +//} -func today() string { - localNow := time.Now().Local() - return localNow.Format("2006-01-02") -} +//func today() string { +//localNow := time.Now().Local() +//return localNow.Format("2006-01-02") +//} diff --git a/bamboohr/client.go b/bamboohr/client.go index 8e932366..fd8664d0 100644 --- a/bamboohr/client.go +++ b/bamboohr/client.go @@ -14,9 +14,9 @@ type Client struct { } // NewClient creates and returns a new BambooHR client -func NewClient() *Client { +func NewClient(url string) *Client { client := Client{ - apiBase: "https://api.bamboohr.com/api/gateway.php", + apiBase: url, apiKey: os.Getenv("WTF_BAMBOO_HR_TOKEN"), subdomain: os.Getenv("WTF_BAMBOO_HR_SUBDOMAIN"), } diff --git a/bamboohr/widget.go b/bamboohr/widget.go index c28d0f58..e5d62307 100644 --- a/bamboohr/widget.go +++ b/bamboohr/widget.go @@ -29,6 +29,7 @@ func NewWidget(config *config.Config) *Widget { RefreshedAt: time.Now(), RefreshInt: refreshInterval, }, + Config: config, } widget.addView() @@ -40,7 +41,10 @@ func NewWidget(config *config.Config) *Widget { /* -------------------- Exported Functions -------------------- */ func (widget *Widget) Refresh() { - items := Fetch() + url, _ := widget.Config.String("wtf.bamboohr.url") + + client := NewClient(url) + items := client.Away("timeOff", wtf.Today(), wtf.Today()) widget.View.SetTitle(fmt.Sprintf(" 👽 Away (%d) ", len(items))) widget.RefreshedAt = time.Now() diff --git a/config.yml b/config.yml index 92530864..a17c5e48 100644 --- a/config.yml +++ b/config.yml @@ -2,5 +2,6 @@ wtf: refreshInterval: 1 bamboohr: refreshInterval: 900 + url: "https://api.bamboohr.com/api/gateway.php" status: refreshInterval: 1 diff --git a/wtf/utils.go b/wtf/utils.go index c970d574..f9d58cf2 100644 --- a/wtf/utils.go +++ b/wtf/utils.go @@ -4,6 +4,7 @@ import ( "fmt" "io/ioutil" "os/exec" + "time" ) func CenterText(str string, width int) string { @@ -29,3 +30,8 @@ func ExecuteCommand(cmd *exec.Cmd) string { return str } + +func Today() string { + localNow := time.Now().Local() + return localNow.Format("2006-01-02") +}