RackDAV is a Ruby gem that allows you to use the WebDAV protocol to edit and manage files over HTTP. It comes with its own file backend, but you can also create your own backend by subclassing RackDAV::Resource.
To install the gem, run gem install rack_dav
.
To quickly test out RackDAV, copy the config.ru file from this repository and run bundle exec rackup
. This will start a web server on a default port that you can connect to without any authentication.
To use RackDAV in your own rack application, include the following in your config.ru file:
require 'rubygems'
require 'rack_dav'
use Rack::CommonLogger
run RackDAV::Handler.new(:root => '/path/to/docs')
If you want to create your own WebDAV resource, you will need to subclass RackDAV::Resource and implement the following methods:
-
children: If this is a collection, return the child resources.
-
collection?: Is this resource a collection?
-
exist?: Does this recource exist?
-
creation_date: Return the creation time.
-
last_modified: Return the time of last modification.
-
last_modified=(time): Set the time of last modification.
-
etag: Return an Etag, an unique hash value for this resource.
-
content_type: Return the mime type of this resource.
-
content_length: Return the size in bytes for this resource.
-
get(request, response): Write the content of the resource to the response.body.
-
put(request, response): Save the content of the request.body.
-
post(request, response): Usually forbidden.
-
delete: Delete this resource.
-
copy(dest): Copy this resource to given destination resource.
-
move(dest): Move this resource to given destination resource.
-
make_collection: Create this resource as collection.
-
set_custom_property(name, value): Set a custom property on the resource. If the value is nil, delete the custom property.
-
get_custom_property(name): Return the value of the named custom property.
-
lock(locktoken, timeout, lockscope=nil, locktype=nil, owner=nil): Lock this resource. If scope, type and owner are nil, refresh the given lock.
-
unlock(token): Unlock this resource
Note that it is possible that a resource object may be instantiated for a resource that does not yet exist.
For more examples and inspiration, you can look at the FileResource implementation.