Module: HTTPX::Plugins::WebDav::InstanceMethods

Defined in:
lib/httpx/plugins/webdav.rb,
sig/plugins/webdav.rbs

Instance Method Summary collapse

Instance Method Details

#copy(src, dest) ⇒ Response, ErrorResponse

sends a COPY WebDav request for src and dest.

Parameters:

  • src (String)
  • dst (String)

Returns:



17
18
19
# File 'lib/httpx/plugins/webdav.rb', line 17

def copy(src, dest)
  request("COPY", src, headers: { "destination" => @options.origin.merge(dest) })
end

#lock(path, timeout: nil) {|response| ... } ⇒ Response, ErrorResponse

sends a LOCK WebDav request for path (for the time set by timeout, when passed). it calls #unlock after the block is executed.

Parameters:

  • path (String)
  • timeout: (interval) (defaults to: nil)

Yields:

Yield Parameters:

Yield Returns:

  • (void)

Returns:



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/httpx/plugins/webdav.rb', line 28

def lock(path, timeout: nil, &blk)
  headers = {}
  headers["timeout"] = if timeout && timeout.positive?
    "Second-#{timeout}"
  else
    "Infinite, Second-4100000000"
  end
  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:owner>null</D:owner>" \
        "</D:lockinfo>"
  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

  response
end

#mkcol(dir) ⇒ Response

sends a MKCOL WebDav request for dir.

Parameters:

  • dir (String)

Returns:



64
65
66
# File 'lib/httpx/plugins/webdav.rb', line 64

def mkcol(dir)
  request("MKCOL", dir)
end

#move(src, dest) ⇒ Response, ErrorResponse

sends a MOVE WebDav request for src and dest.

Parameters:

  • src (String)
  • dst (String)

Returns:



22
23
24
# File 'lib/httpx/plugins/webdav.rb', line 22

def move(src, dest)
  request("MOVE", src, headers: { "destination" => @options.origin.merge(dest) })
end

#propfind(path, xml = nil) ⇒ Response

sends a PROPFIND WebDav request for path.

Parameters:

  • path (String)
  • xml (?(:acl | String)) (defaults to: nil)

Returns:



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/httpx/plugins/webdav.rb', line 69

def propfind(path, xml = nil)
  body = case xml
         when :acl
           '<?xml version="1.0" encoding="utf-8" ?><D:propfind xmlns:D="DAV:"><D:prop><D:owner/>' \
           "<D:supported-privilege-set/><D:current-user-privilege-set/><D:acl/></D:prop></D:propfind>"
         when nil
           '<?xml version="1.0" encoding="utf-8"?><DAV:propfind xmlns:DAV="DAV:"><DAV:allprop/></DAV:propfind>'
         else
           xml
  end

  request("PROPFIND", path, headers: { "depth" => "1" }, xml: body)
end

#proppatch(path, xml) ⇒ Response

sends a PROPPATCH WebDav request for path.

Parameters:

  • path (String)
  • xml (String)

Returns:



84
85
86
87
88
# File 'lib/httpx/plugins/webdav.rb', line 84

def proppatch(path, xml)
  body = "<?xml version=\"1.0\"?>" \
         "<D:propertyupdate xmlns:D=\"DAV:\" xmlns:Z=\"http://ns.example.com/standards/z39.50/\">#{xml}</D:propertyupdate>"
  request("PROPPATCH", path, xml: body)
end

#unlock(path, lock_token) ⇒ Response, ErrorResponse

sends a UNLOCK WebDav request for path, using the given lock_token.

Parameters:

  • path (String)
  • lock_token (String, nil)

Returns:



59
60
61
# File 'lib/httpx/plugins/webdav.rb', line 59

def unlock(path, lock_token)
  request("UNLOCK", path, headers: { "lock-token" => lock_token })
end