updated README.md, unexported responses types

This commit is contained in:
Adphi 2019-07-22 16:40:42 +02:00
parent 85ab4b93f0
commit 5a9b0d715c
20 changed files with 747 additions and 2328 deletions

1226
README.md

File diff suppressed because it is too large Load Diff

View File

@ -17,7 +17,7 @@ func (a *apps) List() ([]string, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
var r AppListResponse var r appListResponse
res.JSON(&r) res.JSON(&r)
return r.Ocs.Data.Apps, nil return r.Ocs.Data.Apps, nil
} }
@ -31,7 +31,7 @@ func (a *apps) ListEnabled() ([]string, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
var r AppListResponse var r appListResponse
res.JSON(&r) res.JSON(&r)
return r.Ocs.Data.Apps, nil return r.Ocs.Data.Apps, nil
} }
@ -45,7 +45,7 @@ func (a *apps) ListDisabled() ([]string, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
var r AppListResponse var r appListResponse
res.JSON(&r) res.JSON(&r)
return r.Ocs.Data.Apps, nil return r.Ocs.Data.Apps, nil
} }
@ -56,7 +56,7 @@ func (a *apps) Infos(name string) (App, error) {
if err != nil { if err != nil {
return App{}, err return App{}, err
} }
var r AppResponse var r appResponse
res.JSON(&r) res.JSON(&r)
return r.Ocs.Data, nil return r.Ocs.Data, nil
} }

View File

@ -18,7 +18,7 @@ func (a *appsConfig) List() (apps []string, err error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
var r AppConfigResponse var r appConfigResponse
res.JSON(&r) res.JSON(&r)
return r.Ocs.Data.Data, nil return r.Ocs.Data.Data, nil
} }
@ -29,7 +29,7 @@ func (a *appsConfig) Keys(id string) (keys []string, err error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
var r AppConfigResponse var r appConfigResponse
res.JSON(&r) res.JSON(&r)
return r.Ocs.Data.Data, nil return r.Ocs.Data.Data, nil
} }
@ -40,7 +40,7 @@ func (a *appsConfig) Value(id, key string) (string, error) {
if err != nil { if err != nil {
return "", err return "", err
} }
var r AppcConfigValueResponse var r appcConfigValueResponse
res.JSON(&r) res.JSON(&r)
return r.Ocs.Data.Data, nil return r.Ocs.Data.Data, nil
} }

View File

