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

Decouple bamboohr client from widget

Have the client be in charge of API
Have the widget be in charge of widget config
This is a step in the direction of running multiple version (with their own configs)
This commit is contained in:
Sean Smith 2019-02-15 23:41:46 -05:00
parent 1f93ae7972
commit 14d85715b0
2 changed files with 16 additions and 20 deletions

View File

@ -3,9 +3,6 @@ package bamboohr
import (
"encoding/xml"
"fmt"
"os"
"github.com/wtfutil/wtf/wtf"
)
// A Client represents the data required to connect to the BambooHR API
@ -16,13 +13,13 @@ type Client struct {
}
// NewClient creates and returns a new BambooHR client
func NewClient(url string) *Client {
func NewClient(url string, apiKey string, subdomain string) *Client {
client := Client{
apiBase: url,
apiKey: apiKey,
subdomain: subdomain,
}
client.loadAPICredentials()
return &client
}
@ -62,15 +59,3 @@ func (client *Client) away(startDate, endDate string) (cal Calendar, err error)
return
}
func (client *Client) loadAPICredentials() {
client.apiKey = wtf.Config.UString(
"wtf.mods.bamboohr.apiKey",
os.Getenv("WTF_BAMBOO_HR_TOKEN"),
)
client.subdomain = wtf.Config.UString(
"wtf.mods.bamboohr.subdomain",
os.Getenv("WTF_BAMBOO_HR_SUBDOMAIN"),
)
}

View File

@ -2,6 +2,7 @@ package bamboohr
import (
"fmt"
"os"
"github.com/rivo/tview"
"github.com/wtfutil/wtf/wtf"
@ -22,7 +23,17 @@ func NewWidget(app *tview.Application) *Widget {
/* -------------------- Exported Functions -------------------- */
func (widget *Widget) Refresh() {
client := NewClient("https://api.bamboohr.com/api/gateway.php")
apiKey := wtf.Config.UString(
"wtf.mods.bamboohr.apiKey",
os.Getenv("WTF_BAMBOO_HR_TOKEN"),
)
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),