2018-07-25 13:06:31 +00:00
|
|
|
package gonextcloud
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2019-07-22 14:17:11 +00:00
|
|
|
|
|
|
|
req "github.com/levigross/grequests"
|
2018-07-25 13:06:31 +00:00
|
|
|
)
|
|
|
|
|
2019-07-22 14:17:11 +00:00
|
|
|
//apps contains all apps available actions
|
|
|
|
type apps struct {
|
|
|
|
c *client
|
2018-10-21 12:53:12 +00:00
|
|
|
}
|
|
|
|
|
2019-07-22 14:17:11 +00:00
|
|
|
//List return the list of the Nextcloud apps
|
|
|
|
func (a *apps) List() ([]string, error) {
|
2018-10-21 12:53:12 +00:00
|
|
|
res, err := a.c.baseRequest(http.MethodGet, routes.apps, nil)
|
2018-07-25 13:06:31 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-07-22 14:40:42 +00:00
|
|
|
var r appListResponse
|
2018-07-25 13:06:31 +00:00
|
|
|
res.JSON(&r)
|
|
|
|
return r.Ocs.Data.Apps, nil
|
|
|
|
}
|
|
|
|
|
2018-10-21 12:53:12 +00:00
|
|
|
//ListEnabled lists the enabled apps
|
2019-07-22 14:17:11 +00:00
|
|
|
func (a *apps) ListEnabled() ([]string, error) {
|
2018-07-25 13:06:31 +00:00
|
|
|
ro := &req.RequestOptions{
|
|
|
|
Params: map[string]string{"filter": "enabled"},
|
|
|
|
}
|
2018-10-21 12:53:12 +00:00
|
|
|
res, err := a.c.baseRequest(http.MethodGet, routes.apps, ro)
|
2018-07-25 13:06:31 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-07-22 14:40:42 +00:00
|
|
|
var r appListResponse
|
2018-07-25 13:06:31 +00:00
|
|
|
res.JSON(&r)
|
|
|
|
return r.Ocs.Data.Apps, nil
|
|
|
|
}
|
|
|
|
|
2018-10-21 12:53:12 +00:00
|
|
|
//ListDisabled lists the disabled apps
|
2019-07-22 14:17:11 +00:00
|
|
|
func (a *apps) ListDisabled() ([]string, error) {
|
2018-07-25 13:06:31 +00:00
|
|
|
ro := &req.RequestOptions{
|
|
|
|
Params: map[string]string{"filter": "disabled"},
|
|
|
|
}
|
2018-10-21 12:53:12 +00:00
|
|
|
res, err := a.c.baseRequest(http.MethodGet, routes.apps, ro)
|
2018-07-25 13:06:31 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-07-22 14:40:42 +00:00
|
|
|
var r appListResponse
|
2018-07-25 13:06:31 +00:00
|
|
|
res.JSON(&r)
|
|
|
|
return r.Ocs.Data.Apps, nil
|
|
|
|
}
|
|
|
|
|
2018-10-21 12:53:12 +00:00
|
|
|
//Infos return the app's details
|
2019-07-22 14:17:11 +00:00
|
|
|
func (a *apps) Infos(name string) (App, error) {
|
2018-10-21 12:53:12 +00:00
|
|
|
res, err := a.c.baseRequest(http.MethodGet, routes.apps, nil, name)
|
2018-07-25 13:06:31 +00:00
|
|
|
if err != nil {
|
2019-07-22 14:17:11 +00:00
|
|
|
return App{}, err
|
2018-07-25 13:06:31 +00:00
|
|
|
}
|
2019-07-22 14:40:42 +00:00
|
|
|
var r appResponse
|
2018-07-25 13:06:31 +00:00
|
|
|
res.JSON(&r)
|
|
|
|
return r.Ocs.Data, nil
|
|
|
|
}
|
|
|
|
|
2018-10-21 12:53:12 +00:00
|
|
|
//Enable enables an app
|
2019-07-22 14:17:11 +00:00
|
|
|
func (a *apps) Enable(name string) error {
|
2018-10-21 12:53:12 +00:00
|
|
|
_, err := a.c.baseRequest(http.MethodPost, routes.apps, nil, name)
|
2018-07-30 08:03:38 +00:00
|
|
|
return err
|
2018-07-25 13:06:31 +00:00
|
|
|
}
|
|
|
|
|
2018-10-21 12:53:12 +00:00
|
|
|
//Disable disables an app
|
2019-07-22 14:17:11 +00:00
|
|
|
func (a *apps) Disable(name string) error {
|
2018-10-21 12:53:12 +00:00
|
|
|
_, err := a.c.baseRequest(http.MethodDelete, routes.apps, nil, name)
|
2018-07-25 13:06:31 +00:00
|
|
|
return err
|
|
|
|
}
|