shrine-webdav 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f33b8bdebb3c93cadde0cf85989b55f7bceeb44e
4
- data.tar.gz: 7676d1394a2038d41a04eaf6508081335038e410
3
+ metadata.gz: 3f3a70e8dcbd91037acc9693ebc51321b8ff4477
4
+ data.tar.gz: 40b305052ad5054794f5162ef7289b3c3c8f6aa5
5
5
  SHA512:
6
- metadata.gz: 2cf2c1e6c2839389c2f19cecde93a2bbd5e8ebca58ef6f69fae5e7ca0e532aec0b676791b0c22867ed1fa63e24b4dcdbc3bb901d76405f7b4dfb6d9d838e93f9
7
- data.tar.gz: 9a3009956f3d585824764dad2681095989967349665b1a2ab4b443d0ad380927b1d559992cb3ac262fc8110674a4d58904d11e528b9ee6768c15caea1e3bb893
6
+ metadata.gz: ed332c4ffa6dd2c0b2b79c0c1a8c58864a0373c355a85f96290b96045e9972721dabc077db776302911949f9e81e23de7c1e6d0a75a067373954e584409a16fb
7
+ data.tar.gz: cb759c944a2e3e92077cd66251da26455c4ecd16ff8c154109aa70d74b54ca1fb3c6737e10101375f54be7e220d10486e0654591d8d6b4b352e04610abb36cd2
@@ -5,18 +5,17 @@ require 'down/http'
5
5
  class Shrine
6
6
  module Storage
7
7
  class WebDAV
8
- def initialize(host:, prefix: nil)
8
+ def initialize(host:, prefix: nil, upload_options: {})
9
9
  @host = host
10
10
  @prefix = prefix
11
11
  @prefixed_host = path(@host, @prefix)
12
+ @upload_options = upload_options
12
13
  end
13
14
 
14
15
  def upload(io, id, shrine_metadata: {}, **upload_options)
15
- mkpath_to_file(id)
16
- uri = path(@prefixed_host, id)
17
- response = HTTP.put(uri, body: io.read)
18
- return if (200..299).cover?(response.code.to_i)
19
- raise Error, "uploading of #{uri} failed, the server response was #{response}"
16
+ options = current_options(upload_options)
17
+ mkpath_to_file(id) unless options[:create_full_put_path]
18
+ put(id, io)
20
19
  end
21
20
 
22
21
  def url(id, **options)
@@ -38,6 +37,19 @@ class Shrine
38
37
 
39
38
  private
40
39
 
40
+ def current_options(upload_options)
41
+ options = {}
42
+ options.update(@upload_options)
43
+ options.update(upload_options)
44
+ end
45
+
46
+ def put(id, io)
47
+ uri = path(@prefixed_host, id)
48
+ response = HTTP.put(uri, body: io.read)
49
+ return if (200..299).cover?(response.code.to_i)
50
+ raise Error, "uploading of #{uri} failed, the server response was #{response}"
51
+ end
52
+
41
53
  def path(host, uri)
42
54
  (uri.nil? || uri.empty?) ? host : [host, uri].compact.join('/')
43
55
  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.3'
6
+ spec.version = '0.1.4'
7
7
  spec.authors = ['Ivan Kushmantsev']
8
8
  spec.email = ['i.kushmantsev@fun-box.ru']
9
9
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shrine-webdav
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Kushmantsev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-02 00:00:00.000000000 Z
11
+ date: 2017-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: shrine