# frozen_string_literal: true module HTTPX module Plugins # # This plugin implements convenience methods for performing WEBDAV requests. # # https://gitlab.com/honeyryderchuck/httpx/wikis/WEBDAV # module WebDav module InstanceMethods def copy(src, dest) request(:copy, src, headers: { "destination" => @options.origin.merge(dest) }) end def move(src, dest) request(:move, src, headers: { "destination" => @options.origin.merge(dest) }) end def lock(path, timeout: nil, &blk) headers = {} headers["timeout"] = if timeout && timeout.positive? "Second-#{timeout}" else "Infinite, Second-4100000000" end xml = "" \ "" \ "" \ "" \ "null" \ "" response = request(:lock, path, headers: headers, xml: xml) return response unless response.is_a?(Response) return response unless blk && response.status == 200 lock_token = response.headers["lock-token"] begin blk.call(response) ensure unlock(path, lock_token) end end def unlock(path, lock_token) request(:unlock, path, headers: { "lock-token" => lock_token }) end def mkcol(dir) request(:mkcol, dir) end def propfind(path, xml = nil) body = case xml when :acl '' \ "" when nil '' else xml end request(:propfind, path, headers: { "depth" => "1" }, xml: body) end def proppatch(path, xml) body = "" \ "#{xml}" request(:proppatch, path, xml: body) end # %i[ orderpatch acl report search] end end register_plugin(:webdav, WebDav) end end