shrine-webdav 0.1.8 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +42 -5
- data/lib/shrine/storage/webdav.rb +31 -8
- data/shrine-webdav.gemspec +3 -3
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4871b3235c1d7ccf38a75dfa6d842b6a9eade6414f9ed93883505055c7849480
|
4
|
+
data.tar.gz: 262b824743eab4952ed8054bda6ca689187d41fbe17db27fefa87371aa756569
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45826788bc58b67b5ee5dad819d1558c0dd7de75aa86419783f59ac4f70973cb1785f7c1431a14eb9f1bc02a6e6c6a4c68689fcc770f9782fa7698479eb730d3
|
7
|
+
data.tar.gz: 4b5c8f96d13d14db918e6b56139a55049fee42d1a74a97b4bbfdeb96de416de3704fed116025204e6ab6a58665a46483d543f8d76b65a6bc8c418a1d88779213
|
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# Shrine::Storage::WebDAV
|
2
2
|
|
3
|
-
Provides a simple WebDAV storage for Shrine.
|
4
|
-
|
5
3
|
[![Build Status](https://travis-ci.org/funbox/shrine-webdav.svg?branch=master)](https://travis-ci.org/funbox/shrine-webdav)
|
6
4
|
|
5
|
+
Provides a simple WebDAV storage for [Shrine](https://shrinerb.com/).
|
6
|
+
|
7
7
|
## Installation
|
8
8
|
|
9
9
|
Add this line to your application's Gemfile:
|
@@ -15,6 +15,7 @@ gem 'shrine-webdav'
|
|
15
15
|
## Usage
|
16
16
|
|
17
17
|
Suppose you have Report model which should be able to store data in a remote WebDAV storage.
|
18
|
+
|
18
19
|
```ruby
|
19
20
|
class Report < ApplicationRecord
|
20
21
|
end
|
@@ -27,7 +28,9 @@ end
|
|
27
28
|
# created_at :datetime not null
|
28
29
|
# updated_at :datetime not null
|
29
30
|
```
|
30
|
-
|
31
|
+
|
32
|
+
Before you start add attributes pointing to remote files to your model you should describe Uploader class:
|
33
|
+
|
31
34
|
```ruby
|
32
35
|
# app/models/reports/report_uploader.rb
|
33
36
|
class ReportUploader < Shrine
|
@@ -40,16 +43,20 @@ class ReportUploader < Shrine
|
|
40
43
|
end
|
41
44
|
end
|
42
45
|
```
|
46
|
+
|
43
47
|
You don't have to override method `generate_location`, but if you didn't you would have random file names.
|
44
48
|
|
45
49
|
Now you can add the attributes:
|
50
|
+
|
46
51
|
```ruby
|
47
52
|
class Report < ApplicationRecord
|
48
53
|
include ReportUploader::Attachment.new(:pdf)
|
49
54
|
include ReportUploader::Attachment.new(:xls)
|
50
55
|
end
|
51
56
|
```
|
57
|
+
|
52
58
|
Note corresponding migrations:
|
59
|
+
|
53
60
|
```ruby
|
54
61
|
class AddFileAttributes < ActiveRecord::Migration[5.1]
|
55
62
|
def change
|
@@ -60,6 +67,7 @@ end
|
|
60
67
|
```
|
61
68
|
|
62
69
|
Create file `shrine.rb` in `config/initializers/` to configure WebDAV storage:
|
70
|
+
|
63
71
|
```ruby
|
64
72
|
# config/initializers/shrine.rb
|
65
73
|
require 'shrine'
|
@@ -72,6 +80,7 @@ Shrine.storages = {
|
|
72
80
|
```
|
73
81
|
|
74
82
|
Now you can use your virtual attributes `pdf` and `xls` like this:
|
83
|
+
|
75
84
|
```ruby
|
76
85
|
report = Report.new(name: 'Senseless report')
|
77
86
|
|
@@ -88,18 +97,46 @@ report.xls = File.open('sample.xls')
|
|
88
97
|
report.save
|
89
98
|
```
|
90
99
|
|
100
|
+
Gem also supports http options `timeout` and `basic auth` Basic usage:
|
101
|
+
|
102
|
+
```
|
103
|
+
Shrine::Storage::WebDAV.new(
|
104
|
+
host: 'http://webdav-server.com',
|
105
|
+
prefix: 'your_project/store',
|
106
|
+
http_options: {
|
107
|
+
basic_auth: { user: 'user', pass: 'pass' },
|
108
|
+
timeout: { connect: 5, write: 2, read: 10 }
|
109
|
+
}
|
110
|
+
)
|
111
|
+
```
|
112
|
+
|
113
|
+
You can also use global timeouts like this:
|
114
|
+
|
115
|
+
```
|
116
|
+
Shrine::Storage::WebDAV.new(
|
117
|
+
host: 'http://webdav-server.com',
|
118
|
+
prefix: 'your_project/store',
|
119
|
+
http_options: {
|
120
|
+
timeout: 3
|
121
|
+
}
|
122
|
+
)
|
123
|
+
```
|
124
|
+
|
91
125
|
## Development
|
92
126
|
|
93
127
|
After checking out the repo, run `bundle install` to install dependencies. Then, run `rake spec` to run the tests.
|
94
128
|
|
95
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
129
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
130
|
+
|
131
|
+
To release a new version, update the version number in `shrine-webdav.gemspec`, and then run `bundle exec rake release`,
|
132
|
+
which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
96
133
|
|
97
134
|
## Contributing
|
98
135
|
|
99
136
|
Bug reports and pull requests are welcome on GitHub at https://github.com/funbox/shrine-webdav. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
100
137
|
|
101
|
-
|
102
138
|
## License
|
103
139
|
|
104
140
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
105
141
|
|
142
|
+
[![Sponsored by FunBox](https://funbox.ru/badges/sponsored_by_funbox_centered.svg)](https://funbox.ru)
|
@@ -5,11 +5,12 @@ require 'down/http'
|
|
5
5
|
class Shrine
|
6
6
|
module Storage
|
7
7
|
class WebDAV
|
8
|
-
def initialize(host:, prefix: nil, upload_options: {})
|
8
|
+
def initialize(host:, prefix: nil, upload_options: {}, http_options: {})
|
9
9
|
@host = host
|
10
10
|
@prefix = prefix
|
11
11
|
@prefixed_host = path(@host, @prefix)
|
12
12
|
@upload_options = upload_options
|
13
|
+
@http_options = http_options
|
13
14
|
end
|
14
15
|
|
15
16
|
def upload(io, id, shrine_metadata: {}, **upload_options)
|
@@ -18,21 +19,26 @@ class Shrine
|
|
18
19
|
put(id, io)
|
19
20
|
end
|
20
21
|
|
21
|
-
def url(id, **options)
|
22
|
-
path(@
|
22
|
+
def url(id, host: nil, **options)
|
23
|
+
base_url = path(host || @host, options[:prefix] || @prefix)
|
24
|
+
path(base_url, id)
|
23
25
|
end
|
24
26
|
|
25
27
|
def open(id)
|
26
|
-
Down::Http.open(path(@prefixed_host, id))
|
28
|
+
Down::Http.open(path(@prefixed_host, id)) do |client|
|
29
|
+
client.timeout(timeout) if http_timeout
|
30
|
+
client.basic_auth(http_basic_auth) if http_basic_auth
|
31
|
+
client
|
32
|
+
end
|
27
33
|
end
|
28
34
|
|
29
35
|
def exists?(id)
|
30
|
-
response =
|
36
|
+
response = http_client.head(path(@prefixed_host, id))
|
31
37
|
(200..299).cover?(response.code.to_i)
|
32
38
|
end
|
33
39
|
|
34
40
|
def delete(id)
|
35
|
-
|
41
|
+
http_client.delete(path(@prefixed_host, id))
|
36
42
|
end
|
37
43
|
|
38
44
|
private
|
@@ -45,7 +51,7 @@ class Shrine
|
|
45
51
|
|
46
52
|
def put(id, io)
|
47
53
|
uri = path(@prefixed_host, id)
|
48
|
-
response =
|
54
|
+
response = http_client.put(uri, body: io)
|
49
55
|
return if (200..299).cover?(response.code.to_i)
|
50
56
|
raise Error, "uploading of #{uri} failed, the server response was #{response}"
|
51
57
|
end
|
@@ -73,12 +79,29 @@ class Shrine
|
|
73
79
|
dirs << "#{dirs[-1]}/#{dir}"
|
74
80
|
end
|
75
81
|
dirs.each do |dir|
|
76
|
-
response =
|
82
|
+
response = http_client.request(:mkcol, "#{host}#{dir}")
|
77
83
|
unless (200..301).cover?(response.code.to_i)
|
78
84
|
raise Error, "creation of directory #{host}#{dir} failed, the server response was #{response}"
|
79
85
|
end
|
80
86
|
end
|
81
87
|
end
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
def http_client
|
92
|
+
client = HTTP
|
93
|
+
client = client.timeout(http_timeout) if http_timeout
|
94
|
+
client = client.basic_auth(http_basic_auth) if http_basic_auth
|
95
|
+
client
|
96
|
+
end
|
97
|
+
|
98
|
+
def http_timeout
|
99
|
+
@http_options.fetch(:timeout, false)
|
100
|
+
end
|
101
|
+
|
102
|
+
def http_basic_auth
|
103
|
+
@http_options.fetch(:basic_auth, false)
|
104
|
+
end
|
82
105
|
end
|
83
106
|
end
|
84
107
|
end
|
data/shrine-webdav.gemspec
CHANGED
@@ -3,9 +3,9 @@ $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.
|
7
|
-
spec.authors = ['Ivan Kushmantsev']
|
8
|
-
spec.email = ['i.kushmantsev@fun-box.ru']
|
6
|
+
spec.version = '0.2.0'
|
7
|
+
spec.authors = ['Ivan Kushmantsev', 'Dmitry Efimov']
|
8
|
+
spec.email = ['i.kushmantsev@fun-box.ru', 'tuwilof@gmail.com']
|
9
9
|
|
10
10
|
spec.summary = 'Provides a simple WebDAV storage for Shrine.'
|
11
11
|
spec.description = 'Provides a simple WebDAV storage for Shrine.'
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shrine-webdav
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Kushmantsev
|
8
|
+
- Dmitry Efimov
|
8
9
|
autorequire:
|
9
10
|
bindir: exe
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2021-02-10 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: shrine
|
@@ -111,6 +112,7 @@ dependencies:
|
|
111
112
|
description: Provides a simple WebDAV storage for Shrine.
|
112
113
|
email:
|
113
114
|
- i.kushmantsev@fun-box.ru
|
115
|
+
- tuwilof@gmail.com
|
114
116
|
executables: []
|
115
117
|
extensions: []
|
116
118
|
extra_rdoc_files: []
|
@@ -144,8 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
146
|
- !ruby/object:Gem::Version
|
145
147
|
version: '0'
|
146
148
|
requirements: []
|
147
|
-
|
148
|
-
rubygems_version: 2.5.2
|
149
|
+
rubygems_version: 3.0.3
|
149
150
|
signing_key:
|
150
151
|
specification_version: 4
|
151
152
|
summary: Provides a simple WebDAV storage for Shrine.
|