Struct libdav::CardDavClient
source · pub struct CardDavClient {
pub addressbook_home_set: Option<Uri>,
/* private fields */
}Expand description
A client to communicate with a carddav server.
Wraps around a WebDavClient, which provides the underlying functionality.
Fields§
§addressbook_home_set: Option<Uri>URL of collections that are either address book collections or ordinary collections that have child or descendant address book collections owned by the principal. See: https://www.rfc-editor.org/rfc/rfc6352#section-7.1.1
Implementations§
source§impl CardDavClient
impl CardDavClient
sourcepub fn raw_client(base_url: Uri, auth: Auth) -> Self
pub fn raw_client(base_url: Uri, auth: Auth) -> Self
Returns a client without any automatic bootstrapping.
It is generally advised to use CardDavClient::auto_bootstrap instead.
sourcepub async fn auto_bootstrap(
base_url: Uri,
auth: Auth
) -> Result<Self, BootstrapError>
pub async fn auto_bootstrap( base_url: Uri, auth: Auth ) -> Result<Self, BootstrapError>
Auto-bootstrap a new client.
Determines the carddav server’s real host and the context path of the resources for a server, following the discovery mechanism described in rfc6764.
Errors
If any of the underlying DNS or HTTP requests fail, or if any of the responses fail to parse.
Does not return an error if DNS records as missing, only if they contain invalid data.
sourcepub async fn find_addresbooks(
&self,
url: &Uri
) -> Result<Vec<(String, Option<String>)>, DavError>
pub async fn find_addresbooks( &self, url: &Uri ) -> Result<Vec<(String, Option<String>)>, DavError>
Find address book collections under the given url.
Returns absolute paths to each addressbook and their respective etag. This method should be
called with the addressbook_home_set URL to find the current user’s address books.
Errors
If the HTTP call fails or parsing the XML response fails.
Methods from Deref<Target = WebDavClient>§
sourcepub fn context_path(&self) -> &Uri
pub fn context_path(&self) -> &Uri
Returns a URL pointing to the server’s context path.
sourcepub fn relative_uri(&self, path: &str) -> Result<Uri, Error>
pub fn relative_uri(&self, path: &str) -> Result<Uri, Error>
Returns a new URI relative to the server’s root.
Errors
If this client’s base_url is invalid or the provided path is not an acceptable path.
sourcepub async fn find_current_user_principal(
&self
) -> Result<Option<Uri>, FindCurrentUserPrincipalError>
pub async fn find_current_user_principal( &self ) -> Result<Option<Uri>, FindCurrentUserPrincipalError>
Resolves the current user’s principal resource.
Returns None if the response’s status code is 404 or if no principal was found.
Errors
- If the underlying HTTP request fails.
- If the response status code is neither success nor 404.
- If parsing the XML response fails.
- If the
hrefcannot be parsed into a validUri
See also
sourcepub async fn propfind<T: FromXml>(
&self,
url: &Uri,
prop: &str,
depth: u8,
data: &T::Data
) -> Result<Vec<Response<T>>, DavError>
pub async fn propfind<T: FromXml>( &self, url: &Uri, prop: &str, depth: u8, data: &T::Data ) -> Result<Vec<Response<T>>, DavError>
Sends a PROPFIND request and parses the result.
This is a shortcut for simple PROPFIND requests.
Errors
See request_multistatus.
sourcepub async fn request_multistatus<T: FromXml>(
&self,
request: Request<Body>,
data: &T::Data
) -> Result<Multistatus<T>, DavError>
pub async fn request_multistatus<T: FromXml>( &self, request: Request<Body>, data: &T::Data ) -> Result<Multistatus<T>, DavError>
Send a request which expects a multistatus response and parse it as T.
Errors
- If a network error occurs executing the underlying HTTP request.
- If the server returns an error status code.
- If the response is not a valid XML document.
- If the response’s XML schema does not match the expected type.
sourcepub async fn get_collection_displayname(
&self,
href: &str
) -> Result<Option<String>, DavError>
pub async fn get_collection_displayname( &self, href: &str ) -> Result<Option<String>, DavError>
Returns the displayname for the collection at path href.
From rfc3744#section-4:
A principal MUST have a non-empty DAV:displayname property
Errors
See request_multistatus.
sourcepub async fn find_context_path(
&self,
service: DiscoverableService,
host: &str,
port: u16
) -> Result<Option<Uri>, ResolveContextPathError>
pub async fn find_context_path( &self, service: DiscoverableService, host: &str, port: u16 ) -> Result<Option<Uri>, ResolveContextPathError>
Resolve the default context path using a well-known path.
This only applies for servers supporting webdav extensions like caldav or carddav.
Errors
- If the provided scheme, host and port cannot be used to construct a valid URL.
- If there are any network errors.
- If the response is not an HTTP redirection.
- If the
Locationheader in the response is missing or invalid.
See also
sourcepub async fn list_resources(
&self,
collection_href: &str
) -> Result<Vec<ListedResource>, DavError>
pub async fn list_resources( &self, collection_href: &str ) -> Result<Vec<ListedResource>, DavError>
sourcepub async fn create_resource<Href, MimeType>(
&self,
href: Href,
data: Vec<u8>,
mime_type: MimeType
) -> Result<Option<Vec<u8>>, CreateResourceError>where
Href: AsRef<str>,
MimeType: AsRef<[u8]>,
pub async fn create_resource<Href, MimeType>( &self, href: Href, data: Vec<u8>, mime_type: MimeType ) -> Result<Option<Vec<u8>>, CreateResourceError>where Href: AsRef<str>, MimeType: AsRef<[u8]>,
Creates a new resource
Returns an Etag if present in the server’s response.
Errors
See request_multistatus.
sourcepub async fn update_resource<Href, Etag, MimeType>(
&self,
href: Href,
data: Vec<u8>,
etag: Etag,
mime_type: MimeType
) -> Result<Option<Vec<u8>>, UpdateResourceError>where
Href: AsRef<str>,
Etag: AsRef<[u8]>,
MimeType: AsRef<[u8]>,
pub async fn update_resource<Href, Etag, MimeType>( &self, href: Href, data: Vec<u8>, etag: Etag, mime_type: MimeType ) -> Result<Option<Vec<u8>>, UpdateResourceError>where Href: AsRef<str>, Etag: AsRef<[u8]>, MimeType: AsRef<[u8]>,
Updates an existing resource
Returns an Etag if present in the server’s response.
Errors
See request_multistatus.
sourcepub async fn create_collection<Href: AsRef<str>>(
&self,
href: Href,
resourcetype: CollectionType
) -> Result<(), CreateCollectionError>
pub async fn create_collection<Href: AsRef<str>>( &self, href: Href, resourcetype: CollectionType ) -> Result<(), CreateCollectionError>
Creates a collection under path href.
Caveats
Because servers commonly don’t return an Etag for this operation, it needs to be fetched in a separate operation.
Errors
See request_multistatus.
sourcepub async fn delete<Href, Etag>(
&self,
href: Href,
etag: Etag
) -> Result<(), DeleteError>where
Href: AsRef<str>,
Etag: AsRef<[u8]>,
pub async fn delete<Href, Etag>( &self, href: Href, etag: Etag ) -> Result<(), DeleteError>where Href: AsRef<str>, Etag: AsRef<[u8]>,
Deletes the resource at href.
The resource MAY be a collection. Because the implementation for deleting resources and collections is identical, this same method covers both cases.
Errors
See request_multistatus.
sourcepub async fn force_delete<Href>(&self, href: Href) -> Result<(), DeleteError>where
Href: AsRef<str>,
pub async fn force_delete<Href>(&self, href: Href) -> Result<(), DeleteError>where Href: AsRef<str>,
Force deletion of the resource at href.
This function cannot guarantee that a resource or collection has not been modified since it was last read. Use this function with great care.
The resource MAY be a collection. Because the implementation for deleting resources and collections is identical, this same method covers both cases.
Errors
See request_multistatus.