diff --git a/_site/content/posts/modules/trello.md b/_site/content/posts/modules/trello.md index c8649b69..88ec787d 100644 --- a/_site/content/posts/modules/trello.md +++ b/_site/content/posts/modules/trello.md @@ -14,15 +14,6 @@ Displays all Trello cards on specified lists. wtf/trello/ ``` -## Required ENV Variables - -Key: `WTF_TRELLO_APP_KEY`
-Value: Your Trello App Key.
-Key: `WTF_TRELLO_ACCESS_TOKEN`
-Value: Your Trello Access Token.
- -_You can get your API key at: trello.com/app-key._ - ## Keyboard Commands None. @@ -32,11 +23,13 @@ None. ### Single Trello List ```yaml -trello: +trello: + accessToken: "7b8b14f8743a408a93276d7155dd9ee2" + apiKey: "3276d7155dd9ee27b8b14f8743a408a9" board: Main enabled: true list: "Todo" - position: + position: height: 1 left: 2 top: 0 @@ -51,11 +44,13 @@ If you want to monitor multiple Trello lists, use the following configuration (note the difference in `list`): ```yaml -trello: +trello: + accessToken: "7b8b14f8743a408a93276d7155dd9ee2" + apiKey: "3276d7155dd9ee27b8b14f8743a408a9" board: Main enabled: true list: ["Todo", "Done"] - position: + position: height: 1 left: 2 top: 0 @@ -66,6 +61,12 @@ trello: ### Attributes +`accessToken`
+Value: Your Trello access token. + +`apiKey`
+Value: Your Trello API key. + `board`
The name of the Trello board.
diff --git a/_site/content/posts/modules/zendesk.md b/_site/content/posts/modules/zendesk.md index a86479af..b7e9ea16 100644 --- a/_site/content/posts/modules/zendesk.md +++ b/_site/content/posts/modules/zendesk.md @@ -14,14 +14,6 @@ Displays tickets in the "New" status - i.e. have not yet been assigned. wtf/zendesk/ ``` -## Required ENV Variables - -Key: `ZENDESK_API`
-Value: Your Zendesk API Token - -Key: `ZENDESK_DOMAIN`
-Value: Your Zendesk subdomain - ## Keyboard Commands Key: `[return]`
@@ -43,6 +35,7 @@ wtf/zendesk/ ```yaml zendesk: + apiKey: "3276d7155dd9ee27b8b14f8743a408a9" enabled: true position: top: 0 @@ -50,11 +43,15 @@ zendesk: height: 1 width: 1 status: "new" + subdomain: "your_domain" username: "your_email@acme.com" ``` ### Attributes +`apiKey`
+Value: Your Zendesk API token. + `enabled`
Determines whether or not this module is executed and if its data displayed onscreen.
Values: `true`, `false`. @@ -66,6 +63,9 @@ Defines where in the grid this module's widget will be displayed.
The status of tickets you want to retrieve. Values: `new`, `open`, `pending`, `hold`. +`subdomain`
+Value: Your Zendesk subdomain. + `username`
Your Zendesk username Values: A valid Zendesk username (usually an email address). diff --git a/trello/widget.go b/trello/widget.go index 2c2459a4..faa69abd 100644 --- a/trello/widget.go +++ b/trello/widget.go @@ -23,7 +23,10 @@ func NewWidget() *Widget { /* -------------------- Exported Functions -------------------- */ func (widget *Widget) Refresh() { - client := trello.NewClient(os.Getenv("WTF_TRELLO_APP_KEY"), os.Getenv("WTF_TRELLO_ACCESS_TOKEN")) + client := trello.NewClient( + widget.apiKey(), + widget.accessToken(), + ) // Get the cards searchResult, err := GetCards(client, getLists()) @@ -50,6 +53,21 @@ func (widget *Widget) Refresh() { } /* -------------------- Unexported Functions -------------------- */ + +func (widget *Widget) accessToken() string { + return wtf.Config.UString( + "wtf.mods.trello.accessToken", + os.Getenv("WTF_TRELLO_ACCESS_TOKEN"), + ) +} + +func (widget *Widget) apiKey() string { + return wtf.Config.UString( + "wtf.mods.trello.apiKey", + os.Getenv("WTF_TRELLO_APP_KEY"), + ) +} + func (widget *Widget) contentFrom(searchResult *SearchResult) string { str := "" diff --git a/zendesk/client.go b/zendesk/client.go index e450fb7b..19b7b54b 100644 --- a/zendesk/client.go +++ b/zendesk/client.go @@ -16,9 +16,19 @@ type Resource struct { Raw string } -var a = os.Getenv("ZENDESK_API") -var subdomain = os.Getenv("ZENDESK_SUBDOMAIN") -var baseURL = fmt.Sprintf("https://%v.zendesk.com/api/v2", subdomain) +func apiKey() string { + return wtf.Config.UString( + "wtf.mods.zendesk.apiKey", + os.Getenv("ZENDESK_API"), + ) +} + +func subdomain() string { + return wtf.Config.UString( + "wtf.mods.zendesk.apiKey", + os.Getenv("ZENDESK_API"), + ) +} func errHandler(err error) { if err != nil { @@ -26,20 +36,15 @@ func errHandler(err error) { } } -func buildUrl(baseURL string) string { - ticketURL := baseURL + "/tickets.json?sort_by=status" - return ticketURL -} - func api(key string, meth string, path string, params string) (*Resource, error) { - trn := &http.Transport{} client := &http.Client{ Transport: trn, } - var URL = buildUrl(baseURL) + baseURL := fmt.Sprintf("https://%v.zendesk.com/api/v2", subdomain()) + URL := baseURL + "/tickets.json?sort_by=status" req, err := http.NewRequest(meth, URL, bytes.NewBufferString(params)) if err != nil { diff --git a/zendesk/tickets.go b/zendesk/tickets.go index 8cbe53d2..a5ba7575 100644 --- a/zendesk/tickets.go +++ b/zendesk/tickets.go @@ -55,7 +55,7 @@ func listTickets(pag ...string) (*TicketArray, error) { } else { path = pag[0] } - resource, err := api(a, "GET", path, "") + resource, err := api(apiKey(), "GET", path, "") if err != nil { return nil, err } diff --git a/zendesk/widget.go b/zendesk/widget.go index c2b57ab6..cdf5825e 100644 --- a/zendesk/widget.go +++ b/zendesk/widget.go @@ -103,7 +103,7 @@ func (widget *Widget) openTicket() { sel := widget.selected if sel >= 0 && widget.result != nil && sel < len(widget.result.Tickets) { issue := &widget.result.Tickets[widget.selected] - ticketUrl := fmt.Sprintf("https://%s.zendesk.com/agent/tickets/%d", subdomain, issue.Id) + ticketUrl := fmt.Sprintf("https://%s.zendesk.com/agent/tickets/%d", subdomain(), issue.Id) wtf.OpenFile(ticketUrl) } }