shrine-webdav 0.1.6 → 0.2.2

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: d5ddd618b490cf2526c896766ac84bf14a72135e
4
- data.tar.gz: e35fe903e7b1a8a4d0545e80d1bbd878f3845041
2
+ SHA256:
3
+ metadata.gz: 4b25454bd9efb3fce1abfc4e4115c3c088fb2591c1af78e21c5fc0b9a4c12574
4
+ data.tar.gz: 963899e5961c56b89d1616f92a8ae040fd3bb3393a31d24f9dfe86a89e8864b7
5
5
  SHA512:
6
- metadata.gz: 7906aeebc311563ac3f676abfed3451a022db575c288a85854f775dfe35de442054d8f58d11612076dc9449b4b7fd5e04488892581e9594fec44a560530a8ace
7
- data.tar.gz: a5ac489d1a74397ce60b0966ef92c8004cf84b73be25f19567d671659c9cc75ad843b092f2677992eb3cea9f2a0278653351c120eeab2694907ce9333a57eac3
6
+ metadata.gz: 7080026a6684a2306d21f3d6f63dbf8eedf385eed8a4ec0541b4c7971c32810f3a73f40f71f47ecf5945cce9a020304835cf90c3f46913d7e435ac365f096ce9
7
+ data.tar.gz: d0f3a283294ef2b1bd04b5996a963564611b369f5bbe8ae98ac2251782f42fc355b4a463c9820e6fef4372c8ee7c1d028a002875a87fc9bc9121d02036c4f5a9
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
- path(@prefixed_host, 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(http_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)
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.6'
7
- spec.authors = ['Ivan Kushmantsev']
8
- spec.email = ['i.kushmantsev@fun-box.ru']
6
+ spec.version = '0.2.2'
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', '~> 3.0'
24
- spec.add_dependency 'down', '~> 4.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,116 +1,118 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shrine-webdav
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.2
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: 2018-01-23 00:00:00.000000000 Z
12
+ date: 2021-06-28 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: '3.0'
34
+ version: '4.0'
34
35
  type: :runtime
35
36
  prerelease: false
36
37
  version_requirements: !ruby/object:Gem::Requirement
37
38
  requirements:
38
- - - "~>"
39
+ - - ">="
39
40
  - !ruby/object:Gem::Version
40
- version: '3.0'
41
+ version: '4.0'
41
42
  - !ruby/object:Gem::Dependency
42
43
  name: down
43
44
  requirement: !ruby/object:Gem::Requirement
44
45
  requirements:
45
46
  - - "~>"
46
47
  - !ruby/object:Gem::Version
47
- version: '4.0'
48
+ version: '5.0'
48
49
  type: :runtime
49
50
  prerelease: false
50
51
  version_requirements: !ruby/object:Gem::Requirement
51
52
  requirements:
52
53
  - - "~>"
53
54
  - !ruby/object:Gem::Version
54
- version: '4.0'
55
+ version: '5.0'
55
56
  - !ruby/object:Gem::Dependency
56
57
  name: bundler
57
58
  requirement: !ruby/object:Gem::Requirement
58
59
  requirements:
59
60
  - - "~>"
60
61
  - !ruby/object:Gem::Version
61
- version: '1.14'
62
+ version: '2'
62
63
  type: :development
63
64
  prerelease: false
64
65
  version_requirements: !ruby/object:Gem::Requirement
65
66
  requirements:
66
67
  - - "~>"
67
68
  - !ruby/object:Gem::Version
68
- version: '1.14'
69
+ version: '2'
69
70
  - !ruby/object:Gem::Dependency
70
71
  name: rake
71
72
  requirement: !ruby/object:Gem::Requirement
72
73
  requirements:
73
74
  - - "~>"
74
75
  - !ruby/object:Gem::Version
75
- version: '10.0'
76
+ version: '13'
76
77
  type: :development
77
78
  prerelease: false
78
79
  version_requirements: !ruby/object:Gem::Requirement
79
80
  requirements:
80
81
  - - "~>"
81
82
  - !ruby/object:Gem::Version
82
- version: '10.0'
83
+ version: '13'
83
84
  - !ruby/object:Gem::Dependency
84
85
  name: rspec
85
86
  requirement: !ruby/object:Gem::Requirement
86
87
  requirements:
87
88
  - - "~>"
88
89
  - !ruby/object:Gem::Version
89
- version: '3.0'
90
+ version: '3.9'
90
91
  type: :development
91
92
  prerelease: false
92
93
  version_requirements: !ruby/object:Gem::Requirement
93
94
  requirements:
94
95
  - - "~>"
95
96
  - !ruby/object:Gem::Version
96
- version: '3.0'
97
+ version: '3.9'
97
98
  - !ruby/object:Gem::Dependency
98
99
  name: webmock
99
100
  requirement: !ruby/object:Gem::Requirement
100
101
  requirements:
101
- - - ">="
102
+ - - "~>"
102
103
  - !ruby/object:Gem::Version
103
- version: '0'
104
+ version: '3'
104
105
  type: :development
105
106
  prerelease: false
106
107
  version_requirements: !ruby/object:Gem::Requirement
107
108
  requirements:
108
- - - ">="
109
+ - - "~>"
109
110
  - !ruby/object:Gem::Version
110
- version: '0'
111
+ version: '3'
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
- rubyforge_project:
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.