2018-07-25 13:06:31 +00:00
|
|
|
package gonextcloud
|
|
|
|
|
|
|
|
import (
|
|
|
|
req "github.com/levigross/grequests"
|
2018-10-26 13:35:50 +00:00
|
|
|
"gitlab.bertha.cloud/partitio/Nextcloud-Partitio/gonextcloud/types"
|
2018-07-25 13:06:31 +00:00
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2018-10-21 12:53:12 +00:00
|
|
|
//AppsI available methods
|
|
|
|
type AppsI interface {
|
|
|
|
List() ([]string, error)
|
|
|
|
ListEnabled() ([]string, error)
|
|
|
|
ListDisabled() ([]string, error)
|
|
|
|
Infos(name string) (types.App, error)
|
|
|
|
Enable(name string) error
|
|
|
|
Disable(name string) error
|
|
|
|
}
|
|
|
|
|
|
|
|
//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)
|
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-10-21 12:53:12 +00:00
|
|
|
//ListEnabled lists the enabled apps
|
|
|
|
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
|
|
|
|
}
|
|
|
|
var r types.AppListResponse
|
|
|
|
res.JSON(&r)
|
|
|
|
return r.Ocs.Data.Apps, nil
|
|
|
|
}
|
|
|
|
|
2018-10-21 12:53:12 +00:00
|
|
|
//ListDisabled lists the disabled apps
|
|
|
|
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
|
|
|
|
}
|
|
|
|
var r types.AppListResponse
|
|
|
|
res.JSON(&r)
|
|
|
|
return r.Ocs.Data.Apps, nil
|
|
|
|
}
|
|
|
|
|
2018-10-21 12:53:12 +00:00
|
|
|
//Infos return the app's details
|
|
|
|
func (a *Apps) Infos(name string) (types.App, error) {
|
|
|
|
res, err := a.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-10-21 12:53:12 +00:00
|
|
|
//Enable enables an app
|
|
|
|
func (a *Apps) Enable(name string) error {
|
|
|
|
_, 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
|
|
|
|
func (a *Apps) Disable(name string) error {
|
|
|
|
_, err := a.c.baseRequest(http.MethodDelete, routes.apps, nil, name)
|
2018-07-25 13:06:31 +00:00
|
|
|
return err
|
|
|
|
}
|