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

Url added to BambooHR config

This commit is contained in:
Chris Cummer 2018-04-04 08:58:17 -07:00 committed by Chris Cummer
parent b91e1be8df
commit b58c0ea212
5 changed files with 25 additions and 13 deletions

View File

@ -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")
//}

View File

@ -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"),
}

View File

@ -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()

View File

@ -2,5 +2,6 @@ wtf:
refreshInterval: 1
bamboohr:
refreshInterval: 900
url: "https://api.bamboohr.com/api/gateway.php"
status:
refreshInterval: 1

View File

@ -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")
}