mirror of
https://github.com/1f349/go-webdav.git
synced 2024-12-22 08:14:15 +00:00
caldav: add Client.MultiGetCalendar
This commit is contained in:
parent
5328b4c493
commit
a4e0e81003
@ -47,6 +47,11 @@ type CalendarQuery struct {
|
|||||||
CompFilter CompFilter
|
CompFilter CompFilter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CalendarMultiGet struct {
|
||||||
|
Paths []string
|
||||||
|
CompRequest CalendarCompRequest
|
||||||
|
}
|
||||||
|
|
||||||
type CalendarObject struct {
|
type CalendarObject struct {
|
||||||
Path string
|
Path string
|
||||||
ModTime time.Time
|
ModTime time.Time
|
||||||
|
@ -218,6 +218,38 @@ func (c *Client) QueryCalendar(calendar string, query *CalendarQuery) ([]Calenda
|
|||||||
return decodeCalendarObjectList(ms)
|
return decodeCalendarObjectList(ms)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) MultiGetCalendar(path string, multiGet *CalendarMultiGet) ([]CalendarObject, error) {
|
||||||
|
propReq, err := encodeCalendarReq(&multiGet.CompRequest)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
calendarMultiget := calendarMultiget{Prop: propReq}
|
||||||
|
|
||||||
|
if multiGet == nil || len(multiGet.Paths) == 0 {
|
||||||
|
href := internal.Href{Path: path}
|
||||||
|
calendarMultiget.Hrefs = []internal.Href{href}
|
||||||
|
} else {
|
||||||
|
calendarMultiget.Hrefs = make([]internal.Href, len(multiGet.Paths))
|
||||||
|
for i, p := range multiGet.Paths {
|
||||||
|
calendarMultiget.Hrefs[i] = internal.Href{Path: p}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err := c.ic.NewXMLRequest("REPORT", path, &calendarMultiget)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
req.Header.Add("Depth", "1")
|
||||||
|
|
||||||
|
ms, err := c.ic.DoMultiStatus(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return decodeCalendarObjectList(ms)
|
||||||
|
}
|
||||||
|
|
||||||
func populateCalendarObject(co *CalendarObject, resp *http.Response) error {
|
func populateCalendarObject(co *CalendarObject, resp *http.Response) error {
|
||||||
if loc := resp.Header.Get("Location"); loc != "" {
|
if loc := resp.Header.Get("Location"); loc != "" {
|
||||||
u, err := url.Parse(loc)
|
u, err := url.Parse(loc)
|
||||||
|
@ -60,6 +60,15 @@ type calendarQuery struct {
|
|||||||
// TODO: timezone
|
// TODO: timezone
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://tools.ietf.org/html/rfc4791#section-9.10
|
||||||
|
type calendarMultiget struct {
|
||||||
|
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:caldav calendar-multiget"`
|
||||||
|
Hrefs []internal.Href `xml:"DAV: href"`
|
||||||
|
Prop *internal.Prop `xml:"DAV: prop,omitempty"`
|
||||||
|
AllProp *struct{} `xml:"DAV: allprop,omitempty"`
|
||||||
|
PropName *struct{} `xml:"DAV: propname,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
// https://tools.ietf.org/html/rfc4791#section-9.7
|
// https://tools.ietf.org/html/rfc4791#section-9.7
|
||||||
type filter struct {
|
type filter struct {
|
||||||
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:caldav filter"`
|
XMLName xml.Name `xml:"urn:ietf:params:xml:ns:caldav filter"`
|
||||||
|
Loading…
Reference in New Issue
Block a user