mirror of
https://github.com/1f349/go-webdav.git
synced 2024-12-22 16:24:14 +00:00
carddav: add very basic Client
This commit is contained in:
parent
931602e55d
commit
3d05533a31
3
carddav/carddav.go
Normal file
3
carddav/carddav.go
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
package carddav
|
||||||
|
|
||||||
|
const namespace = "urn:ietf:params:xml:ns:carddav"
|
44
carddav/client.go
Normal file
44
carddav/client.go
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
package carddav
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/xml"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/emersion/go-webdav"
|
||||||
|
"github.com/emersion/go-webdav/internal"
|
||||||
|
)
|
||||||
|
|
||||||
|
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) FindAddressbookHomeSet(principal string) (string, error) {
|
||||||
|
name := xml.Name{namespace, "addressbook-home-set"}
|
||||||
|
propfind := internal.NewPropPropfind(name)
|
||||||
|
|
||||||
|
resp, err := c.ic.PropfindFlat(principal, propfind)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
var prop addressbookHomeSet
|
||||||
|
if err := resp.DecodeProp(name, &prop); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return prop.Href, nil
|
||||||
|
}
|
10
carddav/elements.go
Normal file
10
carddav/elements.go
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package carddav
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/xml"
|
||||||
|
)
|
||||||
|
|
||||||
|
type addressbookHomeSet struct {
|
||||||
|
Name xml.Name `xml:"urn:ietf:params:xml:ns:carddav addressbook-home-set"`
|
||||||
|
Href string `xml:"href"`
|
||||||
|
}
|
@ -28,7 +28,7 @@ func (c *Client) FindCurrentUserPrincipal() (string, error) {
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
var prop currentUserPrincipalProp
|
var prop currentUserPrincipal
|
||||||
if err := resp.DecodeProp(name, &prop); err != nil {
|
if err := resp.DecodeProp(name, &prop); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
)
|
)
|
||||||
|
|
||||||
type currentUserPrincipalProp struct {
|
type currentUserPrincipal struct {
|
||||||
Name xml.Name `xml:"DAV: current-user-principal"`
|
Name xml.Name `xml:"DAV: current-user-principal"`
|
||||||
Href string `xml:"href"`
|
Href string `xml:"href"`
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user