-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathapps_impl.go
74 lines (65 loc) · 1.61 KB
/
apps_impl.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
package gonextcloud
import (
"net/http"
req "github.com/levigross/grequests"
)
//apps contains all apps available actions
type apps struct {
c *client
}
//List return the list of the Nextcloud apps
func (a *apps) List() ([]string, error) {
res, err := a.c.baseRequest(http.MethodGet, routes.apps, nil)
if err != nil {
return nil, err
}
var r appListResponse
res.JSON(&r)
return r.Ocs.Data.Apps, nil
}
//ListEnabled lists the enabled apps
func (a *apps) ListEnabled() ([]string, error) {
ro := &req.RequestOptions{
Params: map[string]string{"filter": "enabled"},
}
res, err := a.c.baseRequest(http.MethodGet, routes.apps, ro)
if err != nil {
return nil, err
}
var r appListResponse
res.JSON(&r)
return r.Ocs.Data.Apps, nil
}
//ListDisabled lists the disabled apps
func (a *apps) ListDisabled() ([]string, error) {
ro := &req.RequestOptions{
Params: map[string]string{"filter": "disabled"},
}
res, err := a.c.baseRequest(http.MethodGet, routes.apps, ro)
if err != nil {
return nil, err
}
var r appListResponse
res.JSON(&r)
return r.Ocs.Data.Apps, nil
}
//Infos return the app's details
func (a *apps) Infos(name string) (App, error) {
res, err := a.c.baseRequest(http.MethodGet, routes.apps, nil, name)
if err != nil {
return App{}, err
}
var r appResponse
res.JSON(&r)
return r.Ocs.Data, nil
}
//Enable enables an app
func (a *apps) Enable(name string) error {
_, err := a.c.baseRequest(http.MethodPost, routes.apps, nil, name)
return err
}
//Disable disables an app
func (a *apps) Disable(name string) error {
_, err := a.c.baseRequest(http.MethodDelete, routes.apps, nil, name)
return err
}