NAME

Net::DAVTalk - Interface to talk to DAV servers

VERSION

Version 0.16

SYNOPSIS

Net::DAVTalk is was originally designed as a service module for Net::CalDAVTalk and Net::DAVTalk, abstracting the process of connecting to a DAV server and parsing the XML responses.

Example:

    use Net::DAVTalk;
    use XML::Spice;

    my $davtalk = Net::DAVTalk->new(
        url => "https://dav.example.com/",
        user => "foo\@example.com",
        password => "letmein",
    );

    $davtalk->Request(
        'MKCALENDAR',
        "$calendarId/",
        x('C:mkcalendar', $Self->NS(),
            x('D:set',
                 x('D:prop', @Properties),
            ),
        ),
    );

    $davtalk->Request(
        'DELETE',
        "$calendarId/",
    );

SUBROUTINES/METHODS

$class->new(%Options)

Options:

    url: either full https?:// url, or relative base path on the
    server to the DAV endpoint

    host, scheme and port: alternative to using full URL.
    If URL doesn't start with https?:// then these will be used to
    construct the endpoint URI.

    expandurl and wellknown: if these are set, then the wellknown
    name (caldav and carddav are both defined) will be used to
    resolve /.well-known/$wellknown to find the current-user-principal
    URI, and then THAT will be resovlved to find the $wellknown-home-set
    URI, which will be used as the URL for all further actions on
    this object.

    user and password: if these are set, perform basic authentication.
    user and access_token: if these are set, perform Bearer (OAUTH2)
    authentication.

$Self->SetURL($url)

Change the endpoint URL for an existing connection.

$Self->SetPrincipalURL($url)

Set the URL to the DAV Principal

$Self->fullpath($shortpath)

Convert from a relative path to a full path:

e.g my $path = $Dav->fullpath('Default'); ## /dav/calendars/user/foo/Default

NOTE: a you can pass a non-relative full path (leading /) to this function and it will be returned unchanged.

$Self->shortpath($fullpath)

Convert from a full path to a relative path

e.g my $path = $Dav->fullpath('/dav/calendars/user/foo/Default'); ## Default

NOTE: if the full path is outside the basepath of the object, it will be unchanged.

    my $path = $Dav->fullpath('/dav/calendars/user/bar/Default');
    ## /dav/calendars/user/bar/Default

$Self->Request($method, $path, $content, %headers)

The whole point of the module! Perform a DAV request against the endpoint, returning the response as a parsed hash.

   method: http method, i.e. GET, PROPFIND, MKCOL, DELETE, etc

   path: relative to base url.  With a leading slash, relative to
         server root, i.e. "Default/", "/dav/calendars/user/foo/Default".

   content: if the method takes a body, raw bytes to send

   headers: additional headers to add to request, i.e (Depth => 1)

$Self->GetProps($Path, @Props)

perform a propfind on a particular path and get the properties back

$Self->GetPropsArray($Path, @Props)

perform a propfind on a particular path and get the properties back as an array of one or more items

$Self->GetCurrentUserPrincipal() =head2 $class->GetCurrentUserPrincipal(%Args)

Can be called with the same args as new() as a class method, or on an existing object. Either way it will use the .well-known URI to find the path to the current-user-principal.

Returns a string with the path.

$Self->GetHomeSet =head2 $class->GetHomeSet(%Args)

Can be called with the same args as new() as a class method, or on an existing object. Either way it assumes that the created object has a 'url' parameter pointing at the current user principal URL (see GetCurrentUserPrincipal above)

Returns a string with the path to the home set.

$Self->genuuid()

Helper to generate a uuid string. Returns a UUID, e.g.

    my $uuid = $DAVTalk->genuuid(); # 9b9d68af-ad13-46b8-b7ab-30ab70da14ac

$Self->auth_header()

Generate the authentication header to use on requests:

e.g:

    $Headers{'Authorization'} = $Self->auth_header();

$Self->request_url()

Generate the authentication header to use on requests:

e.g:

    $Headers{'Authorization'} = $Self->auth_header();

$Self->NS()

Returns a hashref of the 'xmlns:shortname' => 'full namespace' items for use in XML::Spice body generation, e.g.

    $DAVTalk->Request(
        'MKCALENDAR',
        "$calendarId/",
        x('C:mkcalendar', $Self->NS(),
            x('D:set',
                 x('D:prop', @Properties),
            ),
        ),
    );

    # { 'xmlns:C' => 'urn:ietf:params:xml:ns:caldav', 'xmlns:D' => 'DAV:' }

$Self->ns($key, $value)

Get or set namespace aliases, e.g

  $Self->ns(C => 'urn:ietf:params:xml:ns:caldav');
  my $NS_C = $Self->ns('C'); # urn:ietf:params:xml:ns:caldav

function2

AUTHOR

Bron Gondwana, <brong at cpan.org>

BUGS

Please report any bugs or feature requests to bug-net-davtalk at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-DAVTalk. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Net::DAVTalk

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

Copyright 2015 FastMail Pty. Ltd.

This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at:

http://www.perlfoundation.org/artistic_license_2_0

Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license.

If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license.

This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder.

This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed.

Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.