shrine-url 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +28 -11
- data/lib/shrine/storage/url.rb +16 -12
- data/shrine-url.gemspec +2 -2
- metadata +11 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d71adf3e0289f46eb8d37e30fbe150d0437a7ab1c7c5792bac97a422ed06527
|
4
|
+
data.tar.gz: 3975124486888b299ee14fb31f4d33a7da0af429153a8af63db27619140540c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 405e170fe35aa5e1ae3536872bebe93a1a6cbeb38c6f3d4e63de402a59963d31b87ada22d614345ca4bf6c12e06fcd56a21b72cbf9e43e3e9906b2ff94c17852
|
7
|
+
data.tar.gz: 17e3874c33214e2f488d0f8c3527926be6ae49e9125329305dbda9de1b9bb351d917d7e7ca665aa125593f1816c5c4b6a027ef2f5e79c9d367526e1bd49981ef
|
data/README.md
CHANGED
@@ -5,8 +5,8 @@ custom URL.
|
|
5
5
|
|
6
6
|
## Installation
|
7
7
|
|
8
|
-
```
|
9
|
-
gem "shrine-url"
|
8
|
+
```rb
|
9
|
+
gem "shrine-url", "~> 2.0"
|
10
10
|
```
|
11
11
|
|
12
12
|
## Usage
|
@@ -35,18 +35,24 @@ Now you can assign this data as the cached attachment:
|
|
35
35
|
```rb
|
36
36
|
photo = Photo.new(image: data)
|
37
37
|
photo.image #=> #<Shrine::UploadedFile>
|
38
|
-
|
39
38
|
photo.image.url #=> "http://example.com/image.jpg"
|
40
|
-
photo.image.download # Sends a GET request and streams body to Tempfile
|
41
|
-
photo.image.open { |io| } # Sends a GET request and yields `Down::ChunkedIO` ready for reading
|
42
|
-
photo.image.exists? # Sends a HEAD request and returns true if it's 2xx
|
43
|
-
photo.image.delete # Sends a DELETE request
|
44
39
|
```
|
45
40
|
|
46
|
-
No HTTP requests are made
|
47
|
-
|
48
|
-
|
49
|
-
|
41
|
+
No HTTP requests are made when file is assigned (but you can load the
|
42
|
+
`restore_cached_data` Shrine plugin if you want metadata to be extracted on
|
43
|
+
assignment). When this "cached file" is about to be uploaded to a permanent
|
44
|
+
storage, `shrine-url` will download the file from the given URL using [Down].
|
45
|
+
|
46
|
+
```rb
|
47
|
+
uploaded_file.download # Sends a GET request and streams body to Tempfile
|
48
|
+
uploaded_file.open { |io| } # Sends a GET request and yields `Down::ChunkedIO` ready for reading
|
49
|
+
uploaded_file.exists? # Sends a HEAD request and returns true if response status is 2xx
|
50
|
+
uploaded_file.delete # Sends a DELETE request if :delete is set to true
|
51
|
+
```
|
52
|
+
|
53
|
+
By default the `Down::Http` backend will be used for downloading, which is
|
54
|
+
implemented using [HTTP.rb]. You can change the Down backend via the
|
55
|
+
`:downloader` option:
|
50
56
|
|
51
57
|
```rb
|
52
58
|
Shrine::Storage::Url.new(downloader: :wget)
|
@@ -63,6 +69,16 @@ remote URL (like [shrine-cloudinary] or [shrine-uploadcare]), downloading will
|
|
63
69
|
be completely skipped as the permanent storage will use only the URL for
|
64
70
|
uploading the file.
|
65
71
|
|
72
|
+
## Deleting
|
73
|
+
|
74
|
+
Calling `Shrine::UploadedFile#delete` will call `Shrine::Storage::Url#delete`,
|
75
|
+
which for safety doesn't do anything by default. If you want it to make a
|
76
|
+
`DELETE` request to the URL, you can set `:delete` to `true` on initialization:
|
77
|
+
|
78
|
+
```rb
|
79
|
+
Shrine::Storage::Url.new(delete: true)
|
80
|
+
```
|
81
|
+
|
66
82
|
## Advantages and Use Cases
|
67
83
|
|
68
84
|
The main advantage of using `shrine-url` over the `remote_url` Shrine plugin is
|
@@ -98,4 +114,5 @@ you'll need to have Docker installed and running.
|
|
98
114
|
[shrine-cloudinary]: https://github.com/shrinerb/shrine-cloudinary
|
99
115
|
[shrine-uploadcare]: https://github.com/shrinerb/shrine-uploadcare
|
100
116
|
[Down]: https://github.com/janko-m/down
|
117
|
+
[HTTP.rb]: https://github.com/httprb/http
|
101
118
|
[kennethreitz/httpbin]: https://github.com/kennethreitz/httpbin
|
data/lib/shrine/storage/url.rb
CHANGED
@@ -6,14 +6,9 @@ class Shrine
|
|
6
6
|
class Url
|
7
7
|
attr_reader :downloader
|
8
8
|
|
9
|
-
def initialize(downloader: :http)
|
10
|
-
|
11
|
-
|
12
|
-
const_name = downloader.to_s.split("_").map(&:capitalize).join
|
13
|
-
@downloader = Down.const_get(const_name)
|
14
|
-
else
|
15
|
-
@downloader = downloader
|
16
|
-
end
|
9
|
+
def initialize(downloader: :http, delete: false)
|
10
|
+
@downloader = resolve_downloader(downloader)
|
11
|
+
@delete = false
|
17
12
|
end
|
18
13
|
|
19
14
|
def upload(io, id, **)
|
@@ -38,17 +33,26 @@ class Shrine
|
|
38
33
|
end
|
39
34
|
|
40
35
|
def delete(id)
|
41
|
-
request(:delete, id)
|
36
|
+
request(:delete, id) if @delete
|
42
37
|
end
|
43
38
|
|
44
39
|
private
|
45
40
|
|
46
|
-
def request(verb, url, follow: {},
|
47
|
-
options[:follow]
|
48
|
-
options[:headers] = { user_agent: "shrine-url/1.0.2" }.merge(headers)
|
41
|
+
def request(verb, url, follow: {}, **options)
|
42
|
+
options[:follow] = { max_hops: 2 }.merge(follow)
|
49
43
|
|
50
44
|
HTTP.request(verb, url, options)
|
51
45
|
end
|
46
|
+
|
47
|
+
def resolve_downloader(downloader)
|
48
|
+
if downloader.is_a?(Symbol)
|
49
|
+
require "down/#{downloader}"
|
50
|
+
const_name = downloader.to_s.split("_").map(&:capitalize).join
|
51
|
+
Down.const_get(const_name)
|
52
|
+
else
|
53
|
+
downloader
|
54
|
+
end
|
55
|
+
end
|
52
56
|
end
|
53
57
|
end
|
54
58
|
end
|
data/shrine-url.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |gem|
|
2
2
|
gem.name = "shrine-url"
|
3
|
-
gem.version = "2.
|
3
|
+
gem.version = "2.2.0"
|
4
4
|
|
5
5
|
gem.required_ruby_version = ">= 2.1"
|
6
6
|
|
@@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
|
|
15
15
|
|
16
16
|
gem.add_dependency "shrine", ">= 2.0"
|
17
17
|
gem.add_dependency "down", "~> 4.4"
|
18
|
-
gem.add_dependency "http", "
|
18
|
+
gem.add_dependency "http", ">= 3.2", "< 5"
|
19
19
|
|
20
20
|
gem.add_development_dependency "rake"
|
21
21
|
gem.add_development_dependency "minitest"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shrine-url
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Janko Marohnić
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: shrine
|
@@ -42,16 +42,22 @@ dependencies:
|
|
42
42
|
name: http
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '3.2'
|
48
|
+
- - "<"
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '5'
|
48
51
|
type: :runtime
|
49
52
|
prerelease: false
|
50
53
|
version_requirements: !ruby/object:Gem::Requirement
|
51
54
|
requirements:
|
52
|
-
- - "
|
55
|
+
- - ">="
|
53
56
|
- !ruby/object:Gem::Version
|
54
57
|
version: '3.2'
|
58
|
+
- - "<"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '5'
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
62
|
name: rake
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -138,8 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
144
|
- !ruby/object:Gem::Version
|
139
145
|
version: '0'
|
140
146
|
requirements: []
|
141
|
-
|
142
|
-
rubygems_version: 2.7.6
|
147
|
+
rubygems_version: 3.0.1
|
143
148
|
signing_key:
|
144
149
|
specification_version: 4
|
145
150
|
summary: Provides a fake storage which allows you to create a Shrine attachment defined
|