mirror of
https://github.com/1f349/go-webdav.git
synced 2024-10-18 08:51:50 +01:00
48 lines
989 B
Go
48 lines
989 B
Go
package caldav
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/emersion/go-webdav"
|
|
"github.com/emersion/go-webdav/internal"
|
|
)
|
|
|
|
// Client provides access to a remote CardDAV server.
|
|
type Client struct {
|
|
*webdav.Client
|
|
|
|
ic *internal.Client
|
|
}
|
|
|
|
func NewClient(c *http.Client, endpoint string) (*Client, error) {
|
|
wc, err := webdav.NewClient(c, endpoint)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ic, err := internal.NewClient(c, endpoint)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &Client{wc, ic}, nil
|
|
}
|
|
|
|
func (c *Client) SetBasicAuth(username, password string) {
|
|
c.Client.SetBasicAuth(username, password)
|
|
c.ic.SetBasicAuth(username, password)
|
|
}
|
|
|
|
func (c *Client) FindCalendarHomeSet(principal string) (string, error) {
|
|
propfind := internal.NewPropNamePropfind(calendarHomeSetName)
|
|
resp, err := c.ic.PropfindFlat(principal, propfind)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
var prop calendarHomeSet
|
|
if err := resp.DecodeProp(&prop); err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return prop.Href.Path, nil
|
|
}
|