2018-07-25 13:06:31 +00:00
|
|
|
package gonextcloud
|
2018-07-05 10:50:56 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
req "github.com/levigross/grequests"
|
2018-10-26 13:35:50 +00:00
|
|
|
"gitlab.bertha.cloud/partitio/Nextcloud-Partitio/gonextcloud/types"
|
2018-07-05 10:50:56 +00:00
|
|
|
"net/url"
|
|
|
|
)
|
|
|
|
|
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
|
|
|
|
|
|
|
Apps *Apps
|
|
|
|
AppsConfig *AppsConfig
|
|
|
|
GroupFolders *GroupFolders
|
|
|
|
Notifications *Notifications
|
|
|
|
Shares *Shares
|
|
|
|
Users *Users
|
|
|
|
Groups *Groups
|
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",
|
|
|
|
},
|
|
|
|
}
|
2018-10-21 12:53:12 +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}
|
|
|
|
return c, nil
|
2018-07-05 10:50:56 +00:00
|
|
|
}
|