2018-07-25 13:06:31 +00:00
|
|
|
package gonextcloud
|
|
|
|
|
|
|
|
import (
|
|
|
|
req "github.com/levigross/grequests"
|
2018-10-08 16:50:11 +00:00
|
|
|
"gitlab.adphi.fr/partitio/Nextcloud-Partitio/gonextcloud/types"
|
2018-07-25 13:06:31 +00:00
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2018-07-30 08:03:38 +00:00
|
|
|
//AppList return the list of the Nextcloud Apps
|
2018-07-25 13:06:31 +00:00
|
|
|
func (c *Client) AppList() ([]string, error) {
|
2018-09-03 10:17:02 +00:00
|
|
|
res, err := c.baseRequest(http.MethodGet, routes.apps, nil)
|
2018-07-25 13:06:31 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var r types.AppListResponse
|
|
|
|
res.JSON(&r)
|
|
|
|
return r.Ocs.Data.Apps, nil
|
|
|
|
}
|
|
|
|
|
2018-07-30 08:03:38 +00:00
|
|
|
//AppListEnabled lists the enabled apps
|
2018-07-25 13:06:31 +00:00
|
|
|
func (c *Client) AppListEnabled() ([]string, error) {
|
|
|
|
ro := &req.RequestOptions{
|
|
|
|
Params: map[string]string{"filter": "enabled"},
|
|
|
|
}
|
2018-09-03 10:17:02 +00:00
|
|
|
res, err := c.baseRequest(http.MethodGet, routes.apps, ro)
|
2018-07-25 13:06:31 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var r types.AppListResponse
|
|
|
|
res.JSON(&r)
|
|
|
|
return r.Ocs.Data.Apps, nil
|
|
|
|
}
|
|
|
|
|
2018-07-30 08:03:38 +00:00
|
|
|
//AppListDisabled lists the disabled apps
|
2018-07-25 13:06:31 +00:00
|
|
|
func (c *Client) AppListDisabled() ([]string, error) {
|
|
|
|
ro := &req.RequestOptions{
|
|
|
|
Params: map[string]string{"filter": "disabled"},
|
|
|
|
}
|
2018-09-03 10:17:02 +00:00
|
|
|
res, err := c.baseRequest(http.MethodGet, routes.apps, ro)
|
2018-07-25 13:06:31 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var r types.AppListResponse
|
|
|
|
res.JSON(&r)
|
|
|
|
return r.Ocs.Data.Apps, nil
|
|
|
|
}
|
|
|
|
|
2018-07-30 08:03:38 +00:00
|
|
|
//AppInfos return the app's details
|
2018-07-25 13:06:31 +00:00
|
|
|
func (c *Client) AppInfos(name string) (types.App, error) {
|
2018-09-03 10:17:02 +00:00
|
|
|
res, err := c.baseRequest(http.MethodGet, routes.apps, nil, name)
|
2018-07-25 13:06:31 +00:00
|
|
|
if err != nil {
|
|
|
|
return types.App{}, err
|
|
|
|
}
|
|
|
|
var r types.AppResponse
|
|
|
|
res.JSON(&r)
|
|
|
|
return r.Ocs.Data, nil
|
|
|
|
}
|
|
|
|
|
2018-07-30 08:03:38 +00:00
|
|
|
//AppEnable enables an app
|
2018-07-25 13:06:31 +00:00
|
|
|
func (c *Client) AppEnable(name string) error {
|
2018-09-03 10:17:02 +00:00
|
|
|
_, err := c.baseRequest(http.MethodPut, routes.apps, nil, name)
|
2018-07-30 08:03:38 +00:00
|
|
|
return err
|
2018-07-25 13:06:31 +00:00
|
|
|
}
|
|
|
|
|
2018-07-30 08:03:38 +00:00
|
|
|
//AppDisable disables an app
|
2018-07-25 13:06:31 +00:00
|
|
|
func (c *Client) AppDisable(name string) error {
|
2018-09-03 10:17:02 +00:00
|
|
|
_, err := c.baseRequest(http.MethodDelete, routes.apps, nil, name)
|
2018-07-25 13:06:31 +00:00
|
|
|
return err
|
|
|
|
}
|