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:
parent
1f93ae7972
commit
14d85715b0
@ -3,9 +3,6 @@ package bamboohr
|
|||||||
import (
|
import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/wtfutil/wtf/wtf"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// A Client represents the data required to connect to the BambooHR API
|
// 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
|
// NewClient creates and returns a new BambooHR client
|
||||||
func NewClient(url string) *Client {
|
func NewClient(url string, apiKey string, subdomain string) *Client {
|
||||||
client := Client{
|
client := Client{
|
||||||
apiBase: url,
|
apiBase: url,
|
||||||
|
apiKey: apiKey,
|
||||||
|
subdomain: subdomain,
|
||||||
}
|
}
|
||||||
|
|
||||||
client.loadAPICredentials()
|
|
||||||
|
|
||||||
return &client
|
return &client
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,15 +59,3 @@ func (client *Client) away(startDate, endDate string) (cal Calendar, err error)
|
|||||||
|
|
||||||
return
|
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"),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
@ -2,6 +2,7 @@ package bamboohr
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
"github.com/wtfutil/wtf/wtf"
|
"github.com/wtfutil/wtf/wtf"
|
||||||
@ -22,7 +23,17 @@ func NewWidget(app *tview.Application) *Widget {
|
|||||||
/* -------------------- Exported Functions -------------------- */
|
/* -------------------- Exported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) Refresh() {
|
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(
|
todayItems := client.Away(
|
||||||
"timeOff",
|
"timeOff",
|
||||||
wtf.Now().Format(wtf.DateFormat),
|
wtf.Now().Format(wtf.DateFormat),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user