shrine-webdav 0.1.4 → 0.2.0

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
- SHA1:
3
- metadata.gz: 3f3a70e8dcbd91037acc9693ebc51321b8ff4477
4
- data.tar.gz: 40b305052ad5054794f5162ef7289b3c3c8f6aa5
2
+ SHA256:
3
+ metadata.gz: 4871b3235c1d7ccf38a75dfa6d842b6a9eade6414f9ed93883505055c7849480
4
+ data.tar.gz: 262b824743eab4952ed8054bda6ca689187d41fbe17db27fefa87371aa756569
5
5
  SHA512:
6
- metadata.gz: ed332c4ffa6dd2c0b2b79c0c1a8c58864a0373c355a85f96290b96045e9972721dabc077db776302911949f9e81e23de7c1e6d0a75a067373954e584409a16fb
7
- data.tar.gz: cb759c944a2e3e92077cd66251da26455c4ecd16ff8c154109aa70d74b54ca1fb3c6737e10101375f54be7e220d10486e0654591d8d6b4b352e04610abb36cd2
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
- Before you can add attributes pointing to remote files to your model you should describe Uploader class:
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`. To release a new version, update the version number in `shrine-webdav.gemspec`, and then run `bundle exec rake release`, 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).
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
- id
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 = HTTP.head(path(@prefixed_host, id))
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
- HTTP.delete(path(@prefixed_host, id))
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 = HTTP.put(uri, body: io.read)
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 = HTTP.request(:mkcol, "#{host}#{dir}")
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
@@ -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.1.4'
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.'
@@ -19,12 +19,12 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ['lib']
21
21
 
22
- spec.add_dependency 'shrine', '>= 2.0'
23
- spec.add_dependency 'http', '~> 2.2', '>= 2.2.2'
24
- spec.add_dependency 'down', '~> 3.0'
22
+ spec.add_dependency 'shrine', '~> 3.0'
23
+ spec.add_dependency 'http', '~> 4.0'
24
+ spec.add_dependency 'down', '~> 5.0'
25
25
 
26
- spec.add_development_dependency 'bundler', '~> 1.14'
27
- spec.add_development_dependency 'rake', '~> 10.0'
28
- spec.add_development_dependency 'rspec', '~> 3.0'
29
- spec.add_development_dependency 'webmock'
26
+ spec.add_development_dependency 'bundler', '~> 2'
27
+ spec.add_development_dependency 'rake', '~> 13'
28
+ spec.add_development_dependency 'rspec', '~> 3.9'
29
+ spec.add_development_dependency 'webmock', '~> 3'
30
30
  end
metadata CHANGED
@@ -1,122 +1,118 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shrine-webdav
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
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: 2017-06-05 00:00:00.000000000 Z
12
+ date: 2021-02-10 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: shrine
15
16
  requirement: !ruby/object:Gem::Requirement
16
17
  requirements:
17
- - - ">="
18
+ - - "~>"
18
19
  - !ruby/object:Gem::Version
19
- version: '2.0'
20
+ version: '3.0'
20
21
  type: :runtime
21
22
  prerelease: false
22
23
  version_requirements: !ruby/object:Gem::Requirement
23
24
  requirements:
24
- - - ">="
25
+ - - "~>"
25
26
  - !ruby/object:Gem::Version
26
- version: '2.0'
27
+ version: '3.0'
27
28
  - !ruby/object:Gem::Dependency
28
29
  name: http
29
30
  requirement: !ruby/object:Gem::Requirement
30
31
  requirements:
31
32
  - - "~>"
32
33
  - !ruby/object:Gem::Version
33
- version: '2.2'
34
- - - ">="
35
- - !ruby/object:Gem::Version
36
- version: 2.2.2
34
+ version: '4.0'
37
35
  type: :runtime
38
36
  prerelease: false
39
37
  version_requirements: !ruby/object:Gem::Requirement
40
38
  requirements:
41
39
  - - "~>"
42
40
  - !ruby/object:Gem::Version
43
- version: '2.2'
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: 2.2.2
41
+ version: '4.0'
47
42
  - !ruby/object:Gem::Dependency
48
43
  name: down
49
44
  requirement: !ruby/object:Gem::Requirement
50
45
  requirements:
51
46
  - - "~>"
52
47
  - !ruby/object:Gem::Version
53
- version: '3.0'
48
+ version: '5.0'
54
49
  type: :runtime
55
50
  prerelease: false
56
51
  version_requirements: !ruby/object:Gem::Requirement
57
52
  requirements:
58
53
  - - "~>"
59
54
  - !ruby/object:Gem::Version
60
- version: '3.0'
55
+ version: '5.0'
61
56
  - !ruby/object:Gem::Dependency
62
57
  name: bundler
63
58
  requirement: !ruby/object:Gem::Requirement
64
59
  requirements:
65
60
  - - "~>"
66
61
  - !ruby/object:Gem::Version
67
- version: '1.14'
62
+ version: '2'
68
63
  type: :development
69
64
  prerelease: false
70
65
  version_requirements: !ruby/object:Gem::Requirement
71
66
  requirements:
72
67
  - - "~>"
73
68
  - !ruby/object:Gem::Version
74
- version: '1.14'
69
+ version: '2'
75
70
  - !ruby/object:Gem::Dependency
76
71
  name: rake
77
72
  requirement: !ruby/object:Gem::Requirement
78
73
  requirements:
79
74
  - - "~>"
80
75
  - !ruby/object:Gem::Version
81
- version: '10.0'
76
+ version: '13'
82
77
  type: :development
83
78
  prerelease: false
84
79
  version_requirements: !ruby/object:Gem::Requirement
85
80
  requirements:
86
81
  - - "~>"
87
82
  - !ruby/object:Gem::Version
88
- version: '10.0'
83
+ version: '13'
89
84
  - !ruby/object:Gem::Dependency
90
85
  name: rspec
91
86
  requirement: !ruby/object:Gem::Requirement
92
87
  requirements:
93
88
  - - "~>"
94
89
  - !ruby/object:Gem::Version
95
- version: '3.0'
90
+ version: '3.9'
96
91
  type: :development
97
92
  prerelease: false
98
93
  version_requirements: !ruby/object:Gem::Requirement
99
94
  requirements:
100
95
  - - "~>"
101
96
  - !ruby/object:Gem::Version
102
- version: '3.0'
97
+ version: '3.9'
103
98
  - !ruby/object:Gem::Dependency
104
99
  name: webmock
105
100
  requirement: !ruby/object:Gem::Requirement
106
101
  requirements:
107
- - - ">="
102
+ - - "~>"
108
103
  - !ruby/object:Gem::Version
109
- version: '0'
104
+ version: '3'
110
105
  type: :development
111
106
  prerelease: false
112
107
  version_requirements: !ruby/object:Gem::Requirement
113
108
  requirements:
114
- - - ">="
109
+ - - "~>"
115
110
  - !ruby/object:Gem::Version
116
- version: '0'
111
+ version: '3'
117
112
  description: Provides a simple WebDAV storage for Shrine.
118
113
  email:
119
114
  - i.kushmantsev@fun-box.ru
115
+ - tuwilof@gmail.com
120
116
  executables: []
121
117
  extensions: []
122
118
  extra_rdoc_files: []
@@ -150,8 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
146
  - !ruby/object:Gem::Version
151
147
  version: '0'
152
148
  requirements: []
153
- rubyforge_project:
154
- rubygems_version: 2.5.1
149
+ rubygems_version: 3.0.3
155
150
  signing_key:
156
151
  specification_version: 4
157
152
  summary: Provides a simple WebDAV storage for Shrine.