mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Clean up the Zendesk module's API credentials loading
This commit is contained in:
parent
2fe8164e20
commit
b6036a3eae
@ -14,15 +14,6 @@ Displays all Trello cards on specified lists.
|
||||
wtf/trello/
|
||||
```
|
||||
|
||||
## Required ENV Variables
|
||||
|
||||
<span class="caption">Key:</span> `WTF_TRELLO_APP_KEY` <br />
|
||||
<span class="caption">Value:</span> Your Trello App Key. <br />
|
||||
<span class="caption">Key:</span> `WTF_TRELLO_ACCESS_TOKEN` <br />
|
||||
<span class="caption">Value:</span> Your Trello Access Token. <br />
|
||||
|
||||
_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` <br />
|
||||
Value: Your Trello access token.
|
||||
|
||||
`apiKey` <br />
|
||||
Value: Your Trello API key.
|
||||
|
||||
`board` <br />
|
||||
The name of the Trello board. <br />
|
||||
|
||||
|
@ -14,14 +14,6 @@ Displays tickets in the "New" status - i.e. have not yet been assigned.
|
||||
wtf/zendesk/
|
||||
```
|
||||
|
||||
## Required ENV Variables
|
||||
|
||||
<span class="caption">Key:</span> `ZENDESK_API` <br />
|
||||
<span class="caption">Value:</span> Your Zendesk API Token
|
||||
|
||||
<span class="caption">Key:</span> `ZENDESK_DOMAIN` <br />
|
||||
<span class="caption">Value:</span> Your Zendesk subdomain
|
||||
|
||||
## Keyboard Commands
|
||||
|
||||
<span class="caption">Key:</span> `[return]` <br />
|
||||
@ -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` <br />
|
||||
Value: Your Zendesk API token.
|
||||
|
||||
`enabled` <br />
|
||||
Determines whether or not this module is executed and if its data displayed onscreen. <br />
|
||||
Values: `true`, `false`.
|
||||
@ -66,6 +63,9 @@ Defines where in the grid this module's widget will be displayed. <br />
|
||||
The status of tickets you want to retrieve.
|
||||
Values: `new`, `open`, `pending`, `hold`.
|
||||
|
||||
`subdomain` <br />
|
||||
Value: Your Zendesk subdomain.
|
||||
|
||||
`username` <br />
|
||||
Your Zendesk username
|
||||
Values: A valid Zendesk username (usually an email address).
|
||||
|
@ -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 := ""
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user