net_dav 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/net/dav.rb +47 -4
- data/net_dav.gemspec +3 -2
- data/net_dav.gif +0 -0
- data/spec/integration/net_dav_spec.rb +28 -0
- metadata +5 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
data/lib/net/dav.rb
CHANGED
@@ -362,9 +362,35 @@ module Net #:nodoc:
|
|
362
362
|
@handler.pass = pass
|
363
363
|
end
|
364
364
|
|
365
|
-
|
365
|
+
# Perform a PROPFIND request
|
366
|
+
#
|
367
|
+
# Example:
|
368
|
+
#
|
369
|
+
# Basic propfind:
|
370
|
+
#
|
371
|
+
# properties = propfind('/path/')
|
372
|
+
#
|
373
|
+
# Get ACL for resource:
|
374
|
+
#
|
375
|
+
# properties = propfind('/path/', :acl)
|
376
|
+
#
|
377
|
+
# Custom propfind:
|
378
|
+
#
|
379
|
+
# properties = propfind('/path/', '<?xml version="1.0" encoding="utf-8"?>...')
|
380
|
+
#
|
381
|
+
# See http://webdav.org/specs/rfc3744.html#rfc.section.5.9 for more on
|
382
|
+
# how to retrieve access control properties.
|
383
|
+
def propfind(path,*options)
|
366
384
|
headers = {'Depth' => '1'}
|
367
|
-
|
385
|
+
if(options[0] == :acl)
|
386
|
+
body = '<?xml version="1.0" encoding="utf-8" ?><D:propfind xmlns:D="DAV:"><D:prop><D:owner/>' +
|
387
|
+
'<D:supported-privilege-set/><D:current-user-privilege-set/><D:acl/></D:prop></D:propfind>'
|
388
|
+
else
|
389
|
+
body = options[0]
|
390
|
+
end
|
391
|
+
if(!body)
|
392
|
+
body = '<?xml version="1.0" encoding="utf-8"?><DAV:propfind xmlns:DAV="DAV:"><DAV:allprop/></DAV:propfind>'
|
393
|
+
end
|
368
394
|
res = @handler.request(:propfind, path, body, headers)
|
369
395
|
Nokogiri::XML.parse(res.body)
|
370
396
|
end
|
@@ -399,14 +425,14 @@ module Net #:nodoc:
|
|
399
425
|
namespaces = {'x' => "DAV:"}
|
400
426
|
begin
|
401
427
|
doc = propfind(path)
|
402
|
-
rescue Net::
|
428
|
+
rescue Net::ProtocolError => e
|
403
429
|
msg = e.to_s + ": " + path.to_s
|
404
430
|
if(options[:suppress_errors])then
|
405
431
|
# Ignore dir if propfind returns an error
|
406
432
|
warn("Warning: " + msg)
|
407
433
|
return nil
|
408
434
|
else
|
409
|
-
raise
|
435
|
+
raise e.class.new(msg, nil)
|
410
436
|
end
|
411
437
|
end
|
412
438
|
path.sub!(/\/$/, '')
|
@@ -548,6 +574,23 @@ module Net #:nodoc:
|
|
548
574
|
Nokogiri::XML.parse(res.body)
|
549
575
|
end
|
550
576
|
|
577
|
+
# Returns true if resource exists on server.
|
578
|
+
#
|
579
|
+
# Example:
|
580
|
+
# dav.exists?('https://www.example.com/collection/') => true
|
581
|
+
# dav.exists?('/collection/') => true
|
582
|
+
def exists?(path)
|
583
|
+
path = @uri.merge(path).path
|
584
|
+
headers = {'Depth' => '1'}
|
585
|
+
body = '<?xml version="1.0" encoding="utf-8"?><DAV:propfind xmlns:DAV="DAV:"><DAV:allprop/></DAV:propfind>'
|
586
|
+
begin
|
587
|
+
res = @handler.request(:propfind, path, body, headers)
|
588
|
+
rescue
|
589
|
+
return false
|
590
|
+
end
|
591
|
+
return (res.is_a? Net::HTTPSuccess)
|
592
|
+
end
|
593
|
+
|
551
594
|
# Makes a new directory (collection)
|
552
595
|
def mkdir(path)
|
553
596
|
path = @uri.merge(path).path
|
data/net_dav.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{net_dav}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.5.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Miron Cuperman", "Thomas Flemming"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2010-03-12}
|
13
13
|
s.default_executable = %q{dav}
|
14
14
|
s.description = %q{WebDAV client library in the style of Net::HTTP, using Net::HTTP and libcurl, if installed}
|
15
15
|
s.email = %q{c1.github@niftybox.net}
|
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
|
|
29
29
|
"lib/net/dav.rb",
|
30
30
|
"lib/net/dav/item.rb",
|
31
31
|
"net_dav.gemspec",
|
32
|
+
"net_dav.gif",
|
32
33
|
"script/multi-test",
|
33
34
|
"spec/fixtures/file.html",
|
34
35
|
"spec/integration/net_dav_spec.rb",
|
data/net_dav.gif
ADDED
Binary file
|
@@ -22,6 +22,22 @@ describe "Net::Dav" do
|
|
22
22
|
@props.should match(/200 OK/)
|
23
23
|
end
|
24
24
|
|
25
|
+
it "should raise if finding non-existent path" do
|
26
|
+
dav = Net::DAV.new("http://localhost:10080/")
|
27
|
+
lambda do
|
28
|
+
dav.find("/") do |item|
|
29
|
+
end
|
30
|
+
end.should_not raise_error
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should raise if finding non-existent path" do
|
34
|
+
dav = Net::DAV.new("http://localhost:10080/")
|
35
|
+
lambda do
|
36
|
+
dav.find("/asdf") do |item|
|
37
|
+
end
|
38
|
+
end.should raise_error Net::HTTPServerException
|
39
|
+
end
|
40
|
+
|
25
41
|
it "should write files to webdav server" do
|
26
42
|
dav = Net::DAV.new("http://localhost:10080/")
|
27
43
|
@props = find_props_or_error(dav, "/new_file.html")
|
@@ -78,6 +94,18 @@ describe "Net::Dav" do
|
|
78
94
|
@props.should match(/200 OK/i)
|
79
95
|
end
|
80
96
|
|
97
|
+
it "should retrieve acl" do
|
98
|
+
dav = Net::DAV.new("http://localhost:10080/")
|
99
|
+
@props = dav.propfind("/", :acl).to_s
|
100
|
+
@props.should match(/200 OK/i)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should detect if resource or collection exists on server" do
|
104
|
+
dav = Net::DAV.new("http://localhost:10080/")
|
105
|
+
dav.exists?('/file.html').should == true
|
106
|
+
dav.exists?('/totally_unknown_file.html').should == false
|
107
|
+
end
|
108
|
+
|
81
109
|
# proppatch seems to work, but our simple webdav server don't update properties
|
82
110
|
# it "should alter properties on resources on webdav server" do
|
83
111
|
# dav = Net::DAV.new("http://localhost:10080/")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: net_dav
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miron Cuperman
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date:
|
13
|
+
date: 2010-03-12 00:00:00 -08:00
|
14
14
|
default_executable: dav
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -63,6 +63,7 @@ files:
|
|
63
63
|
- lib/net/dav.rb
|
64
64
|
- lib/net/dav/item.rb
|
65
65
|
- net_dav.gemspec
|
66
|
+
- net_dav.gif
|
66
67
|
- script/multi-test
|
67
68
|
- spec/fixtures/file.html
|
68
69
|
- spec/integration/net_dav_spec.rb
|
@@ -99,6 +100,6 @@ signing_key:
|
|
99
100
|
specification_version: 3
|
100
101
|
summary: WebDAV client library in the style of Net::HTTP
|
101
102
|
test_files:
|
102
|
-
- spec/integration/net_dav_spec.rb
|
103
|
-
- spec/integration/webdav_server.rb
|
104
103
|
- spec/spec_helper.rb
|
104
|
+
- spec/integration/webdav_server.rb
|
105
|
+
- spec/integration/net_dav_spec.rb
|