-
Notifications
You must be signed in to change notification settings - Fork 1
/
guide_sections.go
83 lines (71 loc) · 2 KB
/
guide_sections.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
package zendesk
import (
"context"
"fmt"
"net/http"
"net/url"
"time"
)
type SectionsResponse struct {
Sections []Section `json:"sections"`
Page int `json:"page"`
PreviousPage any `json:"previous_page"`
NextPage string `json:"next_page"`
PerPage int `json:"per_page"`
PageCount int `json:"page_count"`
Count int `json:"count"`
SortBy string `json:"sort_by"`
SortOrder string `json:"sort_order"`
CursorPaginationResponse
}
type Section struct {
CategoryID CategoryID `json:"category_id"`
CreatedAt time.Time `json:"created_at"`
Description string `json:"description"`
HTMLURL string `json:"html_url"`
ID SectionID `json:"id"`
Locale string `json:"locale"`
Name string `json:"name"`
Outdated bool `json:"outdated"`
ParentSectionID any `json:"parent_section_id"`
Position uint `json:"position"`
Sorting string `json:"sorting"`
SourceLocale string `json:"source_locale"`
ThemeTemplate string `json:"theme_template"`
UpdatedAt time.Time `json:"updated_at"`
URL string `json:"url"`
}
// https://developer.zendesk.com/api-reference/help_center/help-center-api/sections/
type SectionService struct {
client *client
}
func (s SectionService) List(
ctx context.Context,
pageHandler func(response SectionsResponse) error,
) error {
query := url.Values{}
query.Set("page[size]", "100")
for {
target := SectionsResponse{}
request, err := http.NewRequestWithContext(
ctx,
http.MethodGet,
fmt.Sprintf("/api/v2/help_center/sections?%s", query.Encode()),
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
}
query.Set("page[after]", target.Meta.AfterCursor)
}
return nil
}