2018-07-25 13:06:31 +00:00
|
|
|
package gonextcloud
|
2018-07-05 10:50:56 +00:00
|
|
|
|
|
|
|
import (
|
2019-07-13 23:49:50 +00:00
|
|
|
"net/url"
|
|
|
|
|
2018-07-05 10:50:56 +00:00
|
|
|
req "github.com/levigross/grequests"
|
2019-07-13 23:49:50 +00:00
|
|
|
"github.com/studio-b12/gowebdav"
|
|
|
|
|
2018-10-26 13:35:50 +00:00
|
|
|
"gitlab.bertha.cloud/partitio/Nextcloud-Partitio/gonextcloud/types"
|
2018-07-05 10:50:56 +00:00
|
|
|
)
|
|
|
|
|
2018-07-30 08:03:38 +00:00
|
|
|
// Client is the API client that performs all operations against a Nextcloud server.
|
2018-07-05 10:50:56 +00:00
|
|
|
type Client struct {
|
|
|
|
baseURL *url.URL
|
|
|
|
username string
|
|
|
|
password string
|
|
|
|
session *req.Session
|
|
|
|
headers map[string]string
|
|
|
|
capabilities *types.Capabilities
|
2018-10-16 09:02:04 +00:00
|
|
|
version *types.Version
|
2018-10-21 12:53:12 +00:00
|
|
|
|
2018-12-11 09:27:11 +00:00
|
|
|
apps *Apps
|
|
|
|
appsConfig *AppsConfig
|
|
|
|
groupFolders *GroupFolders
|
|
|
|
notifications *Notifications
|
|
|
|
shares *Shares
|
|
|
|
users *Users
|
|
|
|
groups *Groups
|
2019-07-13 23:49:50 +00:00
|
|
|
webdav *gowebdav.Client
|
2018-07-05 10:50:56 +00:00
|
|
|
}
|
|
|
|
|
2018-07-30 08:03:38 +00:00
|
|
|
// NewClient create a new Client from the Nextcloud Instance URL
|
2018-07-05 10:50:56 +00:00
|
|
|
func NewClient(hostname string) (*Client, error) {
|
2018-07-13 11:41:51 +00:00
|
|
|
baseURL, err := url.ParseRequestURI(hostname)
|
2018-07-05 10:50:56 +00:00
|
|
|
if err != nil {
|
2018-07-13 11:41:51 +00:00
|
|
|
baseURL, err = url.ParseRequestURI("https://" + hostname)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-07-05 10:50:56 +00:00
|
|
|
}
|
2018-07-13 11:41:51 +00:00
|
|
|
|
2018-10-21 12:53:12 +00:00
|
|
|
c := &Client{
|
2018-07-05 10:50:56 +00:00
|
|
|
baseURL: baseURL,
|
|
|
|
headers: map[string]string{
|
|
|
|
"OCS-APIREQUEST": "true",
|
|
|
|
"Accept": "application/json",
|
|
|
|
},
|
|
|
|
}
|
2019-07-13 23:49:50 +00:00
|
|
|
|
2018-12-11 09:27:11 +00:00
|
|
|
c.apps = &Apps{c}
|
|
|
|
c.appsConfig = &AppsConfig{c}
|
|
|
|
c.groupFolders = &GroupFolders{c}
|
|
|
|
c.notifications = &Notifications{c}
|
|
|
|
c.shares = &Shares{c}
|
|
|
|
c.users = &Users{c}
|
|
|
|
c.groups = &Groups{c}
|
2019-07-13 23:49:50 +00:00
|
|
|
// Create empty webdav client
|
|
|
|
// It will be replaced after login
|
|
|
|
c.webdav = &gowebdav.Client{}
|
2018-10-21 12:53:12 +00:00
|
|
|
return c, nil
|
2018-07-05 10:50:56 +00:00
|
|
|
}
|
2018-12-11 09:27:11 +00:00
|
|
|
|
2019-01-03 13:09:23 +00:00
|
|
|
//Apps return the Apps client Interface
|
2018-12-11 09:27:11 +00:00
|
|
|
func (c *Client) Apps() types.Apps {
|
|
|
|
return c.apps
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:09:23 +00:00
|
|
|
//AppsConfig return the AppsConfig client Interface
|
2018-12-11 09:27:11 +00:00
|
|
|
func (c *Client) AppsConfig() types.AppsConfig {
|
|
|
|
return c.appsConfig
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:09:23 +00:00
|
|
|
//GroupFolders return the GroupFolders client Interface
|
2018-12-11 09:27:11 +00:00
|
|
|
func (c *Client) GroupFolders() types.GroupFolders {
|
|
|
|
return c.groupFolders
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:09:23 +00:00
|
|
|
//Notifications return the Notifications client Interface
|
2018-12-11 09:27:11 +00:00
|
|
|
func (c *Client) Notifications() types.Notifications {
|
|
|
|
return c.notifications
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:09:23 +00:00
|
|
|
//Shares return the Shares client Interface
|
2018-12-11 09:27:11 +00:00
|
|
|
func (c *Client) Shares() types.Shares {
|
|
|
|
return c.shares
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:09:23 +00:00
|
|
|
//Users return the Users client Interface
|
2018-12-11 09:27:11 +00:00
|
|
|
func (c *Client) Users() types.Users {
|
|
|
|
return c.users
|
|
|
|
}
|
|
|
|
|
2019-01-03 13:09:23 +00:00
|
|
|
//Groups return the Groups client Interface
|
2018-12-11 09:27:11 +00:00
|
|
|
func (c *Client) Groups() types.Groups {
|
|
|
|
return c.groups
|
|
|
|
}
|
2019-07-13 23:49:50 +00:00
|
|
|
|
|
|
|
// WebDav return the WebDav client Interface
|
|
|
|
func (c *Client) WebDav() types.WebDav {
|
|
|
|
return c.webdav
|
|
|
|
}
|