carrierwave-webdav 0.5.0 → 0.6.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 +1 -1
- data/lib/carrierwave/httparty_monkey.rb +10 -1
- data/lib/carrierwave/storage/webdav.rb +2 -2
- data/lib/carrierwave/webdav/file.rb +14 -2
- data/lib/carrierwave/webdav/version.rb +1 -1
- data/spec/lib/webdav_storage_spec.rb +16 -15
- data/spec/supports/helpers.rb +23 -6
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 27f93efb8393806ab738e97c7be04ef421f0c1fbeaaaa2477ad3ddf6dc2b1115
|
4
|
+
data.tar.gz: 89b9a7419294f1c00a7914dab5bfcf31b04df4dbe56b0f29d80462219af595f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4bf66881ba5352d4badb60e2b6ff2a8a66fd1dc014edcfb42bdf0a3ca1db73867c0e93ad89440716c2853de2a241f0c4818778d856fffe932a58e1b053d49c6
|
7
|
+
data.tar.gz: f812070f628a7673683ffa82f1323d8bcb38fcbe7c70e78279a378222f4f2dc70a01b75f1ce33294293ca74303cb6cb9c14ab2f78c98ebeb6f241865e278c633
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# CarrierWave for WebDAV
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/qinix/carrierwave-webdav.png?branch=master)](https://travis-ci.org/qinix/carrierwave-webdav)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/github/qinix/carrierwave-webdav/badge.svg?branch=master)](https://coveralls.io/github/qinix/carrierwave-webdav?branch=master)
|
4
5
|
|
5
6
|
This gem adds support for WebDAV to
|
6
7
|
[CarrierWave](https://github.com/carrierwaveuploader/carrierwave/)
|
@@ -57,4 +58,3 @@ them yourself. In Rails for example, you could use the `send_data` method.
|
|
57
58
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
58
59
|
4. Push to the branch (`git push origin my-new-feature`)
|
59
60
|
5. Create new Pull Request
|
60
|
-
|
@@ -8,6 +8,7 @@ module HTTParty
|
|
8
8
|
|
9
9
|
class Request
|
10
10
|
SupportedHTTPMethods << Net::HTTP::Mkcol
|
11
|
+
SupportedHTTPMethods << Net::HTTP::Propfind
|
11
12
|
end
|
12
13
|
|
13
14
|
module ClassMethods
|
@@ -15,6 +16,11 @@ module HTTParty
|
|
15
16
|
def mkcol(path, options = {}, &block)
|
16
17
|
perform_request Net::HTTP::Mkcol, path, options, &block
|
17
18
|
end
|
19
|
+
|
20
|
+
# Perform a PROPFIND request to a path
|
21
|
+
def propfind(path, options = {}, &block)
|
22
|
+
perform_request Net::HTTP::Propfind, path, options, &block
|
23
|
+
end
|
18
24
|
end
|
19
25
|
|
20
26
|
class Basement
|
@@ -24,5 +30,8 @@ module HTTParty
|
|
24
30
|
def self.mkcol(*args, &block)
|
25
31
|
Basement.mkcol(*args, &block)
|
26
32
|
end
|
27
|
-
end # HTTParty
|
28
33
|
|
34
|
+
def self.propfind(*args, &block)
|
35
|
+
Basement.propfind(*args, &block)
|
36
|
+
end
|
37
|
+
end # HTTParty
|
@@ -16,7 +16,7 @@ module CarrierWave
|
|
16
16
|
#
|
17
17
|
def cache!(file)
|
18
18
|
cached = build_webdav_file(uploader.cache_path)
|
19
|
-
cached.write(file
|
19
|
+
cached.write(file)
|
20
20
|
cached
|
21
21
|
end
|
22
22
|
|
@@ -65,7 +65,7 @@ module CarrierWave
|
|
65
65
|
#
|
66
66
|
def store!(file)
|
67
67
|
stored = build_webdav_file(uploader.store_path)
|
68
|
-
stored.write(file
|
68
|
+
stored.write(file)
|
69
69
|
stored
|
70
70
|
end
|
71
71
|
|
@@ -42,7 +42,16 @@ module CarrierWave
|
|
42
42
|
res = mkcol
|
43
43
|
end
|
44
44
|
|
45
|
-
|
45
|
+
::File.open(file.file, 'rb') do |io|
|
46
|
+
res = HTTParty.put(write_url, options.merge({
|
47
|
+
body_stream: io,
|
48
|
+
headers: {
|
49
|
+
'Transfer-Encoding' => 'chunked',
|
50
|
+
'Content-Type' => file.content_type
|
51
|
+
}
|
52
|
+
}))
|
53
|
+
end
|
54
|
+
|
46
55
|
if res.code != 201 and res.code != 204
|
47
56
|
raise CarrierWave::IntegrityError.new("Can't put a new file: #{res.inspect}")
|
48
57
|
end
|
@@ -50,7 +59,7 @@ module CarrierWave
|
|
50
59
|
end
|
51
60
|
|
52
61
|
def length
|
53
|
-
|
62
|
+
headers.content_length
|
54
63
|
end
|
55
64
|
|
56
65
|
def content_type
|
@@ -99,6 +108,9 @@ module CarrierWave
|
|
99
108
|
end # Make path like a/b/c/t.txt to array ['/a', '/a/b', '/a/b/c']
|
100
109
|
use_server = @write_server ? @write_server : server
|
101
110
|
dirs.each do |dir|
|
111
|
+
# skip if dir already exists
|
112
|
+
next if HTTParty.propfind("#{use_server}#{dir}", options).code == 207
|
113
|
+
|
102
114
|
res = HTTParty.mkcol("#{use_server}#{dir}", options)
|
103
115
|
unless [200, 201, 207, 409].include? res.code
|
104
116
|
raise CarrierWave::IntegrityError.new("Can't create a new collection: #{res.inspect}")
|
@@ -18,6 +18,7 @@ describe CarrierWave::Storage::WebDAV do
|
|
18
18
|
|
19
19
|
@storage = CarrierWave::Storage::WebDAV.new(@uploader)
|
20
20
|
@file = CarrierWave::SanitizedFile.new(file_path('test.txt'))
|
21
|
+
@file.content_type = 'text/plain'
|
21
22
|
|
22
23
|
# NOTE: specs fail with this options
|
23
24
|
#
|
@@ -31,16 +32,16 @@ describe CarrierWave::Storage::WebDAV do
|
|
31
32
|
describe '#cache!' do
|
32
33
|
it 'should cache from WebDAV' do
|
33
34
|
stub_mkcol @cache_uri
|
34
|
-
stub_put @
|
35
|
+
stub_put(@cache_uri, @file.path)
|
35
36
|
webdav_file = @storage.cache!(@file)
|
36
|
-
stub_get @
|
37
|
+
stub_get(@cache_uri, @file.path)
|
37
38
|
expect(@file.read).to eq(webdav_file.read)
|
38
39
|
end
|
39
40
|
end
|
40
41
|
|
41
42
|
describe '#retrieve_from_cache!' do
|
42
43
|
it 'should retreive a cache file from WebDAV' do
|
43
|
-
stub_get @
|
44
|
+
stub_get(@cache_uri, @file.path)
|
44
45
|
webdav_file = @storage.retrieve_from_cache!('tmp_test.txt')
|
45
46
|
expect(@file.read).to eq(webdav_file.read)
|
46
47
|
end
|
@@ -56,17 +57,17 @@ describe CarrierWave::Storage::WebDAV do
|
|
56
57
|
|
57
58
|
it 'should store from WebDAV' do
|
58
59
|
stub_mkcol @uri
|
59
|
-
stub_put @
|
60
|
+
stub_put(@uri, @file.path)
|
60
61
|
webdav_file = @storage.store!(@file)
|
61
|
-
stub_get @
|
62
|
+
stub_get(@uri, @file.path)
|
62
63
|
expect(@file.read).to eq(webdav_file.read)
|
63
64
|
end
|
64
65
|
|
65
66
|
it 'should retrieve a file from WebDAV' do
|
66
67
|
stub_mkcol @uri
|
67
|
-
stub_put @
|
68
|
+
stub_put(@uri, @file.path)
|
68
69
|
webdav_file = @storage.store!(@file)
|
69
|
-
stub_get @
|
70
|
+
stub_get(@uri, @file.path)
|
70
71
|
retrieved_file = @storage.retrieve!(webdav_file)
|
71
72
|
expect(@file.read).to eq(retrieved_file.read)
|
72
73
|
expect(File.basename(@file.path)).to eq(File.basename(retrieved_file.path))
|
@@ -74,7 +75,7 @@ describe CarrierWave::Storage::WebDAV do
|
|
74
75
|
|
75
76
|
it 'should delete a file from WebDAV' do
|
76
77
|
stub_mkcol @uri
|
77
|
-
stub_put @
|
78
|
+
stub_put(@uri, @file.path)
|
78
79
|
webdav_file = @storage.store!(@file)
|
79
80
|
stub_delete @uri
|
80
81
|
expect(Net::HTTPOK).to eq(webdav_file.delete.response.class)
|
@@ -82,23 +83,23 @@ describe CarrierWave::Storage::WebDAV do
|
|
82
83
|
|
83
84
|
it 'should size equal' do
|
84
85
|
stub_mkcol @uri
|
85
|
-
stub_put @
|
86
|
+
stub_put(@uri, @file.path)
|
86
87
|
webdav_file = @storage.store!(@file)
|
87
|
-
|
88
|
+
stub_head(@uri, @file.path)
|
88
89
|
expect(@file.size).to eq(webdav_file.size)
|
89
90
|
end
|
90
91
|
|
91
92
|
it 'assigns file content type to attribute' do
|
92
93
|
stub_mkcol @uri
|
93
|
-
stub_put @
|
94
|
+
stub_put(@uri, @file.path)
|
94
95
|
webdav_file = @storage.store!(@file)
|
95
|
-
stub_head @
|
96
|
+
stub_head(@uri, @file.path)
|
96
97
|
expect(@file.content_type).to eq(webdav_file.content_type)
|
97
98
|
end
|
98
99
|
|
99
100
|
it 'should url equal' do
|
100
101
|
stub_mkcol @uri
|
101
|
-
stub_put @
|
102
|
+
stub_put(@uri, @file.path)
|
102
103
|
webdav_file = @storage.store!(@file)
|
103
104
|
expect("#{@uploader.webdav_server}/#{@uploader.store_path}").to eq(webdav_file.url)
|
104
105
|
end
|
@@ -125,10 +126,10 @@ describe CarrierWave::Storage::WebDAV do
|
|
125
126
|
# secure_uri.password = @uploader.webdav_password
|
126
127
|
|
127
128
|
stub_mkcol secure_uri
|
128
|
-
stub_put
|
129
|
+
stub_put(secure_uri, @file.path)
|
129
130
|
webdav_file = @storage.store!(@file)
|
130
131
|
|
131
|
-
stub_get @
|
132
|
+
stub_get(@uri, @file.path)
|
132
133
|
expect(@file.read).to eq(webdav_file.read)
|
133
134
|
end
|
134
135
|
end
|
data/spec/supports/helpers.rb
CHANGED
@@ -1,22 +1,39 @@
|
|
1
|
+
require 'mime/types'
|
2
|
+
|
1
3
|
module Helpers
|
2
4
|
|
3
5
|
def file_path( *paths )
|
4
6
|
File.expand_path(File.join(File.dirname(__FILE__), '../fixtures', *paths))
|
5
7
|
end
|
6
8
|
|
7
|
-
def
|
9
|
+
def mime_type(path)
|
10
|
+
::MIME::Types.type_for(path).first.to_s
|
11
|
+
end
|
12
|
+
|
13
|
+
def file_response(path)
|
14
|
+
{
|
15
|
+
:status => 200,
|
16
|
+
:body => File.read(path),
|
17
|
+
:headers => {
|
18
|
+
'Content-Type' => mime_type(path),
|
19
|
+
'Content-Length' => File.size(path).to_s
|
20
|
+
}
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def stub_get(url, path)
|
8
25
|
stub_request(:get, url.to_s).
|
9
|
-
to_return(
|
26
|
+
to_return(file_response(path))
|
10
27
|
end
|
11
28
|
|
12
|
-
def stub_head(url)
|
29
|
+
def stub_head(url, path)
|
13
30
|
stub_request(:head, url.to_s).
|
14
|
-
to_return(
|
31
|
+
to_return(file_response(path))
|
15
32
|
end
|
16
33
|
|
17
|
-
def stub_put(url)
|
34
|
+
def stub_put(url, path)
|
18
35
|
stub_request(:put, url.to_s).
|
19
|
-
with(:body =>
|
36
|
+
with(:body => File.read(path)).
|
20
37
|
to_return(:status => 201, :body => '', :headers => {})
|
21
38
|
end
|
22
39
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carrierwave-webdav
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Qinix
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-12-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: carrierwave
|
@@ -82,8 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
84
|
requirements: []
|
85
|
-
|
86
|
-
rubygems_version: 2.5.1
|
85
|
+
rubygems_version: 3.0.3
|
87
86
|
signing_key:
|
88
87
|
specification_version: 4
|
89
88
|
summary: WebDAV support for CarrierWave
|