shrine-fog 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 +48 -3
- data/lib/shrine/storage/fog.rb +16 -3
- data/shrine-fog.gemspec +2 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b9e07ed2d525e24b90ce0fe67604e3bc70861ed
|
4
|
+
data.tar.gz: bd70496c2fd9f3dfa8b010c98331826ec34c20b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: feb342d3a69e6398f00ae18b9992e2392bc148e1dc5843f0acb44e946961dca4554c3bb24083c92ab36bb9016de94cf97f84fcaec4e1cad4b69ed535baf45fbe
|
7
|
+
data.tar.gz: f3857955d172503f8477c50668a1f17f365252e19b4cbdb4dd443667ca44102f5ba46b87f1828a68a95af1981c43e49edee0ae75e74650a17d902f9e4a5a083a
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@ Provides [Fog] storage for [Shrine].
|
|
6
6
|
|
7
7
|
```ruby
|
8
8
|
gem "shrine-fog"
|
9
|
-
gem "fog-xyz # Fog gem for the storage you want to use
|
9
|
+
gem "fog-xyz" # Fog gem for the storage you want to use
|
10
10
|
```
|
11
11
|
|
12
12
|
## Usage
|
@@ -15,6 +15,7 @@ Require the appropriate Fog gem, and assign the parameters for initializing
|
|
15
15
|
the storage:
|
16
16
|
|
17
17
|
```rb
|
18
|
+
require "shrine/storage/fog"
|
18
19
|
require "fog/google"
|
19
20
|
|
20
21
|
Shrine.storages[:store] = Shrine::Storage::Fog.new(
|
@@ -28,6 +29,7 @@ Shrine.storages[:store] = Shrine::Storage::Fog.new(
|
|
28
29
|
You can also assign a Fog storage object as the `:connection`:
|
29
30
|
|
30
31
|
```rb
|
32
|
+
require "shrine/storage/fog"
|
31
33
|
require "fog/google"
|
32
34
|
|
33
35
|
google = Fog::Storage.new(
|
@@ -42,15 +44,58 @@ Shrine.storages[:store] = Shrine::Storage::Fog.new(
|
|
42
44
|
)
|
43
45
|
```
|
44
46
|
|
45
|
-
|
47
|
+
If both cache and store are a Fog storage, the uploaded file is copied to store
|
48
|
+
instead of reuploaded.
|
49
|
+
|
50
|
+
### URLs
|
51
|
+
|
52
|
+
By default the shrine-fog will generate public unsigned URLs, but if you want
|
53
|
+
to change that tell Fog not to store files publicly, you can set `:public` to
|
54
|
+
false:
|
55
|
+
|
56
|
+
```rb
|
57
|
+
fog = Shrine::Storage::Fog.new(**fog_options)
|
58
|
+
fog.url("image.jpg") #=> "https://my-bucket.s3-eu-west-1.amazonaws.com/image.jpg"
|
59
|
+
|
60
|
+
fog = Shrine::Storage::Fog.new(public: false, **fog_options)
|
61
|
+
fog.url("image.jpg") #=> "https://my-bucket.s3-eu-west-1.amazonaws.com/foo?X-Amz-Expires=3600&X-Amz-Date=20151217T102105Z&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIJF55TMZZY45UT6Q/20151217/eu-west-1/s3/aws4_request&X-Amz-SignedHeaders=host&X-Amz-Signature=6908d8cd85ce4469f141a36955611f26d29ae7919eb8a6cba28f9194a92d96c3"
|
62
|
+
```
|
63
|
+
|
64
|
+
The signed URLs by default expire in 1 hour, you set `:expires` to number of
|
65
|
+
seconds you want the URL to expire:
|
66
|
+
|
67
|
+
```rb
|
68
|
+
Shrine::Storage::Fog.new(expires: 24*60*60, **fog_options) # expires in 1 day
|
69
|
+
```
|
70
|
+
|
71
|
+
### S3 or Filesystem
|
46
72
|
|
47
73
|
If you want to store your files to Amazon S3 or the filesystem, you should use
|
48
74
|
the storages that ship with Shrine (instead of [fog-aws] or [fog-local]) as
|
49
75
|
they are much more advanced.
|
50
76
|
|
77
|
+
## Running tests
|
78
|
+
|
79
|
+
Tests use [fog-aws], so you'll have to create an `.env` file with appropriate
|
80
|
+
credentials:
|
81
|
+
|
82
|
+
```sh
|
83
|
+
# .env
|
84
|
+
S3_ACCESS_KEY_ID="..."
|
85
|
+
S3_SECRET_ACCESS_KEY="..."
|
86
|
+
S3_REGION="..."
|
87
|
+
S3_BUCKET="..."
|
88
|
+
```
|
89
|
+
|
90
|
+
Afterwards you can run the tests:
|
91
|
+
|
92
|
+
```sh
|
93
|
+
$ bundle exec rake test
|
94
|
+
```
|
95
|
+
|
51
96
|
## License
|
52
97
|
|
53
|
-
[MIT](http://opensource.org/licenses/MIT)
|
98
|
+
[MIT](http://opensource.org/licenses/MIT)
|
54
99
|
|
55
100
|
[Fog]: http://fog.io/
|
56
101
|
[Shrine]: https://github.com/janko-m/shrine
|
data/lib/shrine/storage/fog.rb
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
require "down"
|
2
|
+
require "uri"
|
2
3
|
|
3
4
|
class Shrine
|
4
5
|
module Storage
|
5
6
|
class Fog
|
6
7
|
attr_reader :connection, :directory, :prefix
|
7
8
|
|
8
|
-
def initialize(directory:, prefix: nil, public: true, connection: nil, **options)
|
9
|
+
def initialize(directory:, prefix: nil, public: true, expires: 3600, connection: nil, **options)
|
9
10
|
@connection = connection || ::Fog::Storage.new(options)
|
10
11
|
@directory = @connection.directories.new(key: directory)
|
11
12
|
@prefix = prefix
|
12
13
|
@public = public
|
14
|
+
@expires = expires
|
13
15
|
end
|
14
16
|
|
15
17
|
def upload(io, id, metadata = {})
|
@@ -37,11 +39,18 @@ class Shrine
|
|
37
39
|
end
|
38
40
|
|
39
41
|
def delete(id)
|
40
|
-
|
42
|
+
file(id).destroy
|
41
43
|
end
|
42
44
|
|
43
45
|
def url(id, **options)
|
44
|
-
|
46
|
+
signed_url = file(id).url(Time.now + @expires, **options)
|
47
|
+
if @public
|
48
|
+
uri = URI(signed_url)
|
49
|
+
uri.query = nil
|
50
|
+
uri.to_s
|
51
|
+
else
|
52
|
+
signed_url
|
53
|
+
end
|
45
54
|
end
|
46
55
|
|
47
56
|
def clear!(confirm = nil)
|
@@ -51,6 +60,10 @@ class Shrine
|
|
51
60
|
|
52
61
|
protected
|
53
62
|
|
63
|
+
def file(id)
|
64
|
+
directory.files.new(key: path(id))
|
65
|
+
end
|
66
|
+
|
54
67
|
def get(id)
|
55
68
|
directory.files.get(path(id))
|
56
69
|
end
|
data/shrine-fog.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |gem|
|
2
2
|
gem.name = "shrine-fog"
|
3
|
-
gem.version = "0.1.
|
3
|
+
gem.version = "0.1.1"
|
4
4
|
|
5
5
|
gem.required_ruby_version = ">= 2.1"
|
6
6
|
|
@@ -16,6 +16,7 @@ Gem::Specification.new do |gem|
|
|
16
16
|
|
17
17
|
gem.add_development_dependency "down", ">= 1.0.3"
|
18
18
|
|
19
|
+
gem.add_development_dependency "rake"
|
19
20
|
gem.add_development_dependency "fog-aws"
|
20
21
|
gem.add_development_dependency "mime-types"
|
21
22
|
gem.add_development_dependency "dotenv"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shrine-fog
|
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: 2015-12-
|
11
|
+
date: 2015-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: down
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 1.0.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: fog-aws
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|