A Ruby WebDAV client library.
gem install webdav
Or in your Gemfile:
gem 'webdav'require 'webdav'
dav = WebDAV.new('https://dav.example.com/files/', username: 'user', password: 'pass')response = dav.propfind('/', depth: '1')
response.resources.each do |resource|
puts resource[:href]
puts resource[:properties]
endresponse = dav.get('/documents/report.txt')
puts response.bodydav.put('/documents/report.txt', body: 'Hello, world.', content_type: 'text/plain')dav.delete('/documents/report.txt')dav.mkcol('/documents/archive/')dav.copy('/documents/report.txt', to: '/archive/report.txt')
dav.move('/documents/draft.txt', to: '/documents/final.txt')lock_body = <<~XML
<?xml version="1.0" encoding="UTF-8"?>
<d:lockinfo xmlns:d="DAV:">
<d:lockscope><d:exclusive/></d:lockscope>
<d:locktype><d:write/></d:locktype>
</d:lockinfo>
XML
response = dav.lock('/documents/report.txt', body: lock_body)
# ...
dav.unlock('/documents/report.txt', token: 'urn:uuid:...')response = dav.report('/calendars/user/', body: report_xml, depth: '1')
response.resources.each do |resource|
puts resource[:href]
endpropfind(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
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)
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
Responses with status >= 400 raise WebDAV::Error, which has code, message, and body.
MIT