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

WTF-400 BambooHR extracted to new config format

This commit is contained in:
Chris Cummer 2019-04-13 11:36:24 -07:00
parent cf661e7e15
commit 936acc0326
3 changed files with 41 additions and 12 deletions

View File

@ -182,7 +182,8 @@ func makeWidget(app *tview.Application, pages *tview.Pages, widgetName string) w
// Always in alphabetical order // Always in alphabetical order
switch widgetName { switch widgetName {
case "bamboohr": case "bamboohr":
widget = bamboohr.NewWidget(app) cfg := bamboohr.NewSettingsFromYAML(wtf.Config)
widget = bamboohr.NewWidget(app, cfg)
case "bargraph": case "bargraph":
widget = bargraph.NewWidget(app) widget = bargraph.NewWidget(app)
case "bittrex": case "bittrex":

View File

@ -0,0 +1,27 @@
package bamboohr
import (
"os"
"github.com/olebedev/config"
"github.com/wtfutil/wtf/cfg"
)
type Settings struct {
Common *cfg.Common
APIKey string
Subdomain string
}
func NewSettingsFromYAML(ymlConfig *config.Config) *Settings {
localConfig, _ := ymlConfig.Get("wtf.mods.bamboohr")
settings := Settings{
Common: cfg.NewCommonSettingsFromYAML(ymlConfig),
APIKey: localConfig.UString("apiKey", os.Getenv("WTF_BAMBOO_HR_TOKEN")),
Subdomain: localConfig.UString("subdomain", os.Getenv("WTF_BAMBOO_HR_SUBDOMAIN")),
}
return &settings
}

View File

@ -2,19 +2,25 @@ package bamboohr
import ( import (
"fmt" "fmt"
"os" // "os"
"github.com/rivo/tview" "github.com/rivo/tview"
"github.com/wtfutil/wtf/wtf" "github.com/wtfutil/wtf/wtf"
) )
const APIURI = "https://api.bamboohr.com/api/gateway.php"
type Widget struct { type Widget struct {
wtf.TextWidget wtf.TextWidget
settings *Settings
} }
func NewWidget(app *tview.Application) *Widget { func NewWidget(app *tview.Application, settings *Settings) *Widget {
widget := Widget{ widget := Widget{
TextWidget: wtf.NewTextWidget(app, "BambooHR", "bamboohr", false), TextWidget: wtf.NewTextWidget(app, "BambooHR", "bamboohr", false),
settings: settings,
} }
return &widget return &widget
@ -23,17 +29,12 @@ func NewWidget(app *tview.Application) *Widget {
/* -------------------- Exported Functions -------------------- */ /* -------------------- Exported Functions -------------------- */
func (widget *Widget) Refresh() { func (widget *Widget) Refresh() {
apiKey := wtf.Config.UString( client := NewClient(
"wtf.mods.bamboohr.apiKey", APIURI,
os.Getenv("WTF_BAMBOO_HR_TOKEN"), widget.settings.APIKey,
widget.settings.Subdomain,
) )
subdomain := wtf.Config.UString(
"wtf.mods.bamboohr.subdomain",
os.Getenv("WTF_BAMBOO_HR_SUBDOMAIN"),
)
client := NewClient("https://api.bamboohr.com/api/gateway.php", apiKey, subdomain)
todayItems := client.Away( todayItems := client.Away(
"timeOff", "timeOff",
wtf.Now().Format(wtf.DateFormat), wtf.Now().Format(wtf.DateFormat),