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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd2b1d205b1bf8156e9e2012af459a4006ca6b3c
4
- data.tar.gz: e933550a6bf5b00dd2913f2c6452a9b07c36b53a
3
+ metadata.gz: f33b8bdebb3c93cadde0cf85989b55f7bceeb44e
4
+ data.tar.gz: 7676d1394a2038d41a04eaf6508081335038e410
5
5
  SHA512:
6
- metadata.gz: c3ecbce7d30601bab187544f8654be9cb7599a80ae9f1e7bac60d79035b34359e2a001df306686c30ce070490b4f6972b6b1209f7d97f164ff3c683157a1533a
7
- data.tar.gz: 516e0c8ebeba3067e1e0b5903e76512d19dee824f8ab97e640a5a4181c2e90c27da32c8ae19a3fcf1ece159e3a9e92ab23a7ed4b72897eeffd5ff213b9b72430
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
- mkpath(prefix) unless prefix.nil? || prefix.empty?
11
- @host = path(host, prefix)
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
- response = HTTP.put(path(@host, id), body: io.read)
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 #{path(@host, id)} failed, the server response was #{response}"
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(@host, id))
27
+ Down::Http.open(path(@prefixed_host, id))
27
28
  end
28
29
 
29
30
  def exists?(id)
30
- response = HTTP.head(path(@host, id))
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(@host, id))
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 mkpath(path)
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, "#{@host}#{dir}")
64
+ response = HTTP.request(:mkcol, "#{host}#{dir}")
59
65
  unless (200..301).cover?(response.code.to_i)
60
- raise Error, "creation of directory #{@host}#{dir} failed, the server response was #{response}"
66
+ raise Error, "creation of directory #{host}#{dir} failed, the server response was #{response}"
61
67
  end
62
68
  end
63
69
  end
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = 'shrine-webdav'
6
- spec.version = '0.1.2'
6
+ spec.version = '0.1.3'
7
7
  spec.authors = ['Ivan Kushmantsev']
8
8
  spec.email = ['i.kushmantsev@fun-box.ru']
9
9
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shrine-webdav
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Kushmantsev