-
Notifications
You must be signed in to change notification settings - Fork 7
/
folder_service.go
57 lines (47 loc) · 1.25 KB
/
folder_service.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
package yext
const folderPath = "folders"
var (
FolderListMaxLimit = 1000
)
// Folder is a representation of a Folder in Yext Location Manager.
// For details see http://developer.yext.com/docs/api-reference/#operation/getLocationFolders
type Folder struct {
Id string `json:"id"`
Name string `json:"name"`
ParentId string `json:"parentId"`
}
type FolderService struct {
client *Client
}
type FolderListResponse struct {
Count int `json:"count"`
Folders []*Folder `json:"folders"`
}
func (s *FolderService) ListAll() ([]*Folder, error) {
var folders []*Folder
var lg listRetriever = func(opts *ListOptions) (int, int, error) {
flr, _, err := s.List(opts)
if err != nil {
return 0, 0, err
}
folders = append(folders, flr.Folders...)
return len(flr.Folders), flr.Count, err
}
if err := listHelper(lg, &ListOptions{Limit: FolderListMaxLimit}); err != nil {
return nil, err
} else {
return folders, nil
}
}
func (s *FolderService) List(opts *ListOptions) (*FolderListResponse, *Response, error) {
requrl, err := addListOptions(folderPath, opts)
if err != nil {
return nil, nil, err
}
v := &FolderListResponse{}
r, err := s.client.DoRequest("GET", requrl, v)
if err != nil {
return nil, r, err
}
return v, r, err
}