-
Notifications
You must be signed in to change notification settings - Fork 4
/
folders.go
131 lines (105 loc) · 2.99 KB
/
folders.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
131
package grafana
import (
"fmt"
"time"
)
type FoldersService struct {
client *Client
}
type Folders []Folder
type Folder struct {
ID int `json:"id,omitempty"`
UID string `json:"uid,omitempty"`
Title string `json:"title,omitempty"`
URL string `json:"url,omitempty"`
HasACL bool `json:"hasAcl,omitempty"`
CanSave bool `json:"canSave,omitempty"`
CanEdit bool `json:"canEdit,omitempty"`
CanAdmin bool `json:"canAdmin,omitempty"`
CreatedBy string `json:"createdBy,omitempty"`
Created *time.Time `json:"created,omitempty"`
UpdatedBy string `json:"updatedBy,omitempty"`
Updated *time.Time `json:"updated,omitempty"`
Version int `json:"version,omitempty"`
}
func (s *FoldersService) GetAllFolders() (*Folders, *Response, error) {
req, err := s.client.NewRequest("GET", "folders", nil, nil)
if err != nil {
return nil, nil, err
}
f := new(Folders)
resp, err := s.client.Do(req, f)
if err != nil {
return nil, resp, err
}
return f, resp, err
}
func (s *FoldersService) GetFolderByID(id int) (*Folder, *Response, error) {
u := fmt.Sprintf("folders/id/%d", id)
req, err := s.client.NewRequest("GET", u, nil, nil)
if err != nil {
return nil, nil, err
}
f := new(Folder)
resp, err := s.client.Do(req, f)
if err != nil {
return nil, resp, err
}
return f, resp, err
}
func (s *FoldersService) GetFolderByUID(uid string) (*Folder, *Response, error) {
u := fmt.Sprintf("folders/%s", uid)
req, err := s.client.NewRequest("GET", u, nil, nil)
if err != nil {
return nil, nil, err
}
f := new(Folder)
resp, err := s.client.Do(req, f)
if err != nil {
return nil, resp, err
}
return f, resp, err
}
type CreateFolderOptions struct {
UID string `json:"uid,omitempty"` //optional, will be generated if not set
Title string `json:"title,omitempty"`
}
func (s *FoldersService) CreateFolder(opt *CreateFolderOptions) (*Folder, *Response, error) {
req, err := s.client.NewRequest("POST", "folders", opt, nil)
if err != nil {
return nil, nil, err
}
f := new(Folder)
resp, err := s.client.Do(req, f)
if err != nil {
return nil, resp, err
}
return f, resp, err
}
type UpdateFolderByUIDOptions struct {
UID string `json:"uid,omitempty"` //updates the uid
Title string `json:"title,omitempty"`
Version int `json:"version,omitempty"`
Overwrite bool `json:"overwrite,omitempty"`
}
func (s *FoldersService) UpdateFolderByUID(uid string, opt *UpdateFolderByUIDOptions) (*Folder, *Response, error) {
u := fmt.Sprintf("folders/%s", uid)
req, err := s.client.NewRequest("PUT", u, opt, nil)
if err != nil {
return nil, nil, err
}
f := new(Folder)
resp, err := s.client.Do(req, f)
if err != nil {
return nil, resp, err
}
return f, resp, err
}
func (s *FoldersService) DeleteFolderByUID(uid string) (*Response, error) {
u := fmt.Sprintf("folders/%s", uid)
req, err := s.client.NewRequest("DELETE", u, nil, nil)
if err != nil {
return nil, err
}
return s.client.Do(req, nil)
}