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:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user