Class: Shrine::Storage::WebDAV
- Inherits:
-
Object
- Object
- Shrine::Storage::WebDAV
- Defined in:
- lib/shrine/storage/webdav.rb
Instance Method Summary collapse
- #delete(id) ⇒ Object
- #exists?(id) ⇒ Boolean
-
#initialize(host:, prefix: nil, upload_options: {}, http_options: {}) ⇒ WebDAV
constructor
A new instance of WebDAV.
- #open(id, **options) ⇒ Object
- #upload(io, id, shrine_metadata: {}, **upload_options) ⇒ Object
- #url(id, host: nil, **options) ⇒ Object
Constructor Details
#initialize(host:, prefix: nil, upload_options: {}, http_options: {}) ⇒ WebDAV
Returns a new instance of WebDAV.
8 9 10 11 12 13 14 |
# File 'lib/shrine/storage/webdav.rb', line 8 def initialize(host:, prefix: nil, upload_options: {}, http_options: {}) @host = host @prefix = prefix @prefixed_host = path(@host, @prefix) @upload_options = @http_options = end |
Instance Method Details
#delete(id) ⇒ Object
40 41 42 |
# File 'lib/shrine/storage/webdav.rb', line 40 def delete(id) http_client.delete(path(@prefixed_host, id)) end |
#exists?(id) ⇒ Boolean
35 36 37 38 |
# File 'lib/shrine/storage/webdav.rb', line 35 def exists?(id) response = http_client.head(path(@prefixed_host, id)) (200..299).cover?(response.code.to_i) end |
#open(id, **options) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/shrine/storage/webdav.rb', line 27 def open(id, **) Down::Http.open(path(@prefixed_host, id)) do |client| client.timeout(http_timeout) if http_timeout client.basic_auth(http_basic_auth) if http_basic_auth client end end |
#upload(io, id, shrine_metadata: {}, **upload_options) ⇒ Object
16 17 18 19 20 |
# File 'lib/shrine/storage/webdav.rb', line 16 def upload(io, id, shrine_metadata: {}, **) = () mkpath_to_file(id) unless [:create_full_put_path] put(id, io) end |
#url(id, host: nil, **options) ⇒ Object
22 23 24 25 |
# File 'lib/shrine/storage/webdav.rb', line 22 def url(id, host: nil, **) base_url = path(host || @host, [:prefix] || @prefix) path(base_url, id) end |