forked from grafana/grafana-api-golang-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
org_preferences.go
50 lines (41 loc) · 1.28 KB
/
org_preferences.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
package gapi
import (
"encoding/json"
)
// UpdateOrgPreferencesResponse represents the response to a request
// updating Grafana org preferences.
type UpdateOrgPreferencesResponse struct {
Message string `json:"message"`
}
// OrgPreferences fetches org preferences.
func (c *Client) OrgPreferences() (Preferences, error) {
var prefs Preferences
err := c.request("GET", "/api/org/preferences", nil, nil, &prefs)
return prefs, err
}
// UpdateOrgPreferences updates only those org preferences specified in the passed Preferences, without impacting others.
func (c *Client) UpdateOrgPreferences(p Preferences) (UpdateOrgPreferencesResponse, error) {
var resp UpdateOrgPreferencesResponse
data, err := json.Marshal(p)
if err != nil {
return resp, err
}
err = c.request("PATCH", "/api/org/preferences", nil, data, &resp)
if err != nil {
return resp, err
}
return resp, err
}
// UpdateAllOrgPreferences overrwrites all org preferences with the passed Preferences.
func (c *Client) UpdateAllOrgPreferences(p Preferences) (UpdateOrgPreferencesResponse, error) {
var resp UpdateOrgPreferencesResponse
data, err := json.Marshal(p)
if err != nil {
return resp, err
}
err = c.request("PUT", "/api/org/preferences", nil, data, &resp)
if err != nil {
return resp, err
}
return resp, err
}