-
Notifications
You must be signed in to change notification settings - Fork 1
/
support_triggers.go
75 lines (63 loc) · 1.74 KB
/
support_triggers.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
package zendesk
import (
"context"
"fmt"
"net/http"
"net/url"
"time"
)
type TriggersResponse struct {
Triggers []Trigger `json:"triggers"`
CursorPaginationResponse
}
type Trigger struct {
ID TriggerID `json:"id"`
URL string `json:"url"`
Title string `json:"title"`
Active bool `json:"active"`
UpdatedAt time.Time `json:"updated_at"`
CreatedAt time.Time `json:"created_at"`
Default bool `json:"default"`
Actions []BusinessRuleAction `json:"actions"`
Conditions BusinessRuleConditions `json:"conditions"`
Description *string `json:"description"`
Position int `json:"position"`
RawTitle string `json:"raw_title"`
CategoryID string `json:"category_id"`
}
// https://developer.zendesk.com/api-reference/ticketing/business-rules/triggers/
type TriggerService struct {
client *client
}
// https://developer.zendesk.com/api-reference/ticketing/business-rules/triggers/#list-triggers
func (s *TriggerService) List(
ctx context.Context,
pageHandler func(response TriggersResponse) error,
) error {
query := url.Values{}
query.Set("page[size]", "100")
endpoint := fmt.Sprintf("/api/v2/triggers?%s", query.Encode())
for {
target := TriggersResponse{}
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.Meta.HasMore {
break
}
endpoint = target.Links.Next
}
return nil
}