shrine-url 0.1.0 → 0.1.1
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 +4 -4
- data/README.md +36 -10
- data/lib/shrine/storage/url.rb +3 -1
- data/shrine-url.gemspec +2 -2
- metadata +4 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5da2ca4ce8958271c422287cc7b8ee6fe7999526
|
4
|
+
data.tar.gz: 1c9b02222b55b30bb63cb333fd73c4dc4e8951ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cfe2bf454cbc951f7f7804a91098d5bb610b165810c4ca2370cf70d52e91519be8d643496b5b0937ca44ab611d9364b4139fc65e6971c149d8589d62a870a01f
|
7
|
+
data.tar.gz: d085d268244090667a609831df75949ff1ea9569f0a2c24104b2ab9a26d0de0e9c7e5db4613d95cb8d613392bbbd1644da6e0fe3e2b9d7995f201b6dc0a029a0
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Shrine::Storage::Url
|
2
2
|
|
3
|
-
Provides a
|
4
|
-
|
3
|
+
Provides a "storage" which allows you to save uploaded files defined by a
|
4
|
+
custom URL.
|
5
5
|
|
6
6
|
## Installation
|
7
7
|
|
@@ -11,20 +11,45 @@ gem "shrine-url"
|
|
11
11
|
|
12
12
|
## Usage
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
```rb
|
15
|
+
require "shrine/storage/url"
|
16
|
+
|
17
|
+
Shrine.storages[:cache] = Shrine::Storage::Url.new
|
18
|
+
```
|
16
19
|
|
17
20
|
```rb
|
18
|
-
|
21
|
+
photo = Photo.new
|
22
|
+
|
23
|
+
attachment_data = {
|
19
24
|
id: "http://example.com/image.jpg",
|
20
|
-
storage: "
|
21
|
-
metadata: {}
|
25
|
+
storage: "cache",
|
26
|
+
metadata: {...}
|
22
27
|
}
|
28
|
+
|
29
|
+
photo.image = attachment_data.to_json
|
30
|
+
photo.image #=> #<Shrine::UploadedFile>
|
31
|
+
|
32
|
+
photo.image.url #=> "http://example.com/image.jpg"
|
33
|
+
photo.image.download # Downloads from this URL
|
34
|
+
photo.image.exists? # Checks whether a request to this URL returns 200
|
35
|
+
photo.image.delete # No-op
|
23
36
|
```
|
24
37
|
|
25
|
-
|
26
|
-
|
27
|
-
|
38
|
+
The custom URL can be saved to `id`, and `#url` will simply read that field.
|
39
|
+
When this `Shrine::UploadedFile` is uploaded to another storage (e.g. permanent
|
40
|
+
storage), if the storage doesn't support upload from URL the file will simply
|
41
|
+
be downloaded from the custom URL, just like for any other storage.
|
42
|
+
|
43
|
+
## Use cases
|
44
|
+
|
45
|
+
This storage can be used with [shrine-transloadit] for direct uploads, where a
|
46
|
+
temporary URL of the uploaded file is returned, and we want to use that URL for
|
47
|
+
further background processing, eventually replacing the attachment with
|
48
|
+
processed files.
|
49
|
+
|
50
|
+
It is also used in [shrine-tus-demo], where the files are uploaded to a
|
51
|
+
separate endpoint, and then its file URL is attached to a database record and
|
52
|
+
promoted to permanent storage.
|
28
53
|
|
29
54
|
## Contributing
|
30
55
|
|
@@ -37,3 +62,4 @@ $ rake test
|
|
37
62
|
[MIT](/LICENSE.txt)
|
38
63
|
|
39
64
|
[shrine-transloadit]: https://github.com/janko-m/shrine-transloadit
|
65
|
+
[shrine-tus-demo]: https://github.com/janko-m/shrine-tus-demo
|
data/lib/shrine/storage/url.rb
CHANGED
@@ -20,7 +20,9 @@ class Shrine
|
|
20
20
|
def exists?(id)
|
21
21
|
response = nil
|
22
22
|
uri = URI(id)
|
23
|
-
Net::HTTP.start(uri.host, uri.port)
|
23
|
+
Net::HTTP.start(uri.host, uri.port) do |http|
|
24
|
+
response = http.head(uri.request_uri)
|
25
|
+
end
|
24
26
|
response.code.to_i == 200
|
25
27
|
end
|
26
28
|
|
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 = "0.1.
|
3
|
+
gem.version = "0.1.1"
|
4
4
|
|
5
5
|
gem.required_ruby_version = ">= 2.1"
|
6
6
|
|
@@ -14,7 +14,7 @@ Gem::Specification.new do |gem|
|
|
14
14
|
gem.require_path = "lib"
|
15
15
|
|
16
16
|
gem.add_dependency "shrine", ">= 2.0"
|
17
|
-
gem.add_dependency "down", ">= 2.3.
|
17
|
+
gem.add_dependency "down", ">= 2.3.7"
|
18
18
|
|
19
19
|
gem.add_development_dependency "rake"
|
20
20
|
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: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Janko Marohnić
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: shrine
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 2.3.
|
33
|
+
version: 2.3.7
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 2.3.
|
40
|
+
version: 2.3.7
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -103,4 +103,3 @@ specification_version: 4
|
|
103
103
|
summary: Provides a fake storage which allows you to create a Shrine attachment defined
|
104
104
|
only by a custom URL.
|
105
105
|
test_files: []
|
106
|
-
has_rdoc:
|