Project

webdav

0.0
No release in over 3 years
A Ruby WebDAV client library.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Runtime

 Project Readme

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
  <?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:...')

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 properties
  • proppatch(path, body:) — Modify properties
  • report(path, body:, depth:) — Run a report query
  • mkcol(path) — Create a collection
  • copy(path, to:, depth:, overwrite:) — Copy a resource
  • move(path, to:, overwrite:) — Move a resource
  • lock(path, body:) — Lock a resource
  • unlock(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

  • code
  • message
  • headers
  • body
  • etag
  • content_type
  • success?

WebDAV::MultiStatus additionally provides:

  • resources — an array of hashes, each with:
    • href
    • properties
    • status

Errors

Responses with status >= 400 raise WebDAV::Error, which has code, message, and body.

Dependencies

Licence

MIT