-
Notifications
You must be signed in to change notification settings - Fork 1
/
support_ticket_custom_status.go
130 lines (104 loc) · 3.1 KB
/
support_ticket_custom_status.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package zendesk
import (
"context"
"fmt"
"net/http"
)
// https://developer.zendesk.com/api-reference/ticketing/tickets/custom_ticket_statuses/
type CustomStatusService struct {
client *client
}
// https://developer.zendesk.com/api-reference/ticketing/tickets/custom_ticket_statuses/#json-format
type CustomStatus struct {
Active bool `json:"active"`
ID CustomStatusID `json:"id"`
AgentLabel string `json:"agent_label"`
StatusCategory CustomStatusCategory `json:"status_category"`
}
type CustomStatusCategory string
const (
StatusCategoryNew CustomStatusCategory = "new"
StatusCategoryOpen CustomStatusCategory = "open"
StatusCategoryPending CustomStatusCategory = "pending"
StatusCategoryHold CustomStatusCategory = "hold"
// Tickets with a "Closed" status belong to the "StatusCategorySolved" status category.
StatusCategorySolved CustomStatusCategory = "solved"
)
type CustomStatusesResponse struct {
CustomStatuses []CustomStatus `json:"custom_statuses"`
OffsetPaginationResponse
}
type CustomStatusResponse struct {
CustomStatus CustomStatus `json:"custom_status"`
}
type CustomStatusPayload struct {
CustomStatus any `json:"custom_status"`
}
/*
https://developer.zendesk.com/api-reference/ticketing/tickets/custom_ticket_statuses/#list-custom-ticket-statuses
Does not support cursor pagination.
*/
func (s CustomStatusService) List(
ctx context.Context,
pageHandler func(response CustomStatusesResponse) error,
) error {
endpoint := "/api/v2/custom_statuses"
for {
target := CustomStatusesResponse{}
request, err := http.NewRequestWithContext(
ctx,
http.MethodGet,
endpoint,
http.NoBody,
)
if err != nil {
return err
}
if err := s.client.ZendeskRequest(request, &target); err != nil {
return err
}
if err := pageHandler(target); err != nil {
return err
}
if target.NextPage != nil {
endpoint = *target.NextPage
continue
}
break
}
return nil
}
// https://developer.zendesk.com/api-reference/ticketing/tickets/custom_ticket_statuses/#show-custom-ticket-status
func (s CustomStatusService) Show(ctx context.Context, id CustomStatusID) (CustomStatus, error) {
target := CustomStatusResponse{}
request, err := http.NewRequestWithContext(
ctx,
http.MethodGet,
fmt.Sprintf("/api/v2/custom_statuses/%d", id),
http.NoBody,
)
if err != nil {
return CustomStatus{}, err
}
if err := s.client.ZendeskRequest(request, &target); err != nil {
return CustomStatus{}, err
}
return target.CustomStatus, nil
}
// https://developer.zendesk.com/api-reference/ticketing/tickets/custom_ticket_statuses/#create-custom-ticket-status
func (s CustomStatusService) Create(ctx context.Context, payload CustomStatusPayload) (CustomStatusResponse, error) {
target := CustomStatusResponse{}
request, err := http.NewRequestWithContext(
ctx,
http.MethodPost,
"/api/v2/custom_statuses",
structToReader(payload),
)
if err != nil {
return CustomStatusResponse{}, err
}
if err := s.client.ZendeskRequest(request, &target); err != nil {
return CustomStatusResponse{}, err
}
return target, nil
}