gonextcloud/apps.go

75 lines
1.9 KiB
Go
Raw Normal View History

package gonextcloud
import (
req "github.com/levigross/grequests"
"github.com/partitio/gonextcloud/types"
"net/http"
)
2018-07-30 08:03:38 +00:00
//AppList return the list of the Nextcloud Apps
func (c *Client) AppList() ([]string, error) {
res, err := c.baseRequest(routes.apps, "", "", nil, http.MethodGet)
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
func (c *Client) AppListEnabled() ([]string, error) {
ro := &req.RequestOptions{
Params: map[string]string{"filter": "enabled"},
}
res, err := c.baseRequest(routes.apps, "", "", ro, http.MethodGet)
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
func (c *Client) AppListDisabled() ([]string, error) {
ro := &req.RequestOptions{
Params: map[string]string{"filter": "disabled"},
}
res, err := c.baseRequest(routes.apps, "", "", ro, http.MethodGet)
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
func (c *Client) AppInfos(name string) (types.App, error) {
res, err := c.baseRequest(routes.apps, name, "", nil, http.MethodGet)
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
func (c *Client) AppEnable(name string) error {
2018-07-30 08:03:38 +00:00
_, err := c.baseRequest(routes.apps, name, "", nil, http.MethodPut)
return err
}
2018-07-30 08:03:38 +00:00
//AppDisable disables an app
func (c *Client) AppDisable(name string) error {
2018-07-30 08:03:38 +00:00
_, err := c.baseRequest(routes.apps, name, "", nil, http.MethodDelete)
return err
}
func (c *Client) appsBaseRequest(name string, route string, ro *req.RequestOptions, method string) error {
_, err := c.baseRequest(routes.apps, name, route, ro, method)
return err
}