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
switch widgetName {
case "bamboohr":
widget = bamboohr.NewWidget(app)
cfg := bamboohr.NewSettingsFromYAML(wtf.Config)
widget = bamboohr.NewWidget(app, cfg)
case "bargraph":
widget = bargraph.NewWidget(app)
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 (
"fmt"
"os"
// "os"
"github.com/rivo/tview"
"github.com/wtfutil/wtf/wtf"
)
const APIURI = "https://api.bamboohr.com/api/gateway.php"
type Widget struct {
wtf.TextWidget
settings *Settings
}
func NewWidget(app *tview.Application) *Widget {
func NewWidget(app *tview.Application, settings *Settings) *Widget {
widget := Widget{
TextWidget: wtf.NewTextWidget(app, "BambooHR", "bamboohr", false),
settings: settings,
}
return &widget
@ -23,17 +29,12 @@ func NewWidget(app *tview.Application) *Widget {
/* -------------------- Exported Functions -------------------- */
func (widget *Widget) Refresh() {
apiKey := wtf.Config.UString(
"wtf.mods.bamboohr.apiKey",
os.Getenv("WTF_BAMBOO_HR_TOKEN"),
client := NewClient(
APIURI,
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(
"timeOff",
wtf.Now().Format(wtf.DateFormat),