webdav
A Ruby WebDAV client library.
Installation
gem install webdav
Or in your Gemfile:
gem 'webdav'
Usage
require 'webdav'
dav = WebDAV.new('https://dav.example.com/files/', username: 'user', password: 'pass')
Discovering resources
response = dav.propfind('/', depth: '1')
response.resources.each do |resource|
puts resource[:href]
puts resource[:properties]
end
Reading a resource
response = dav.get('/documents/report.txt')
puts response.body
Writing a resource
dav.put('/documents/report.txt', body: 'Hello, world.', content_type: 'text/plain')
Deleting a resource
dav.delete('/documents/report.txt')
Creating a collection
dav.mkcol('/documents/archive/')
Copying and moving
dav.copy('/documents/report.txt', to: '/archive/report.txt')
dav.move('/documents/draft.txt', to: '/documents/final.txt')
Locking and unlocking
lock_body = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<d:lockinfo xmlns:d=\"DAV:\">\n <d:lockscope><d:exclusive/></d:lockscope>\n <d:locktype><d:write/></d:locktype>\n</d:lockinfo>\n"
response = dav.lock('/documents/report.txt', body: lock_body)
# ...
dav.unlock('/documents/report.txt', token: 'urn:uuid:...')
REPORT
response = dav.report('/calendars/user/', body: report_xml, depth: '1')
response.resources.each do |resource|
puts resource[:href]
end
Verbs
WebDAV (RFC 4918 / RFC 3253)
propfind(path, body:, depth:)— Retrieve propertiesproppatch(path, body:)— Modify propertiesreport(path, body:, depth:)— Run a report querymkcol(path)— Create a collectioncopy(path, to:, depth:, overwrite:)— Copy a resourcemove(path, to:, overwrite:)— Move a resourcelock(path, body:)— Lock a resourceunlock(path, token:)— Unlock a resource
Standard HTTP
get(path)head(path)post(path, body:, content_type:)put(path, body:, content_type:)patch(path, body:, content_type:)delete(path)options(path)trace(path)
Responses
All methods return either a WebDAV::Response or a WebDAV::MultiStatus.
WebDAV::Response provides
codemessageheadersbodyetagcontent_typesuccess?
WebDAV::MultiStatus additionally provides:
resources— an array of hashes, each with:hrefpropertiesstatus
Errors
Responses with status >= 400 raise WebDAV::Error, which has code, message, and body.
Dependencies
Licence
MIT