shrine-webdav 0.1.8 → 0.2.3

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: 776491068c8d8bba23c0af394143f2f2659922bb
4
- data.tar.gz: 62b461a2672d70e1fd727a33202dc6fa1382d35f
2
+ SHA256:
3
+ metadata.gz: 1b94c971f0503ab190c12cc37a1acd05ea37aceeb0743e232738fb0d4cce71e8
4
+ data.tar.gz: 72307ce7d57498f170f2dfee12846760189d54be64f9af70c234e8a0f0ba3c3f
5
5
  SHA512:
6
- metadata.gz: 92fef1a7062da132cc59cd672b7268a3badf9585d3ff23f9e1db16e4932cd4ce0a8259606fb5985b0530fe4ea2d0bd88da645973f33d1bd3c70f752fc35c83f7
7
- data.tar.gz: 6d43c5aadac016760b66e97e6f6f0c3dd88027ebaaf319675af6ffa596d501adc657c3700cfeca4fd600e72d6c3ba41d1bef5ccd6eb5ee1f3d5c8eb6e83eabcd
6
+ metadata.gz: d5e7e373cc011d26270ef23f772e1d0b1788d22832da57e5a7eefdb55c76ae3466ba642e9415e821a0e40b752602b28f3847beb4ae78dec4a1190f6f7a8dd81b
7
+ data.tar.gz: a644e2f04fe7d8b8ef9170d03716e37ce9d2abeef0193a654b4c5e9a35011a395411a88cf72e0db3709e7ef91e663a6831862d29b6ee14a900a20f645831e3ea
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
- def open(id)
26
- Down::Http.open(path(@prefixed_host, id))
27
+ def open(id, **options)
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.8'
7
- spec.authors = ['Ivan Kushmantsev']
8
- spec.email = ['i.kushmantsev@fun-box.ru']
6
+ spec.version = '0.2.3'
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.'
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.require_paths = ['lib']
21
21
 
22
22
  spec.add_dependency 'shrine', '~> 3.0'
23
- spec.add_dependency 'http', '~> 4.0'
23
+ spec.add_dependency 'http', '>= 4.0'
24
24
  spec.add_dependency 'down', '~> 5.0'
25
25
 
26
26
  spec.add_development_dependency 'bundler', '~> 2'
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.1.8
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Kushmantsev
8
- autorequire:
8
+ - Dmitry Efimov
9
+ autorequire:
9
10
  bindir: exe
10
11
  cert_chain: []
11
- date: 2019-12-16 00:00:00.000000000 Z
12
+ date: 2021-10-19 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: shrine
@@ -28,14 +29,14 @@ dependencies:
28
29
  name: http
29
30
  requirement: !ruby/object:Gem::Requirement
30
31
  requirements:
31
- - - "~>"
32
+ - - ">="
32
33
  - !ruby/object:Gem::Version
33
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
41
  version: '4.0'
41
42
  - !ruby/object:Gem::Dependency
@@ -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: []
@@ -129,7 +131,7 @@ homepage: https://github.com/funbox/shrine-webdav
129
131
  licenses:
130
132
  - MIT
131
133
  metadata: {}
132
- post_install_message:
134
+ post_install_message:
133
135
  rdoc_options: []
134
136
  require_paths:
135
137
  - lib
@@ -144,9 +146,8 @@ 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
- signing_key:
149
+ rubygems_version: 3.0.3
150
+ signing_key:
150
151
  specification_version: 4
151
152
  summary: Provides a simple WebDAV storage for Shrine.
152
153
  test_files: []