github.com/wtfutil/wtf@v0.43.0/modules/zendesk/tickets.go (about)

     1  package zendesk
     2  
     3  import (
     4  	"encoding/json"
     5  	"log"
     6  )
     7  
     8  type TicketArray struct {
     9  	Count         int    `json:"count"`
    10  	Created       string `json:"created"`
    11  	Next_page     string `json:"next_page"`
    12  	Previous_page string `json:"previous_page"`
    13  	Tickets       []Ticket
    14  }
    15  
    16  type Ticket struct {
    17  	Id                    uint64      `json:"id"`
    18  	URL                   string      `json:"url"`
    19  	ExternalId            string      `json:"external_id"`
    20  	CreatedAt             string      `json:"created_at"`
    21  	UpdatedAt             string      `json:"updated_at"`
    22  	Type                  string      `json:"type"`
    23  	Subject               string      `json:"subject"`
    24  	RawSubject            string      `json:"raw_subject"`
    25  	Description           string      `json:"description"`
    26  	Priority              string      `json:"priority"`
    27  	Status                string      `json:"status"`
    28  	Recipient             string      `json:"recipient"`
    29  	RequesterId           uint64      `json:"requester_id"`
    30  	SubmitterId           uint64      `json:"submitter_id"`
    31  	AssigneeId            uint64      `json:"assignee_id"`
    32  	OrganizationId        uint32      `json:"organization_id"`
    33  	GroupId               uint32      `json:"group_id"`
    34  	CollaboratorIds       []int64     `json:"collaborator_ids"`
    35  	ForumTopicId          uint32      `json:"forum_topic_id"`
    36  	ProblemId             uint32      `json:"problem_id"`
    37  	HasIncidents          bool        `json:"has_incidents"`
    38  	DueAt                 string      `json:"due_at"`
    39  	Tags                  []string    `json:"tags"`
    40  	Satisfaction_rating   string      `json:"satisfaction_rating"`
    41  	Ticket_form_id        uint32      `json:"ticket_form_id"`
    42  	Sharing_agreement_ids interface{} `json:"sharing_agreement_ids"`
    43  	Via                   interface{} `json:"via"`
    44  	Custom_Fields         interface{} `json:"custom_fields"`
    45  	Fields                interface{} `json:"fields"`
    46  }
    47  
    48  func (widget *Widget) listTickets(pag ...string) (*TicketArray, error) {
    49  	tickets := &TicketArray{}
    50  
    51  	resource, err := widget.api("GET")
    52  	if err != nil {
    53  		return nil, err
    54  	}
    55  
    56  	err = json.Unmarshal([]byte(resource.Raw), tickets)
    57  	if err != nil {
    58  		return nil, err
    59  	}
    60  
    61  	return tickets, err
    62  }
    63  
    64  func (widget *Widget) newTickets() (*TicketArray, error) {
    65  	newTicketArray := &TicketArray{}
    66  	tickets, err := widget.listTickets(widget.settings.apiKey)
    67  	if err != nil {
    68  		log.Fatal(err)
    69  	}
    70  	for _, Ticket := range tickets.Tickets {
    71  		if Ticket.Status == widget.settings.status && Ticket.Status != "closed" && Ticket.Status != "solved" {
    72  			newTicketArray.Tickets = append(newTicketArray.Tickets, Ticket)
    73  		}
    74  	}
    75  
    76  	return newTicketArray, nil
    77  }