shrine-imgix 0.1.0
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 +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +72 -0
- data/lib/shrine/storage/imgix.rb +57 -0
- data/shrine-imgix.gemspec +23 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c8f5f6f3c73706b3e362d2c8cb015d6bc8a3ae38
|
4
|
+
data.tar.gz: 5c10ec076e3dfe3d17be76f2490255612de1cccd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5926511ad322c97686b4bdfea29b1cf950341b3e7ad3bbbe9c56d1550dd0cba023ad0f347558556775a8625ef7ab10aca5e0c8c86e0a49293dc445de5240dcad
|
7
|
+
data.tar.gz: 37d13abbba5afe89a4f2f656cf2e7a02c13eb40ae2985c4b7e612a25c47331a80840919645c12e424778a94df467ba1cadfe570282ffe89e93b58eb6a20224a9
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Janko Marohnić
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# Shrine::Imgix
|
2
|
+
|
3
|
+
Provides [Imgix] integration for [Shrine].
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem "shrine-imgix"
|
9
|
+
```
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
Imgix doesn't upload files directly, but instead it transfers images from
|
14
|
+
various sources (S3, Web Folder or Web Proxy), so you first need to set that up
|
15
|
+
(see the [Imgix documentation]). After this is set up, the Imgix Shrine
|
16
|
+
"storage" is used as a wrapper around the main storage of the source:
|
17
|
+
|
18
|
+
```rb
|
19
|
+
require "shrine/storage/imgix"
|
20
|
+
require "shrine/storage/s3"
|
21
|
+
|
22
|
+
s3 = Shrine::Storage::S3.new(**s3_options)
|
23
|
+
imgix = Shrine::Storage::Imgix.new(
|
24
|
+
storage: s3,
|
25
|
+
host: "my-subdomain.imgix.net",
|
26
|
+
token: "abc123",
|
27
|
+
)
|
28
|
+
|
29
|
+
Shrine.storages[:store] = imgix
|
30
|
+
```
|
31
|
+
|
32
|
+
All options other than `:storage` are used for instantiating an `Imgix::Client`,
|
33
|
+
so see the [imgix] gem for information about all possible options.
|
34
|
+
|
35
|
+
All storage actions are forwarded to the main storage, and deleted files are
|
36
|
+
automatically purged from Imgix. The only method that the Imgix storage
|
37
|
+
overrides is, of course, `#url`:
|
38
|
+
|
39
|
+
```rb
|
40
|
+
post.image.url(w: 150, h: 200, fit: "crop")
|
41
|
+
#=> "http://my-subdomain.imgix.net/943kdfs0gkfg.jpg?w=150&h=200&fit=crop"
|
42
|
+
```
|
43
|
+
|
44
|
+
## Development
|
45
|
+
|
46
|
+
The tests for shrine-imgix uses S3, so you'll have to create an `.env` file with
|
47
|
+
appropriate credentials:
|
48
|
+
|
49
|
+
```sh
|
50
|
+
# .env
|
51
|
+
IMGIX_API_KEY="..."
|
52
|
+
IMGIX_HOST="..."
|
53
|
+
S3_ACCESS_KEY_ID="..."
|
54
|
+
S3_SECRET_ACCESS_KEY="..."
|
55
|
+
S3_REGION="..."
|
56
|
+
S3_BUCKET="..."
|
57
|
+
```
|
58
|
+
|
59
|
+
Afterwards you can run the tests:
|
60
|
+
|
61
|
+
```rb
|
62
|
+
bundle exec rake test
|
63
|
+
```
|
64
|
+
|
65
|
+
## License
|
66
|
+
|
67
|
+
[MIT](http://opensource.org/licenses/MIT)
|
68
|
+
|
69
|
+
[Imgix]: https://www.imgix.com/
|
70
|
+
[Shrine]: https://github.com/janko-m/shrine
|
71
|
+
[imgix]: https://github.com/imgix/imgix-rb
|
72
|
+
[Imgix documentation]: https://www.imgix.com/docs
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require "imgix"
|
2
|
+
require "forwardable"
|
3
|
+
require "net/http"
|
4
|
+
require "uri"
|
5
|
+
|
6
|
+
class Shrine
|
7
|
+
module Storage
|
8
|
+
class Imgix
|
9
|
+
PURGE_URL = "https://api.imgix.com/v2/image/purger"
|
10
|
+
|
11
|
+
attr_reader :client, :storage
|
12
|
+
|
13
|
+
def initialize(storage:, **options)
|
14
|
+
@client = ::Imgix::Client.new(options)
|
15
|
+
@token = options[:token]
|
16
|
+
@storage = storage
|
17
|
+
end
|
18
|
+
|
19
|
+
extend Forwardable
|
20
|
+
delegate [:upload, :download, :open, :read, :exists?, :clear!] => :storage
|
21
|
+
|
22
|
+
def move(io, id, metadata = {})
|
23
|
+
@storage.move(io, id, metadata)
|
24
|
+
purge(io.id)
|
25
|
+
end
|
26
|
+
|
27
|
+
def movable?(io, id)
|
28
|
+
@storage.movable?(io, id) if @storage.respond_to?(:movable?)
|
29
|
+
end
|
30
|
+
|
31
|
+
def delete(id)
|
32
|
+
@storage.delete(id)
|
33
|
+
purge(id)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Imgix-specific method
|
37
|
+
def purge(id)
|
38
|
+
uri = URI.parse(PURGE_URL)
|
39
|
+
uri.user = @token
|
40
|
+
|
41
|
+
post(uri, "url" => url(id))
|
42
|
+
end
|
43
|
+
|
44
|
+
def url(id, **options)
|
45
|
+
client.path(id).to_url(**options)
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def post(uri, params = {})
|
51
|
+
response = Net::HTTP.post_form(uri, params)
|
52
|
+
response.error! if (400..599).cover?(response.code.to_i)
|
53
|
+
response
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Gem::Specification.new do |gem|
|
2
|
+
gem.name = "shrine-imgix"
|
3
|
+
gem.version = "0.1.0"
|
4
|
+
|
5
|
+
gem.required_ruby_version = ">= 2.1"
|
6
|
+
|
7
|
+
gem.summary = "Provides Imgix integration for Shrine."
|
8
|
+
gem.homepage = "https://github.com/janko-m/shrine-imgix"
|
9
|
+
gem.authors = ["Janko Marohnić"]
|
10
|
+
gem.email = ["janko.marohnic@gmail.com"]
|
11
|
+
gem.license = "MIT"
|
12
|
+
|
13
|
+
gem.files = Dir["README.md", "LICENSE.txt", "lib/**/*.rb", "shrine-imgix.gemspec"]
|
14
|
+
gem.require_path = "lib"
|
15
|
+
|
16
|
+
gem.add_dependency "imgix"
|
17
|
+
|
18
|
+
gem.add_development_dependency "rake"
|
19
|
+
gem.add_development_dependency "shrine"
|
20
|
+
gem.add_development_dependency "minitest"
|
21
|
+
gem.add_development_dependency "dotenv"
|
22
|
+
gem.add_development_dependency "aws-sdk", "~> 2.1.0"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shrine-imgix
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Janko Marohnić
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: imgix
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
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'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: shrine
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: dotenv
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: aws-sdk
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 2.1.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 2.1.0
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- janko.marohnic@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- LICENSE.txt
|
105
|
+
- README.md
|
106
|
+
- lib/shrine/storage/imgix.rb
|
107
|
+
- shrine-imgix.gemspec
|
108
|
+
homepage: https://github.com/janko-m/shrine-imgix
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata: {}
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '2.1'
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 2.4.5
|
129
|
+
signing_key:
|
130
|
+
specification_version: 4
|
131
|
+
summary: Provides Imgix integration for Shrine.
|
132
|
+
test_files: []
|
133
|
+
has_rdoc:
|