Added Group Search, Improved documentation

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

View File

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

View File

@ -20,7 +20,7 @@ func (c *Client) GroupList() ([]string, error) {
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)
if err != nil {
return nil, err
@ -33,6 +33,22 @@ func (c *Client) Group(name string) ([]string, error) {
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 {
ro := &req.RequestOptions{
Data: map[string]string{