shrine-webdav 0.1.2 → 0.1.3
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.
- checksums.yaml +4 -4
- data/lib/shrine/storage/webdav.rb +18 -12
- data/shrine-webdav.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f33b8bdebb3c93cadde0cf85989b55f7bceeb44e
|
4
|
+
data.tar.gz: 7676d1394a2038d41a04eaf6508081335038e410
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2cf2c1e6c2839389c2f19cecde93a2bbd5e8ebca58ef6f69fae5e7ca0e532aec0b676791b0c22867ed1fa63e24b4dcdbc3bb901d76405f7b4dfb6d9d838e93f9
|
7
|
+
data.tar.gz: 9a3009956f3d585824764dad2681095989967349665b1a2ab4b443d0ad380927b1d559992cb3ac262fc8110674a4d58904d11e528b9ee6768c15caea1e3bb893
|
@@ -7,15 +7,16 @@ class Shrine
|
|
7
7
|
class WebDAV
|
8
8
|
def initialize(host:, prefix: nil)
|
9
9
|
@host = host
|
10
|
-
|
11
|
-
@
|
10
|
+
@prefix = prefix
|
11
|
+
@prefixed_host = path(@host, @prefix)
|
12
12
|
end
|
13
13
|
|
14
14
|
def upload(io, id, shrine_metadata: {}, **upload_options)
|
15
15
|
mkpath_to_file(id)
|
16
|
-
|
16
|
+
uri = path(@prefixed_host, id)
|
17
|
+
response = HTTP.put(uri, body: io.read)
|
17
18
|
return if (200..299).cover?(response.code.to_i)
|
18
|
-
raise Error, "uploading of #{
|
19
|
+
raise Error, "uploading of #{uri} failed, the server response was #{response}"
|
19
20
|
end
|
20
21
|
|
21
22
|
def url(id, **options)
|
@@ -23,41 +24,46 @@ class Shrine
|
|
23
24
|
end
|
24
25
|
|
25
26
|
def open(id)
|
26
|
-
Down::Http.open(path(@
|
27
|
+
Down::Http.open(path(@prefixed_host, id))
|
27
28
|
end
|
28
29
|
|
29
30
|
def exists?(id)
|
30
|
-
response = HTTP.head(path(@
|
31
|
+
response = HTTP.head(path(@prefixed_host, id))
|
31
32
|
(200..299).cover?(response.code.to_i)
|
32
33
|
end
|
33
34
|
|
34
35
|
def delete(id)
|
35
|
-
HTTP.delete(path(@
|
36
|
+
HTTP.delete(path(@prefixed_host, id))
|
36
37
|
end
|
37
38
|
|
38
39
|
private
|
39
40
|
|
40
41
|
def path(host, uri)
|
41
|
-
[host, uri].compact.join('/')
|
42
|
+
(uri.nil? || uri.empty?) ? host : [host, uri].compact.join('/')
|
42
43
|
end
|
43
44
|
|
44
45
|
def mkpath_to_file(path_to_file)
|
46
|
+
@prefix_created ||= create_prefix
|
45
47
|
last_slash = path_to_file.rindex('/')
|
46
48
|
if last_slash
|
47
49
|
path = path_to_file[0..last_slash]
|
48
|
-
mkpath(path)
|
50
|
+
mkpath(@prefixed_host, path)
|
49
51
|
end
|
50
52
|
end
|
51
53
|
|
52
|
-
def
|
54
|
+
def create_prefix
|
55
|
+
mkpath(@host, @prefix) unless @prefix.nil? || @prefix.empty?
|
56
|
+
end
|
57
|
+
|
58
|
+
def mkpath(host, path)
|
53
59
|
dirs = []
|
54
60
|
path.split('/').each do |dir|
|
55
61
|
dirs << "#{dirs[-1]}/#{dir}"
|
56
62
|
end
|
57
63
|
dirs.each do |dir|
|
58
|
-
response = HTTP.request(:mkcol, "#{
|
64
|
+
response = HTTP.request(:mkcol, "#{host}#{dir}")
|
59
65
|
unless (200..301).cover?(response.code.to_i)
|
60
|
-
raise Error, "creation of directory #{
|
66
|
+
raise Error, "creation of directory #{host}#{dir} failed, the server response was #{response}"
|
61
67
|
end
|
62
68
|
end
|
63
69
|
end
|
data/shrine-webdav.gemspec
CHANGED