Added Group Search, Improved documentation

This commit is contained in:
Philippe-Adrien Nousse 2018-07-09 13:36:07 +02:00
parent b1fadec550
commit 8230c87476
5 changed files with 465 additions and 69 deletions

245
README.md
View File

@ -23,18 +23,22 @@ A simple Client for Nextcloud's API in Go.
- ~~demote subadmin~~ - ~~demote subadmin~~
- ~~send welcome mail~~ - ~~send welcome mail~~
- [Groups](#groups) - [Groups](#groups)
- create - ~~create~~
- delete - ~~delete~~
- get members - ~~get members~~
- get subadmins - ~~get subadmins~~
- [Apps](#apps) - [Apps](#apps)
- list - list
- get infos - get infos
- enable - enable
- disable - disable
# Getting started # client
## Authentication --
import "github.com/partitio/gonextcloud/client"
## Usage
```go ```go
package main package main
@ -56,86 +60,191 @@ func main() {
} }
defer c.Logout() defer c.Logout()
} }
```` ```
#### func NewClient
```go
func NewClient(hostname string) (*Client, error)
```
## Authentication
#### func (*Client) Login
```go
func (c *Client) Login(username string, password string) error
```
#### func (*Client) Logout
```go
func (c *Client) Logout() error
```
## Users ## Users
List : #### func (*Client) User
```go
func (c *Client) UserList() ([]string, error)
```
Search
```go
func (c *Client) UserSearch(search string) ([]string, error)
```
Get
```go ```go
func (c *Client) User(name string) (*types.User, error) func (c *Client) User(name string) (*types.User, error)
``` ```
Create
#### func (*Client) UserCreate
```go ```go
func (c *Client) UserCreate(username string, password string) error func (c *Client) UserCreate(username string, password string) error
``` ```
Delete
#### func (*Client) UserDelete
```go ```go
func (c *Client) UserDelete(name string) error func (c *Client) UserDelete(name string) error
``` ```
Enable
#### func (*Client) UserDisable
```go ```go
func (c *Client) UserEnable(name string) error func (c *Client) UserDisable(name string) error
``` ```
Disable
#### func (*Client) UserEnable
```go ```go
func (c *Client) UserDisable(name string) error func (c *Client) UserEnable(name string) error
``` ```
Update
#### func (*Client) UserGroupAdd
```go ```go
func (c *Client) UserUpdateEmail(name string, email string) error func (c *Client) UserGroupAdd(name string, group string) error
``` ```
#### func (*Client) UserGroupDemote
```go ```go
func (c *Client) UserUpdateDisplayName(name string, displayName string) error func (c *Client) UserGroupDemote(name string, group string) error
``` ```
```go
func (c *Client) UserUpdatePhone(name string, phone string) error #### func (*Client) UserGroupList
```
```go
func (c *Client) UserUpdateAddress(name string, address string) error
```
```go
func (c *Client) UserUpdateWebSite(name string, website string) error
```
```go
func (c *Client) UserUpdateTwitter(name string, twitter string) error
```
```go
func (c *Client) UserUpdatePassword(name string, password string) error
```
```go
func (c *Client) UserUpdateQuota(name string, quota string) error
```
Groups
```go ```go
func (c *Client) UserGroupList(name string) ([]string, error) func (c *Client) UserGroupList(name string) ([]string, error)
``` ```
```go
func (c *Client) UserGroupAdd(name string, group string) error
```
```go
func (c *Client) UserGroupRemove(name string, group string) error
```
```go
func (c *Client) UserGroupPromote(name string, group string) error
```
```go
func (c *Client) UserGroupDemote(name string, group string) error
```
```go
func (c *Client) UserGroupSubAdminList(name string) ([]string, error)
```
Welcome Mail
```go
func (c *Client) UserSendWelcomeEmail(name string) error
```
## Groups
TODO
## Apps #### func (*Client) UserGroupPromote
TODO
```go
func (c *Client) UserGroupPromote(name string, group string) error
```
#### func (*Client) UserGroupRemove
```go
func (c *Client) UserGroupRemove(name string, group string) error
```
#### func (*Client) UserGroupSubAdminList
```go
func (c *Client) UserGroupSubAdminList(name string) ([]string, error)
```
#### func (*Client) UserList
```go
func (c *Client) UserList() ([]string, error)
```
#### func (*Client) UserSearch
```go
func (c *Client) UserSearch(search string) ([]string, error)
```
#### func (*Client) UserSendWelcomeEmail
```go
func (c *Client) UserSendWelcomeEmail(name string) error
```
#### func (*Client) UserUpdateAddress
```go
func (c *Client) UserUpdateAddress(name string, address string) error
```
#### func (*Client) UserUpdateDisplayName
```go
func (c *Client) UserUpdateDisplayName(name string, displayName string) error
```
#### func (*Client) UserUpdateEmail
```go
func (c *Client) UserUpdateEmail(name string, email string) error
```
#### func (*Client) UserUpdatePassword
```go
func (c *Client) UserUpdatePassword(name string, password string) error
```
#### func (*Client) UserUpdatePhone
```go
func (c *Client) UserUpdatePhone(name string, phone string) error
```
#### func (*Client) UserUpdateQuota
```go
func (c *Client) UserUpdateQuota(name string, quota string) error
```
#### func (*Client) UserUpdateTwitter
```go
func (c *Client) UserUpdateTwitter(name string, twitter string) error
```
#### func (*Client) UserUpdateWebSite
## Groups
```go
func (c *Client) UserUpdateWebSite(name string, website string) error
```
#### func (*Client) GroupCreate
```go
func (c *Client) GroupCreate(name string) error
```
#### func (*Client) GroupDelete
```go
func (c *Client) GroupDelete(name string) error
```
#### func (*Client) GroupList
```go
func (c *Client) GroupList() ([]string, error)
```
#### func (*Client) GroupSearch
```go
func (c *Client) GroupSearch(search string) ([]string, error)
```
#### func (*Client) GroupSubAdminList
```go
func (c *Client) GroupSubAdminList(name string) ([]string, error)
```
#### func (*Client) GroupUsers
```go
func (c *Client) GroupUsers(name string) ([]string, error)
```

View File

@ -16,6 +16,7 @@ func (c *Client) Login(username string, password string) error {
Auth: []string{c.username, c.password}, Auth: []string{c.username, c.password},
} }
c.session = req.NewSession(&options) c.session = req.NewSession(&options)
// TODO What to do with capabilities ? (other thant connection validation)
u := c.baseURL.ResolveReference(routes.capabilities) u := c.baseURL.ResolveReference(routes.capabilities)
r, err := c.session.Get(u.String(), nil) r, err := c.session.Get(u.String(), nil)
if err != nil { if err != nil {

View File

@ -1,3 +1,43 @@
/*
Package client is a Go client for the Nextcloud Provisioning API.
For more information about the Provisioning API, see the documentation:
https://docs.nextcloud.com/server/13/admin_manual/configuration_user/user_provisioning_api.html
Usage
You use the library by creating a client object and calling methods on it.
For example, to list all the Nextcloud's instance users:
package main
import (
"fmt"
"github.com/partitio/gonextcloud/client"
)
func main() {
url := "https://www.mynextcloud.com"
username := "admin"
password := "password"
c, err := client.NewClient(url)
if err != nil {
panic(err)
}
if err := c.Login(username, password); err != nil {
panic(err)
}
defer c.Logout()
users, err := c.UserList()
if err != nil {
panic(err)
}
fmt.Println("Users :", users)
}
*/
package client package client
import ( import (

View File

@ -20,7 +20,7 @@ func (c *Client) GroupList() ([]string, error) {
return gr.Ocs.Data.Groups, nil return gr.Ocs.Data.Groups, nil
} }
func (c *Client) Group(name string) ([]string, error) { func (c *Client) GroupUsers(name string) ([]string, error) {
res, err := c.baseRequest(routes.groups, name, "", nil, http.MethodGet) res, err := c.baseRequest(routes.groups, name, "", nil, http.MethodGet)
if err != nil { if err != nil {
return nil, err return nil, err
@ -33,6 +33,22 @@ func (c *Client) Group(name string) ([]string, error) {
return r.Ocs.Data.Users, nil return r.Ocs.Data.Users, nil
} }
func (c *Client) GroupSearch(search string) ([]string, error) {
ro := &req.RequestOptions{
Params: map[string]string{"search": search},
}
res, err := c.baseRequest(routes.groups, "", "", ro, http.MethodGet)
if err != nil {
return nil, err
}
var r types.GroupListResponse
res.JSON(&r)
if r.Ocs.Meta.Statuscode != 100 {
return nil, fmt.Errorf("%d : %s", r.Ocs.Meta.Statuscode, r.Ocs.Meta.Message)
}
return r.Ocs.Data.Groups, nil
}
func (c *Client) GroupCreate(name string) error { func (c *Client) GroupCreate(name string) error {
ro := &req.RequestOptions{ ro := &req.RequestOptions{
Data: map[string]string{ Data: map[string]string{

230
docs/README.md Normal file
View File

@ -0,0 +1,230 @@
# client
--
import "github.com/partitio/gonextcloud/client"
## Usage
```go
package main
import (
"fmt"
"github.com/partitio/gonextcloud/client"
)
func main() {
url := "https://www.mynextcloud.com"
username := "admin"
password := "password"
c, err := client.NewClient(url)
if err != nil {
panic(err)
}
if err := c.Login(username, password); err != nil {
panic(err)
}
defer c.Logout()
}
```
#### type Client
```go
type Client struct {
}
```
#### func NewClient
```go
func NewClient(hostname string) (*Client, error)
```
#### func (*Client) GroupCreate
```go
func (c *Client) GroupCreate(name string) error
```
#### func (*Client) GroupDelete
```go
func (c *Client) GroupDelete(name string) error
```
#### func (*Client) GroupList
```go
func (c *Client) GroupList() ([]string, error)
```
#### func (*Client) GroupSearch
```go
func (c *Client) GroupSearch(search string) ([]string, error)
```
#### func (*Client) GroupSubAdminList
```go
func (c *Client) GroupSubAdminList(name string) ([]string, error)
```
#### func (*Client) GroupUsers
```go
func (c *Client) GroupUsers(name string) ([]string, error)
```
#### func (*Client) Login
```go
func (c *Client) Login(username string, password string) error
```
#### func (*Client) Logout
```go
func (c *Client) Logout() error
```
#### func (*Client) User
```go
func (c *Client) User(name string) (*types.User, error)
```
#### func (*Client) UserCreate
```go
func (c *Client) UserCreate(username string, password string) error
```
#### func (*Client) UserDelete
```go
func (c *Client) UserDelete(name string) error
```
#### func (*Client) UserDisable
```go
func (c *Client) UserDisable(name string) error
```
#### func (*Client) UserEnable
```go
func (c *Client) UserEnable(name string) error
```
#### func (*Client) UserGroupAdd
```go
func (c *Client) UserGroupAdd(name string, group string) error
```
#### func (*Client) UserGroupDemote
```go
func (c *Client) UserGroupDemote(name string, group string) error
```
#### func (*Client) UserGroupList
```go
func (c *Client) UserGroupList(name string) ([]string, error)
```
#### func (*Client) UserGroupPromote
```go
func (c *Client) UserGroupPromote(name string, group string) error
```
#### func (*Client) UserGroupRemove
```go
func (c *Client) UserGroupRemove(name string, group string) error
```
#### func (*Client) UserGroupSubAdminList
```go
func (c *Client) UserGroupSubAdminList(name string) ([]string, error)
```
#### func (*Client) UserList
```go
func (c *Client) UserList() ([]string, error)
```
#### func (*Client) UserSearch
```go
func (c *Client) UserSearch(search string) ([]string, error)
```
#### func (*Client) UserSendWelcomeEmail
```go
func (c *Client) UserSendWelcomeEmail(name string) error
```
#### func (*Client) UserUpdateAddress
```go
func (c *Client) UserUpdateAddress(name string, address string) error
```
#### func (*Client) UserUpdateDisplayName
```go
func (c *Client) UserUpdateDisplayName(name string, displayName string) error
```
#### func (*Client) UserUpdateEmail
```go
func (c *Client) UserUpdateEmail(name string, email string) error
```
#### func (*Client) UserUpdatePassword
```go
func (c *Client) UserUpdatePassword(name string, password string) error
```
#### func (*Client) UserUpdatePhone
```go
func (c *Client) UserUpdatePhone(name string, phone string) error
```
#### func (*Client) UserUpdateQuota
```go
func (c *Client) UserUpdateQuota(name string, quota string) error
```
#### func (*Client) UserUpdateTwitter
```go
func (c *Client) UserUpdateTwitter(name string, twitter string) error
```
#### func (*Client) UserUpdateWebSite
```go
func (c *Client) UserUpdateWebSite(name string, website string) error
```
#### type Routes
```go
type Routes struct {
}
```