-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathparental.go
60 lines (49 loc) · 1.15 KB
/
parental.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
package adguard
import (
"encoding/json"
"fmt"
"net/http"
"strings"
)
// GetParentalStatus - Returns whether parental control is enabled or not
func (c *ADG) GetParentalStatus() (*bool, error) {
// initialize request
req, err := http.NewRequest("GET", fmt.Sprintf("%s/parental/status", c.HostURL), nil)
if err != nil {
return nil, err
}
// perform request
body, err := c.doRequest(req)
if err != nil {
return nil, err
}
// convert response to an Enabled object
var enabled Enabled
err = json.Unmarshal(body, &enabled)
if err != nil {
return nil, err
}
return &enabled.Enabled, nil
}
// SetParentalStatus - Enable or disable parental controls
func (c *ADG) SetParentalStatus(status bool) error {
// define which endpoint we need to use based on the action
endpoint := "disable"
if status {
endpoint = "enable"
}
// initialize request
req, err := http.NewRequest("POST", fmt.Sprintf("%s/parental/%s", c.HostURL, endpoint), strings.NewReader(string([]byte(`{}`))))
if err != nil {
return err
}
// perform request
body, err := c.doRequest(req)
if err != nil {
return err
}
// appease Go
_ = body
// return nothing
return nil
}