Skip to content

Commit

Permalink
Merge pull request #2 from fimtitzgerald/item_struct
Browse files Browse the repository at this point in the history
Item struct
  • Loading branch information
Tim Fitzgerald authored Jul 23, 2018
2 parents 2c0c7f2 + 69cb4d0 commit ddc2e96
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 25 deletions.
Binary file modified test_builds/wtf
Binary file not shown.
29 changes: 7 additions & 22 deletions zendesk/tickets.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package zendesk

import (
"encoding/json"
"fmt"
//"fmt"
"log"
)

Expand Down Expand Up @@ -73,32 +73,17 @@ func listTickets(pag ...string) (*TicketArray, error) {

}

func newTickets() ([]string, error) {
var newTickets []string
func newTickets() ([]Ticket, error) {
newTickets := []Ticket{}
tickets, err := listTickets()
if err != nil {
log.Fatal(err)
}
for i := range tickets.Tickets {
if tickets.Tickets[i].Status == "new" {
requester := tickets.Tickets[i].Via
req, _ := requester.(map[string]interface{})
source := req["source"]
fromMap, _ := source.(map[string]interface{})
from := fromMap["from"]
fromValue, _ := from.(map[string]interface{})
name := fromValue["name"]

newTicket := fmt.Sprintf("%v - %v - %v - %v", tickets.Tickets[i].Id, tickets.Tickets[i].Status, tickets.Tickets[i].Subject, name)
newTickets = append(newTickets, newTicket)
}
}
if len(newTickets) < 1 {
fmt.Println("No unassigned tickets in queue - woop!!")
} else {
for i := range newTickets {
fmt.Println(newTickets[i])
for _, Ticket := range tickets.Tickets {
if Ticket.Status == "new" {
newTickets = append(newTickets, Ticket)
}
}

return newTickets, nil
}
26 changes: 23 additions & 3 deletions zendesk/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,35 @@ func (widget *Widget) Refresh() {

/* -------------------- Unexported Functions -------------------- */

func (widget *Widget) textContent(items []string) string {
func (widget *Widget) textContent(items []Ticket) string {
if len(items) == 0 {
return fmt.Sprintf("No unassigned tickets in queue - woop!!")
}

str := ""
for i := range items {
str = items[i]
for _, data := range items {
//str = items[i]
//str = fmt.Sprintf(data.Id)
str = str + widget.format(data)
}

return str
}

func (widget *Widget) format(ticket Ticket) string {
var str string
requesterName := widget.parseRequester(ticket)
str = fmt.Sprintf(" [green]%d - %s\n %s\n\n", ticket.Id, requesterName, ticket.Subject)
return str
}

func (widget *Widget) parseRequester(ticket Ticket) interface{} {
viaMap := ticket.Via
via := viaMap.(map[string]interface{})
source := via["source"]
fromMap, _ := source.(map[string]interface{})
from := fromMap["from"]
fromValMap := from.(map[string]interface{})
fromName := fromValMap["name"]
return fromName
}

0 comments on commit ddc2e96

Please sign in to comment.