shrine-url 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d6f4cb4622bcb4d935b7b86b9888ee7c32079053
4
- data.tar.gz: 1b0f0d88c06a9da86dfd9031db7da73b33c65f32
3
+ metadata.gz: 5da2ca4ce8958271c422287cc7b8ee6fe7999526
4
+ data.tar.gz: 1c9b02222b55b30bb63cb333fd73c4dc4e8951ab
5
5
  SHA512:
6
- metadata.gz: 9a3ac0a1d66ed189d42e185407e2a97971faeb5b792c91c979b2b03c99a29aaaae08f337b1e04d913a5a0ebcec36b0077afb379bb67e25fbb7d2ddf344b616d2
7
- data.tar.gz: 0be5d02f2b146a9dbe9f26bb9aabbcc24b91136bc57e2e359e1c0b3d4be8ff1d24aeeead115321aaa2449ddb1cc281073e014d307d360041f403a028fdc9999c
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 fake storage which allows you to create a Shrine attachment defined
4
- only by a custom URL.
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
- The representation of the uploaded file assumes that the ID will be a custom
15
- URL:
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: "url",
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
- This is used in [shrine-transloadit] for direct uploads, where a temporary URL
26
- of the uploaded file is returned, and we want to use that URL for further
27
- processing, eventually replacing the attachment with permanent files.
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
@@ -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) { |http| response = http.head(id) }
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
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "shrine-url"
3
- gem.version = "0.1.0"
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.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.0
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-07-11 00:00:00.000000000 Z
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.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.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: