diff --git a/apps.go b/apps.go index 8c7f080..96393d8 100644 --- a/apps.go +++ b/apps.go @@ -6,6 +6,7 @@ import ( "net/http" ) +//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 { @@ -16,6 +17,7 @@ func (c *Client) AppList() ([]string, error) { return r.Ocs.Data.Apps, nil } +//AppListEnabled lists the enabled apps func (c *Client) AppListEnabled() ([]string, error) { ro := &req.RequestOptions{ Params: map[string]string{"filter": "enabled"}, @@ -29,6 +31,7 @@ func (c *Client) AppListEnabled() ([]string, error) { return r.Ocs.Data.Apps, nil } +//AppListDisabled lists the disabled apps func (c *Client) AppListDisabled() ([]string, error) { ro := &req.RequestOptions{ Params: map[string]string{"filter": "disabled"}, @@ -42,6 +45,7 @@ func (c *Client) AppListDisabled() ([]string, error) { return r.Ocs.Data.Apps, nil } +//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 { @@ -52,24 +56,16 @@ func (c *Client) AppInfos(name string) (types.App, error) { return r.Ocs.Data, nil } +//AppEnable enables an app func (c *Client) AppEnable(name string) error { - res, err := c.baseRequest(routes.apps, name, "", nil, http.MethodPut) - if err != nil { - return err - } - var r types.BaseResponse - res.JSON(&r) - return nil + _, err := c.baseRequest(routes.apps, name, "", nil, http.MethodPut) + return err } +//AppDisable disables an app func (c *Client) AppDisable(name string) error { - res, err := c.baseRequest(routes.apps, name, "", nil, http.MethodDelete) - if err != nil { - return err - } - var r types.BaseResponse - res.JSON(&r) - return nil + _, 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 { diff --git a/auth.go b/auth.go index bd6e782..07b3d5d 100644 --- a/auth.go +++ b/auth.go @@ -8,6 +8,7 @@ import ( var unauthorized = fmt.Errorf("login first") +// Login perform login and create a session with the Nextcloud API. func (c *Client) Login(username string, password string) error { c.username = username c.password = password @@ -34,6 +35,7 @@ func (c *Client) Login(username string, password string) error { return nil } +// Logout logs out from the Nextcloud API, close the session and delete session's cookie func (c *Client) Logout() error { c.session.CloseIdleConnections() c.session.HTTPClient.Jar = nil diff --git a/client.go b/client.go index 60ae36b..a4a8373 100644 --- a/client.go +++ b/client.go @@ -46,6 +46,7 @@ import ( "net/url" ) +// Client is the API client that performs all operations against a Nextcloud server. type Client struct { baseURL *url.URL username string @@ -55,6 +56,7 @@ type Client struct { capabilities *types.Capabilities } +// NewClient create a new Client from the Nextcloud Instance URL func NewClient(hostname string) (*Client, error) { baseURL, err := url.ParseRequestURI(hostname) if err != nil { diff --git a/gonextcloud_test.go b/gonextcloud_test.go index 3b1a9f2..156149c 100644 --- a/gonextcloud_test.go +++ b/gonextcloud_test.go @@ -29,6 +29,7 @@ type Config struct { NotExistingGroup string `yaml:"not-existing-group"` } +// LoadConfig loads the test configuration func LoadConfig() error { f, err := os.Open("./config.yml") if err != nil { @@ -38,10 +39,7 @@ func LoadConfig() error { if err != nil { return err } - if err := yaml.Unmarshal(b, &config); err != nil { - return err - } - return nil + return yaml.Unmarshal(b, &config) } func TestLoadConfig(t *testing.T) { diff --git a/groups.go b/groups.go index 67aacb8..53b1a00 100644 --- a/groups.go +++ b/groups.go @@ -6,6 +6,7 @@ import ( "net/http" ) +//GroupList lists the Nextcloud groups func (c *Client) GroupList() ([]string, error) { res, err := c.baseRequest(routes.groups, "", "", nil, http.MethodGet) if err != nil { @@ -16,6 +17,7 @@ func (c *Client) GroupList() ([]string, error) { return r.Ocs.Data.Groups, nil } +//GroupUsers list the group's users func (c *Client) GroupUsers(name string) ([]string, error) { res, err := c.baseRequest(routes.groups, name, "", nil, http.MethodGet) if err != nil { @@ -26,6 +28,7 @@ func (c *Client) GroupUsers(name string) ([]string, error) { return r.Ocs.Data.Users, nil } +//GroupSearch return the list of groups matching the search string func (c *Client) GroupSearch(search string) ([]string, error) { ro := &req.RequestOptions{ Params: map[string]string{"search": search}, @@ -39,6 +42,7 @@ func (c *Client) GroupSearch(search string) ([]string, error) { return r.Ocs.Data.Groups, nil } +//GroupCreate creates a group func (c *Client) GroupCreate(name string) error { ro := &req.RequestOptions{ Data: map[string]string{ @@ -51,6 +55,7 @@ func (c *Client) GroupCreate(name string) error { return nil } +//GroupDelete deletes the group func (c *Client) GroupDelete(name string) error { if err := c.groupBaseRequest(name, "", nil, http.MethodDelete); err != nil { return err @@ -58,6 +63,7 @@ func (c *Client) GroupDelete(name string) error { return nil } +//GroupSubAdminList lists the group's subadmins func (c *Client) GroupSubAdminList(name string) ([]string, error) { res, err := c.baseRequest(routes.groups, name, "subadmins", nil, http.MethodGet) if err != nil { diff --git a/routes.go b/routes.go index 1841110..9e26741 100644 --- a/routes.go +++ b/routes.go @@ -2,6 +2,7 @@ package gonextcloud import "net/url" +// Route references the available routes type Routes struct { capabilities *url.URL users *url.URL diff --git a/users.go b/users.go index b4e3cb3..9659adf 100644 --- a/users.go +++ b/users.go @@ -12,6 +12,7 @@ import ( "sync" ) +// UserList return the Nextcloud'user list func (c *Client) UserList() ([]string, error) { res, err := c.baseRequest(routes.users, "", "", nil, http.MethodGet) //res, err := c.session.Get(u.String(), nil) @@ -23,6 +24,7 @@ func (c *Client) UserList() ([]string, error) { return r.Ocs.Data.Users, nil } +// User return the details about the specified user func (c *Client) User(name string) (*types.User, error) { if name == "" { return nil, &types.APIError{Message: "name cannot be empty"} @@ -41,6 +43,7 @@ func (c *Client) User(name string) (*types.User, error) { return &r.Ocs.Data, nil } +// UserSearch returns the users whose name match the search string func (c *Client) UserSearch(search string) ([]string, error) { ro := &req.RequestOptions{ Params: map[string]string{"search": search}, @@ -54,6 +57,7 @@ func (c *Client) UserSearch(search string) ([]string, error) { return r.Ocs.Data.Users, nil } +// UserCreate create a new user func (c *Client) UserCreate(username string, password string, user *types.User) error { ro := &req.RequestOptions{ Data: map[string]string{ @@ -70,10 +74,12 @@ func (c *Client) UserCreate(username string, password string, user *types.User) return c.UserUpdate(user) } +//UserDelete delete the user func (c *Client) UserDelete(name string) error { return c.userBaseRequest(name, "", nil, http.MethodDelete) } +//UserEnable enables the user func (c *Client) UserEnable(name string) error { ro := &req.RequestOptions{ Data: map[string]string{}, @@ -81,6 +87,7 @@ func (c *Client) UserEnable(name string) error { return c.userBaseRequest(name, "enable", ro, http.MethodPut) } +//UserDisable disables the user func (c *Client) UserDisable(name string) error { ro := &req.RequestOptions{ Data: map[string]string{}, @@ -88,10 +95,12 @@ func (c *Client) UserDisable(name string) error { return c.userBaseRequest(name, "disable", ro, http.MethodPut) } +//UserSendWelcomeEmail (re)send the welcome mail to the user (return an error if the user has not configured his email) func (c *Client) UserSendWelcomeEmail(name string) error { return c.userBaseRequest(name, "welcome", nil, http.MethodPost) } +//UserUpdate takes a *types.User struct to update the user's information func (c *Client) UserUpdate(user *types.User) error { m := structs.Map(user) errs := make(chan types.UpdateError) @@ -117,38 +126,47 @@ func (c *Client) UserUpdate(user *types.User) error { return types.NewUpdateError(errs) } +//UserUpdateEmail update the user's email func (c *Client) UserUpdateEmail(name string, email string) error { return c.userUpdateAttribute(name, "email", email) } +//UserUpdateDisplayName update the user's display name func (c *Client) UserUpdateDisplayName(name string, displayName string) error { return c.userUpdateAttribute(name, "displayname", displayName) } +//UserUpdatePhone update the user's phone func (c *Client) UserUpdatePhone(name string, phone string) error { return c.userUpdateAttribute(name, "phone", phone) } +//UserUpdateAddress update the user's address func (c *Client) UserUpdateAddress(name string, address string) error { return c.userUpdateAttribute(name, "address", address) } +//UserUpdateWebSite update the user's website func (c *Client) UserUpdateWebSite(name string, website string) error { return c.userUpdateAttribute(name, "website", website) } +//UserUpdateTwitter update the user's twitter func (c *Client) UserUpdateTwitter(name string, twitter string) error { return c.userUpdateAttribute(name, "twitter", twitter) } +//UserUpdatePassword update the user's password func (c *Client) UserUpdatePassword(name string, password string) error { return c.userUpdateAttribute(name, "password", password) } +//UserUpdateQuota update the user's quota (bytes) func (c *Client) UserUpdateQuota(name string, quota int) error { return c.userUpdateAttribute(name, "quota", strconv.Itoa(quota)) } +//UserGroupList lists the user's groups func (c *Client) UserGroupList(name string) ([]string, error) { res, err := c.baseRequest(routes.users, name, "groups", nil, http.MethodGet) if err != nil { @@ -159,6 +177,7 @@ func (c *Client) UserGroupList(name string) ([]string, error) { return r.Ocs.Data.Groups, nil } +//UserGroupAdd adds a the user to the group func (c *Client) UserGroupAdd(name string, group string) error { ro := &req.RequestOptions{ Data: map[string]string{ @@ -168,6 +187,7 @@ func (c *Client) UserGroupAdd(name string, group string) error { return c.userBaseRequest(name, "groups", ro, http.MethodPost) } +//UserGroupRemove removes the user from the group func (c *Client) UserGroupRemove(name string, group string) error { ro := &req.RequestOptions{ Data: map[string]string{ @@ -177,6 +197,7 @@ func (c *Client) UserGroupRemove(name string, group string) error { return c.userBaseRequest(name, "groups", ro, http.MethodDelete) } +//UserGroupPromote promotes the user as group admin func (c *Client) UserGroupPromote(name string, group string) error { ro := &req.RequestOptions{ Data: map[string]string{ @@ -186,6 +207,7 @@ func (c *Client) UserGroupPromote(name string, group string) error { return c.userBaseRequest(name, "subadmins", ro, http.MethodPost) } +//UserGroupDemote demotes the user func (c *Client) UserGroupDemote(name string, group string) error { ro := &req.RequestOptions{ Data: map[string]string{ @@ -195,6 +217,7 @@ func (c *Client) UserGroupDemote(name string, group string) error { return c.userBaseRequest(name, "subadmins", ro, http.MethodDelete) } +//UserGroupSubAdminList lists the groups where he is subadmin func (c *Client) UserGroupSubAdminList(name string) ([]string, error) { if !c.loggedIn() { return nil, unauthorized