@ -23,9 +23,9 @@ func (c *client) Login(username string, password string) error {
if err != nil { if err != nil {
return err return err
} }
var r CapabilitiesResponse var r capabilitiesResponse
res.JSON(&r) res.JSON(&r)
// No need to check for Ocs.Meta.StatusCode as capabilities are always returned // No need to check for Ocs.meta.StatusCode as capabilities are always returned
c.capabilities = &r.Ocs.Data.Capabilities c.capabilities = &r.Ocs.Data.Capabilities
c.version = &r.Ocs.Data.Version c.version = &r.Ocs.Data.Version
// Check if authentication failed // Check if authentication failed

2
doc.go
View File

@ -21,7 +21,7 @@ For example, to list all the Nextcloud's instance users:
url := "https://www.mynextcloud.com" url := "https://www.mynextcloud.com"
username := "admin" username := "admin"
password := "password" password := "password"
c, err := gonextcloud.newClient(url) c, err := gonextcloud.NewClient(url)
if err != nil { if err != nil {
panic(err) panic(err)
} }

File diff suppressed because it is too large Load Diff

View File

@ -11,8 +11,8 @@ type APIError struct {
Message string Message string
} }
//ErrorFromMeta return a types.APIError from the Response's types.Meta //errorFromMeta return a types.APIError from the Response's types.meta
func ErrorFromMeta(meta Meta) *APIError { func errorFromMeta(meta meta) *APIError {
return &APIError{ return &APIError{
meta.Statuscode, meta.Statuscode,
meta.Message, meta.Message,
@ -43,8 +43,8 @@ func (e *UserUpdateError) Error() string {
return strings.Join(errors, ", ") return strings.Join(errors, ", ")
} }
//NewUpdateError returns an UpdateError based on an UpdateError channel //newUpdateError returns an UpdateError based on an UpdateError channel
func NewUpdateError(errors chan *UpdateError) *UserUpdateError { func newUpdateError(errors chan *UpdateError) *UserUpdateError {
ue := UserUpdateError{map[string]error{}} ue := UserUpdateError{map[string]error{}}
for e := range errors { for e := range errors {
if e != nil { if e != nil {

View File

@ -25,7 +25,7 @@ func TestUserUpdateErrors(t *testing.T) {
} }
close(errs) close(errs)
}() }()
uerrs := NewUpdateError(errs) uerrs := newUpdateError(errs)
assert.Equal(t, exp, uerrs.Errors) assert.Equal(t, exp, uerrs.Errors)
assert.NotEmpty(t, uerrs.Error()) assert.NotEmpty(t, uerrs.Error())
} }
@ -42,6 +42,6 @@ func TestUserUpdateErrorsNil(t *testing.T) {
wg.Wait() wg.Wait()
close(errs) close(errs)
}() }()
uerrs := NewUpdateError(errs) uerrs := newUpdateError(errs)
assert.Nil(t, uerrs) assert.Nil(t, uerrs)
} }

View File

@ -1,5 +1,11 @@
package gonextcloud package gonextcloud
import (
"io"
"os"
"path/filepath"
)
// NewClient create a new client // NewClient create a new client
func NewClient(hostname string) (Client, error) { func NewClient(hostname string) (Client, error) {
return newClient(hostname) return newClient(hostname)
@ -130,3 +136,35 @@ type Users interface {
GroupDemote(name string, group string) error GroupDemote(name string, group string) error
GroupSubAdminList(name string) ([]string, error) GroupSubAdminList(name string) ([]string, error)
} }
// WebDav available methods
type WebDav interface {
// ReadDir reads the contents of a remote directory
ReadDir(path string) ([]os.FileInfo, error)
// Stat returns the file stats for a specified path
Stat(path string) (os.FileInfo, error)
// Remove removes a remote file
Remove(path string) error
// RemoveAll removes remote files
RemoveAll(path string) error
// Mkdir makes a directory
Mkdir(path string, _ os.FileMode) error
// MkdirAll like mkdir -p, but for webdav
MkdirAll(path string, _ os.FileMode) error
// Rename moves a file from A to B
Rename(oldpath, newpath string, overwrite bool) error
// Copy copies a file from A to B
Copy(oldpath, newpath string, overwrite bool) error
// Read reads the contents of a remote file
Read(path string) ([]byte, error)
// ReadStream reads the stream for a given path
ReadStream(path string) (io.ReadCloser, error)
// Write writes data to a given path
Write(path string, data []byte, _ os.FileMode) error
// WriteStream writes a stream
WriteStream(path string, stream io.Reader, _ os.FileMode) error
// Walk walks the file tree rooted at root, calling walkFn for each file or
// directory in the tree, including root.
Walk(path string, walkFunc filepath.WalkFunc) error
}

View File

@ -2,7 +2,7 @@ package gonextcloud
import "strconv" import "strconv"
type GroupFolderBadFormatIDAndGroups struct { type groupFolderBadFormatIDAndGroups struct {
ID string `json:"id"` ID string `json:"id"`
MountPoint string `json:"mount_point"` MountPoint string `json:"mount_point"`
Groups map[string]string `json:"groups"` Groups map[string]string `json:"groups"`
@ -10,7 +10,7 @@ type GroupFolderBadFormatIDAndGroups struct {
Size int `json:"size"` Size int `json:"size"`
} }
type GroupFolderBadFormatGroups struct { type groupFolderBadFormatGroups struct {
ID int `json:"id"` ID int `json:"id"`
MountPoint string `json:"mount_point"` MountPoint string `json:"mount_point"`
Groups map[string]string `json:"groups"` Groups map[string]string `json:"groups"`
@ -26,7 +26,7 @@ type GroupFolder struct {
Size int `json:"size"` Size int `json:"size"`
} }
func (gf *GroupFolderBadFormatGroups) FormatGroupFolder() GroupFolder { func (gf *groupFolderBadFormatGroups) FormatGroupFolder() GroupFolder {
g := GroupFolder{} g := GroupFolder{}
g.ID = gf.ID g.ID = gf.ID
g.MountPoint = gf.MountPoint g.MountPoint = gf.MountPoint
@ -41,7 +41,7 @@ func (gf *GroupFolderBadFormatGroups) FormatGroupFolder() GroupFolder {
return g return g
} }
func (gf *GroupFolderBadFormatIDAndGroups) FormatGroupFolder() GroupFolder { func (gf *groupFolderBadFormatIDAndGroups) FormatGroupFolder() GroupFolder {
g := GroupFolder{} g := GroupFolder{}
g.ID, _ = strconv.Atoi(gf.ID) g.ID, _ = strconv.Atoi(gf.ID)
g.MountPoint = gf.MountPoint g.MountPoint = gf.MountPoint

View File

@ -19,7 +19,7 @@ func (g *groupFolders) List() (map[int]GroupFolder, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
var r GroupFoldersListResponse var r groupFoldersListResponse
res.JSON(&r) res.JSON(&r)
gfs := formatBadIDAndGroups(r.Ocs.Data) gfs := formatBadIDAndGroups(r.Ocs.Data)
return gfs, nil return gfs, nil
@ -31,7 +31,7 @@ func (g *groupFolders) Get(id int) (GroupFolder, error) {
if err != nil { if err != nil {
return GroupFolder{}, err return GroupFolder{}, err
} }
var r GroupFoldersResponse var r groupFoldersResponse
res.JSON(&r) res.JSON(&r)
if r.Ocs.Data.ID == 0 { if r.Ocs.Data.ID == 0 {
return GroupFolder{}, fmt.Errorf("%d is not a valid groupfolder's id", id) return GroupFolder{}, fmt.Errorf("%d is not a valid groupfolder's id", id)
@ -51,7 +51,7 @@ func (g *groupFolders) Create(name string) (id int, err error) {
if err != nil { if err != nil {
return 0, err return 0, err
} }
var r GroupFoldersCreateResponse var r groupFoldersCreateResponse
res.JSON(&r) res.JSON(&r)
id, _ = strconv.Atoi(r.Ocs.Data.ID) id, _ = strconv.Atoi(r.Ocs.Data.ID)
return id, nil return id, nil
@ -129,7 +129,7 @@ func (g *groupFolders) SetQuota(folderID int, quota int) error {
return nil return nil
} }
func formatBadIDAndGroups(g map[string]GroupFolderBadFormatIDAndGroups) map[int]GroupFolder { func formatBadIDAndGroups(g map[string]groupFolderBadFormatIDAndGroups) map[int]GroupFolder {
var gfs = map[int]GroupFolder{} var gfs = map[int]GroupFolder{}
for k := range g { for k := range g {
i, _ := strconv.Atoi(k) i, _ := strconv.Atoi(k)

View File

@ -17,7 +17,7 @@ func (g *groups) List() ([]string, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
var r GroupListResponse var r groupListResponse
res.JSON(&r) res.JSON(&r)
return r.Ocs.Data.Groups, nil return r.Ocs.Data.Groups, nil
} }
@ -33,7 +33,7 @@ func (g *groups) ListDetails(search string) ([]Group, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
var r GroupListDetailsResponse var r groupListDetailsResponse
res.JSON(&r) res.JSON(&r)
return r.Ocs.Data.Groups, nil return r.Ocs.Data.Groups, nil
} }
@ -44,7 +44,7 @@ func (g *groups) Users(name string) ([]string, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
var r UserListResponse var r userListResponse
res.JSON(&r) res.JSON(&r)
return r.Ocs.Data.Users, nil return r.Ocs.Data.Users, nil
} }
@ -58,7 +58,7 @@ func (g *groups) Search(search string) ([]string, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
var r GroupListResponse var r groupListResponse
res.JSON(&r) res.JSON(&r)
return r.Ocs.Data.Groups, nil return r.Ocs.Data.Groups, nil
} }
@ -84,7 +84,7 @@ func (g *groups) SubAdminList(name string) ([]string, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
var r UserListResponse var r userListResponse
res.JSON(&r) res.JSON(&r)
return r.Ocs.Data.Users, nil return r.Ocs.Data.Users, nil
} }

View File

@ -10,7 +10,7 @@ func (c *client) Monitoring() (*Monitoring, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
var m MonitoringResponse var m monitoringResponse
res.JSON(&m) res.JSON(&m)
return &m.Ocs.Data, nil return &m.Ocs.Data, nil
} }

View File

@ -22,7 +22,7 @@ func (n *notifications) List() ([]Notification, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
var r NotificationsListResponse var r notificationsListResponse
res.JSON(&r) res.JSON(&r)
return r.Ocs.Data, nil return r.Ocs.Data, nil
} }
@ -36,7 +36,7 @@ func (n *notifications) Get(id int) (Notification, error) {
if err != nil { if err != nil {
return Notification{}, err return Notification{}, err
} }
var r NotificationResponse var r notificationResponse
res.JSON(&r) res.JSON(&r)
return r.Ocs.Data, nil return r.Ocs.Data, nil
} }

View File

@ -1,7 +1,7 @@
package gonextcloud package gonextcloud
//Meta //meta
type Meta struct { type meta struct {
Status string `json:"status"` Status string `json:"status"`
Statuscode int `json:"statuscode"` Statuscode int `json:"statuscode"`
Message string `json:"message"` Message string `json:"message"`
@ -9,109 +9,109 @@ type Meta struct {
Itemsperpage string `json:"itemsperpage"` Itemsperpage string `json:"itemsperpage"`
} }
//ErrorResponse //errorResponse
type ErrorResponse struct { type errorResponse struct {
Ocs struct { Ocs struct {
Meta Meta `json:"meta"` Meta meta `json:"meta"`
Data []interface{} `json:"data"` Data []interface{} `json:"data"`
} `json:"ocs"` } `json:"ocs"`
} }
//UserListResponse //userListResponse
type UserListResponse struct { type userListResponse struct {
Ocs struct { Ocs struct {
Meta Meta `json:"meta"` Meta meta `json:"meta"`
Data struct { Data struct {
Users []string `json:"users"` Users []string `json:"users"`
} `json:"data"` } `json:"data"`
} `json:"ocs"` } `json:"ocs"`
} }
type UserListDetailsResponse struct { type userListDetailsResponse struct {
Ocs struct { Ocs struct {
Meta Meta `json:"meta"` Meta meta `json:"meta"`
Data struct { Data struct {
Users map[string]UserDetails `json:"users"` Users map[string]UserDetails `json:"users"`
} `json:"data"` } `json:"data"`
} `json:"ocs"` } `json:"ocs"`
} }
//UserResponse //userResponse
type UserResponse struct { type userResponse struct {
Ocs struct { Ocs struct {
Meta Meta `json:"meta"` Meta meta `json:"meta"`
Data UserDetails `json:"data"` Data UserDetails `json:"data"`
} `json:"ocs"` } `json:"ocs"`
} }
//BaseResponse //baseResponse
type BaseResponse struct { type baseResponse struct {
Ocs struct { Ocs struct {
Meta Meta `json:"meta"` Meta meta `json:"meta"`
Data []string `json:"data"` Data []string `json:"data"`
} `json:"ocs"` } `json:"ocs"`
} }
//GroupListResponse //groupListResponse
type GroupListResponse struct { type groupListResponse struct {
Ocs struct { Ocs struct {
Meta Meta `json:"meta"` Meta meta `json:"meta"`
Data struct { Data struct {
Groups []string `json:"groups"` Groups []string `json:"groups"`
} `json:"data"` } `json:"data"`
} `json:"ocs"` } `json:"ocs"`
} }
//GroupListDetailsResponse //groupListDetailsResponse
type GroupListDetailsResponse struct { type groupListDetailsResponse struct {
Ocs struct { Ocs struct {
Meta Meta `json:"meta"` Meta meta `json:"meta"`
Data struct { Data struct {
Groups []Group `json:"groups"` Groups []Group `json:"groups"`
} `json:"data"` } `json:"data"`
} `json:"ocs"` } `json:"ocs"`
} }
//AppListResponse //appListResponse
type AppListResponse struct { type appListResponse struct {
Ocs struct { Ocs struct {
Meta Meta `json:"meta"` Meta meta `json:"meta"`
Data struct { Data struct {
Apps []string `json:"apps"` Apps []string `json:"apps"`
} `json:"data"` } `json:"data"`
} `json:"ocs"` } `json:"ocs"`
} }
//AppResponse //appResponse
type AppResponse struct { type appResponse struct {
Ocs struct { Ocs struct {
Meta Meta `json:"meta"` Meta meta `json:"meta"`
Data App `json:"data"` Data App `json:"data"`
} `json:"ocs"` } `json:"ocs"`
} }
type AppConfigResponse struct { type appConfigResponse struct {
Ocs struct { Ocs struct {
Meta Meta `json:"meta"` Meta meta `json:"meta"`
Data struct { Data struct {
Data []string `json:"data"` Data []string `json:"data"`
} `json:"data"` } `json:"data"`
} `json:"ocs"` } `json:"ocs"`
} }
type AppcConfigValueResponse struct { type appcConfigValueResponse struct {
Ocs struct { Ocs struct {
Meta Meta `json:"meta"` Meta meta `json:"meta"`
Data struct { Data struct {
Data string `json:"data"` Data string `json:"data"`
} `json:"data"` } `json:"data"`
} `json:"ocs"` } `json:"ocs"`
} }
//CapabilitiesResponse //capabilitiesResponse
type CapabilitiesResponse struct { type capabilitiesResponse struct {
Ocs struct { Ocs struct {
Meta Meta `json:"meta"` Meta meta `json:"meta"`
Data struct { Data struct {
Version Version `json:"version"` Version Version `json:"version"`
Capabilities Capabilities `json:"capabilities"` Capabilities Capabilities `json:"capabilities"`
@ -127,58 +127,58 @@ type Version struct {
Edition string `json:"edition"` Edition string `json:"edition"`
} }
type MonitoringResponse struct { type monitoringResponse struct {
Ocs struct { Ocs struct {
Meta Meta `json:"meta"` Meta meta `json:"meta"`
Data Monitoring `json:"data"` Data Monitoring `json:"data"`
} `json:"ocs"` } `json:"ocs"`
} }
type SharesListResponse struct { type sharesListResponse struct {
Ocs struct { Ocs struct {
Meta Meta `json:"meta"` Meta meta `json:"meta"`
Data []Share `json:"data"` Data []Share `json:"data"`
} `json:"ocs"` } `json:"ocs"`
} }
type SharesResponse struct { type sharesResponse struct {
Ocs struct { Ocs struct {
Meta Meta `json:"meta"` Meta meta `json:"meta"`
Data Share `json:"data"` Data Share `json:"data"`
} `json:"ocs"` } `json:"ocs"`
} }
type GroupFoldersListResponse struct { type groupFoldersListResponse struct {
Ocs struct { Ocs struct {
Meta Meta `json:"meta"` Meta meta `json:"meta"`
Data map[string]GroupFolderBadFormatIDAndGroups `json:"data"` Data map[string]groupFolderBadFormatIDAndGroups `json:"data"`
} `json:"ocs"` } `json:"ocs"`
} }
type GroupFoldersCreateResponse struct { type groupFoldersCreateResponse struct {
Ocs struct { Ocs struct {
Meta Meta `json:"meta"` Meta meta `json:"meta"`
Data GroupFolderBadFormatIDAndGroups `json:"data"` Data groupFolderBadFormatIDAndGroups `json:"data"`
} `json:"ocs"` } `json:"ocs"`
} }
type GroupFoldersResponse struct { type groupFoldersResponse struct {
Ocs struct { Ocs struct {
Meta Meta `json:"meta"` Meta meta `json:"meta"`
Data GroupFolderBadFormatGroups `json:"data"` Data groupFolderBadFormatGroups `json:"data"`
} `json:"ocs"` } `json:"ocs"`
} }
type NotificationsListResponse struct { type notificationsListResponse struct {
Ocs struct { Ocs struct {
Meta Meta `json:"meta"` Meta meta `json:"meta"`
Data []Notification `json:"data"` Data []Notification `json:"data"`
} `json:"ocs"` } `json:"ocs"`
} }
type NotificationResponse struct { type notificationResponse struct {
Ocs struct { Ocs struct {
Meta Meta `json:"meta"` Meta meta `json:"meta"`
Data Notification `json:"data"` Data Notification `json:"data"`
} `json:"ocs"` } `json:"ocs"`
} }

View File

@ -2,8 +2,8 @@ package gonextcloud
import "net/url" import "net/url"
// Routes references the available routes // apiRoutes references the available routes
type Routes struct { type apiRoutes struct {
capabilities *url.URL capabilities *url.URL
users *url.URL users *url.URL
groups *url.URL groups *url.URL
@ -20,7 +20,7 @@ const badRequest = 998
var ( var (
apiPath = &url.URL{Path: "/ocs/v2.php"} apiPath = &url.URL{Path: "/ocs/v2.php"}
routes = Routes{ routes = apiRoutes{
capabilities: &url.URL{Path: apiPath.Path + "/cloud/capabilities"}, capabilities: &url.URL{Path: apiPath.Path + "/cloud/capabilities"},
users: &url.URL{Path: apiPath.Path + "/cloud/users"}, users: &url.URL{Path: apiPath.Path + "/cloud/users"},
groups: &url.URL{Path: apiPath.Path + "/cloud/groups"}, groups: &url.URL{Path: apiPath.Path + "/cloud/groups"},

View File

@ -20,7 +20,7 @@ func (s *shares) List() ([]Share, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
var r SharesListResponse var r sharesListResponse
res.JSON(&r) res.JSON(&r)
return r.Ocs.Data, nil return r.Ocs.Data, nil
} }
@ -38,7 +38,7 @@ func (s *shares) GetFromPath(path string, reshares bool, subfiles bool) ([]Share
if err != nil { if err != nil {
return nil, err return nil, err
} }
var r SharesListResponse var r sharesListResponse
res.JSON(&r) res.JSON(&r)
return r.Ocs.Data, nil return r.Ocs.Data, nil
} }
@ -49,7 +49,7 @@ func (s *shares) Get(shareID string) (Share, error) {
if err != nil { if err != nil {
return Share{}, err return Share{}, err
} }
var r SharesListResponse var r sharesListResponse
res.JSON(&r) res.JSON(&r)
return r.Ocs.Data[0], nil return r.Ocs.Data[0], nil
} }
@ -81,7 +81,7 @@ func (s *shares) Create(
if err != nil { if err != nil {
return Share{}, err return Share{}, err
} }
var r SharesResponse var r sharesResponse
res.JSON(&r) res.JSON(&r)
return r.Ocs.Data, nil return r.Ocs.Data, nil
} }
@ -138,7 +138,7 @@ func (s *shares) Update(shareUpdate ShareUpdate) error {
wg.Wait() wg.Wait()
close(errs) close(errs)
}() }()
if err := NewUpdateError(errs); err != nil { if err := newUpdateError(errs); err != nil {
return err return err
} }
return nil return nil

View File

@ -25,7 +25,7 @@ func (u *users) List() ([]string, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
var r UserListResponse var r userListResponse
res.JSON(&r) res.JSON(&r)
return r.Ocs.Data.Users, nil return r.Ocs.Data.Users, nil
} }
@ -37,7 +37,7 @@ func (u *users) ListDetails() (map[string]UserDetails, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
var r UserListDetailsResponse var r userListDetailsResponse
res.JSON(&r) res.JSON(&r)
return r.Ocs.Data.Users, nil return r.Ocs.Data.Users, nil
} }
@ -51,7 +51,7 @@ func (u *users) Get(name string) (*UserDetails, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
var r UserResponse var r userResponse
js := res.String() js := res.String()
// Nextcloud does not encode JSON properly // Nextcloud does not encode JSON properly
js = reformatJSON(js) js = reformatJSON(js)
@ -70,7 +70,7 @@ func (u *users) Search(search string) ([]string, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
var r UserListResponse var r userListResponse
res.JSON(&r) res.JSON(&r)
return r.Ocs.Data.Users, nil return r.Ocs.Data.Users, nil
} }
@ -290,7 +290,7 @@ func (u *users) Update(user *UserDetails) error {
close(errs) close(errs)
}() }()
// Warning : we actually need to check the *err // Warning : we actually need to check the *err
if err := NewUpdateError(errs); err != nil { if err := newUpdateError(errs); err != nil {
return err return err
} }
return nil return nil
@ -343,7 +343,7 @@ func (u *users) GroupList(name string) ([]string, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
var r GroupListResponse var r groupListResponse
res.JSON(&r) res.JSON(&r)
return r.Ocs.Data.Groups, nil return r.Ocs.Data.Groups, nil
} }
@ -399,7 +399,7 @@ func (u *users) GroupSubAdminList(name string) ([]string, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
var r BaseResponse var r baseResponse
res.JSON(&r) res.JSON(&r)
return r.Ocs.Data, nil return r.Ocs.Data, nil
} }

View File

@ -40,12 +40,12 @@ func (c *client) baseRequest(method string, route *url.URL, ro *req.RequestOptio
} }
// As we cannot read the ReaderCloser twice, we use the string content // As we cannot read the ReaderCloser twice, we use the string content
js := res.String() js := res.String()
var r BaseResponse var r baseResponse
json.Unmarshal([]byte(js), &r) json.Unmarshal([]byte(js), &r)
if r.Ocs.Meta.Statuscode == 200 || r.Ocs.Meta.Statuscode == 100 { if r.Ocs.Meta.Statuscode == 200 || r.Ocs.Meta.Statuscode == 100 {
return res, nil return res, nil
} }
err = ErrorFromMeta(r.Ocs.Meta) err = errorFromMeta(r.Ocs.Meta)
return nil, err return nil, err
} }

View File

@ -1,39 +0,0 @@
package gonextcloud
import (
"io"
"os"
"path/filepath"
)
// WebDav available methods
type WebDav interface {
// ReadDir reads the contents of a remote directory
ReadDir(path string) ([]os.FileInfo, error)
// Stat returns the file stats for a specified path
Stat(path string) (os.FileInfo, error)
// Remove removes a remote file
Remove(path string) error
// RemoveAll removes remote files
RemoveAll(path string) error
// Mkdir makes a directory
Mkdir(path string, _ os.FileMode) error
// MkdirAll like mkdir -p, but for webdav
MkdirAll(path string, _ os.FileMode) error
// Rename moves a file from A to B
Rename(oldpath, newpath string, overwrite bool) error
// Copy copies a file from A to B
Copy(oldpath, newpath string, overwrite bool) error
// Read reads the contents of a remote file
Read(path string) ([]byte, error)
// ReadStream reads the stream for a given path
ReadStream(path string) (io.ReadCloser, error)
// Write writes data to a given path
Write(path string, data []byte, _ os.FileMode) error
// WriteStream writes a stream
WriteStream(path string, stream io.Reader, _ os.FileMode) error
// Walk walks the file tree rooted at root, calling walkFn for each file or
// directory in the tree, including root.
Walk(path string, walkFunc filepath.WalkFunc) error
}