shrine-imgix 0.3.0 → 0.5.2

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
- SHA1:
3
- metadata.gz: 13821100dcfca77321605576fbcd0e605ad8b00d
4
- data.tar.gz: 313318ca99ddec0836d2d67aa5aaa5844178f0bb
2
+ SHA256:
3
+ metadata.gz: c27d8fee1e632bcdc8e1f062e57f5d77759288eb6f7aa5572f96cb008b8dc54c
4
+ data.tar.gz: '0862b624a88f39069147eefeacf47d1a1b721f42493bac7ae0d21f34005e6a63'
5
5
  SHA512:
6
- metadata.gz: c89621b4f825f34ee15daa18804438d5978311bd116a86d20f59b947181531dbe1e4479dabd981531c662e1a3e66907658bcfea0e525a2505e73100b7c0c273c
7
- data.tar.gz: ba3d4788f98c2ad94f0280b50944c373fcfbdaee8209109723e86f0f103eb0b9ce6483215d3faafaab8adda7d90e3b530e4d68ca6260fd6eabc29b1769e9d8a3
6
+ metadata.gz: b6d757e626f7ee32dc62df26e9387aaaf768560af18d9a878bc0195a8138524c011760b4f918248746a77086ccc579438180418393f05346bdb8f548499bdb95
7
+ data.tar.gz: 732edc00a874b470a71e42e03ca7606c8d1e8925957ba54baaa05893d7ba31085ad495cb5289be500c34381f4a666ac2b1d8f0d2b6631c9ff6198d4437af5e73
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  Provides [Imgix] integration for [Shrine].
4
4
 
5
5
  Imgix is a service for processing images on the fly, and works with files
6
- stored on Amazon S3.
6
+ stored on external services such as AWS S3 or Google Cloud Storage.
7
7
 
8
8
  ## Installation
9
9
 
@@ -11,60 +11,81 @@ stored on Amazon S3.
11
11
  gem "shrine-imgix"
12
12
  ```
13
13
 
14
- ## Usage
14
+ ## Configuring
15
15
 
16
- Imgix doesn't upload files directly, but instead it transfers images from
17
- various sources (S3, Web Folder or Web Proxy), so you first need to set that up
18
- (see the [Imgix documentation]). After this is set up, the Imgix Shrine
19
- "storage" is used as a wrapper around the main storage of the source:
16
+ Load the `imgix` plugin with Imgix client settings:
20
17
 
21
18
  ```rb
22
- require "shrine/storage/imgix"
23
- require "shrine/storage/s3"
24
-
25
- imgix = Shrine::Storage::Imgix.new(
26
- storage: Shrine::Storage::S3.new(**s3_options),
27
- api_key: "xzy123",
28
- host: "my-subdomain.imgix.net",
29
- secure_url_token: "abc123", # optional
19
+ Shrine.plugin :imgix, client: {
20
+ host: "your-subdomain.imgix.net",
21
+ secure_url_token: "abc123",
22
+ }
23
+ ```
24
+
25
+ You can also pass in an `Imgix::Client` object directly:
26
+
27
+ ```rb
28
+ require "imgix"
29
+
30
+ imgix_client = Imgix::Client.new(
31
+ host: "your-subdomain.imgix.net",
32
+ secure_url_token: "abc123",
30
33
  )
31
34
 
32
- Shrine.storages[:store] = imgix
35
+ Shrine.plugin :imgix, client: imgix_client
33
36
  ```
34
37
 
35
- All options other than `:storage` are used for instantiating an `Imgix::Client`,
36
- so see the [imgix] gem for information about all possible options.
38
+ ### Path prefix
37
39
 
38
- All storage actions are forwarded to the main storage, and deleted files are
39
- automatically purged from Imgix. The only method that the Imgix storage
40
- overrides is, of course, `#url`:
40
+ If you've configured a "Path Prefix" on your Imgix source, and you also have
41
+ `:prefix` set on your Shrine storage, you'll need tell the `imgix` plugin to
42
+ exclude the storage prefix from generated URLs:
41
43
 
42
44
  ```rb
43
- post.image.url(w: 150, h: 200, fit: "crop")
45
+ Shrine.plugin :imgix, client: ..., prefix: false
46
+ ```
47
+
48
+ ## Usage
49
+
50
+ You can generate an Imgix URL for a `Shrine::UploadedFile` object by calling
51
+ `#imgix_url`:
52
+
53
+ ```rb
54
+ photo.image.imgix_url(w: 150, h: 200, fit: "crop")
44
55
  #=> "http://my-subdomain.imgix.net/943kdfs0gkfg.jpg?w=150&h=200&fit=crop"
45
56
  ```
46
57
 
47
- See the [Imgix docs](https://www.imgix.com/docs/reference) for all available
48
- URL options.
58
+ See the [Imgix docs][url reference] for all available URL options.
49
59
 
50
- ## Development
60
+ ### Rails
51
61
 
52
- The tests for shrine-imgix uses S3, so you'll have to create an `.env` file with
53
- appropriate credentials:
62
+ If you're using [imgix-rails] and want to use the `ix_*` helpers, you can use
63
+ `#imgix_id` to retrieve the Imgix path:
54
64
 
55
- ```sh
56
- # .env
57
- IMGIX_API_KEY="..."
58
- IMGIX_HOST="..."
59
- IMGIX_SECURE_URL_TOKEN="..." # optional
60
- S3_ACCESS_KEY_ID="..."
61
- S3_SECRET_ACCESS_KEY="..."
62
- S3_REGION="..."
63
- S3_BUCKET="..."
64
- S3_PREFIX="..."
65
+ ```erb
66
+ <%= ix_image_tag photo.image.imgix_id, url_params: { w: 300, h: 500, fit: "crop" } %>
65
67
  ```
66
68
 
67
- Afterwards you can run the tests:
69
+ ### Purging
70
+
71
+ If you want images to be automatically [purged][purging] from Imgix on
72
+ deletion, you can set `:purge` to `true`:
73
+
74
+ ```rb
75
+ Shrine.plugin :imgix, client: ..., purge: true
76
+ ```
77
+
78
+ You can also purge manually with `Shrine::UploadedFile#imgix_purge`:
79
+
80
+ ```rb
81
+ photo.image.imgix_purge
82
+ ```
83
+
84
+ Note that purging requires passing the `:api_key` option to your Imgix client.
85
+
86
+ ## Development
87
+
88
+ You can run the test suite with:
68
89
 
69
90
  ```sh
70
91
  $ bundle exec rake test
@@ -75,6 +96,8 @@ $ bundle exec rake test
75
96
  [MIT](http://opensource.org/licenses/MIT)
76
97
 
77
98
  [Imgix]: https://www.imgix.com/
78
- [Shrine]: https://github.com/janko-m/shrine
99
+ [Shrine]: https://github.com/janko/shrine
79
100
  [imgix]: https://github.com/imgix/imgix-rb
80
- [Imgix documentation]: https://www.imgix.com/docs
101
+ [url reference]: https://docs.imgix.com/apis/url
102
+ [imgix-rails]: https://github.com/imgix/imgix-rails
103
+ [purging]: https://docs.imgix.com/setup/purging-images
@@ -0,0 +1,61 @@
1
+ require "imgix"
2
+
3
+ class Shrine
4
+ module Plugins
5
+ module Imgix
6
+ def self.configure(uploader, **opts)
7
+ opts[:client] = ::Imgix::Client.new(opts[:client]) if opts[:client].is_a?(Hash)
8
+
9
+ uploader.opts[:imgix] ||= { prefix: true, purge: false }
10
+ uploader.opts[:imgix].merge!(**opts)
11
+
12
+ fail Error, ":client is required for imgix plugin" unless uploader.imgix_client
13
+ end
14
+
15
+ module ClassMethods
16
+ def imgix_client
17
+ opts[:imgix][:client]
18
+ end
19
+ end
20
+
21
+ module FileMethods
22
+ def imgix_url(**options)
23
+ imgix_client.path(imgix_id).to_url(**options)
24
+ end
25
+
26
+ def delete
27
+ super
28
+ imgix_purge if imgix_purge?
29
+ end
30
+
31
+ def imgix_purge
32
+ imgix_client.purge(imgix_id)
33
+ end
34
+
35
+ def imgix_id
36
+ if imgix_prefix? && storage.respond_to?(:prefix)
37
+ [*storage.prefix, id].join("/")
38
+ else
39
+ id
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def imgix_client
46
+ shrine_class.imgix_client
47
+ end
48
+
49
+ def imgix_prefix?
50
+ shrine_class.opts[:imgix][:prefix]
51
+ end
52
+
53
+ def imgix_purge?
54
+ shrine_class.opts[:imgix][:purge]
55
+ end
56
+ end
57
+ end
58
+
59
+ register_plugin(:imgix, Imgix)
60
+ end
61
+ end
@@ -1,8 +1,9 @@
1
1
  require "imgix"
2
- require "forwardable"
3
2
  require "net/http"
4
3
  require "uri"
5
4
 
5
+ warn "Shrine::Storage::Imgix is deprecated and will be removed in next major version. Use the new :imgix plugin instead."
6
+
6
7
  class Shrine
7
8
  module Storage
8
9
  class Imgix
@@ -13,33 +14,58 @@ class Shrine
13
14
  # We initialize the Imgix client, and save the storage. We additionally
14
15
  # save the token as well, because `Imgix::Client` doesn't provide a
15
16
  # reader for the token.
16
- def initialize(storage:, **options)
17
+ def initialize(storage:, include_prefix: false, **options)
17
18
  @client = ::Imgix::Client.new(options)
18
19
  @api_key = options.fetch(:api_key)
19
20
  @storage = storage
21
+ @include_prefix = include_prefix
22
+
23
+ instance_eval do
24
+ # Purges the file from the source storage after moving it.
25
+ def move(io, id, **options)
26
+ @storage.move(io, id, **options)
27
+ io.storage.purge(io.id) if io.storage.is_a?(Storage::Imgix)
28
+ end if @storage.respond_to?(:move)
29
+
30
+ def movable?(io, id)
31
+ @storage.movable?(io, id)
32
+ end if @storage.respond_to?(:movable?)
33
+
34
+ def download(id)
35
+ @storage.download(id)
36
+ end if @storage.respond_to?(:download)
37
+
38
+ def presign(*args)
39
+ @storage.presign(*args)
40
+ end if @storage.respond_to?(:presign)
41
+
42
+ def clear!(*args)
43
+ @storage.clear!(*args)
44
+ end if @storage.respond_to?(:clear!)
45
+ end
20
46
  end
21
47
 
22
- # We delegate all methods that are the same.
23
- extend Forwardable
24
- delegate [:upload, :download, :open, :read, :exists?, :clear!] => :storage
48
+ def upload(io, id, **options)
49
+ @storage.upload(io, id, **options)
50
+ end
25
51
 
26
- # Purges the file from the source storage after moving it.
27
- def move(io, id, **options)
28
- @storage.move(io, id, **options)
29
- io.storage.purge(io.id) if io.storage.is_a?(Storage::Imgix)
52
+ def open(id)
53
+ @storage.open(id)
30
54
  end
31
55
 
32
- def movable?(io, id)
33
- @storage.movable?(io, id) if @storage.respond_to?(:movable?)
56
+ def exists?(id)
57
+ @storage.exists?(id)
34
58
  end
35
59
 
36
- def multi_delete(ids)
37
- if @storage.respond_to?(:multi_delete)
38
- @storage.multi_delete(ids)
39
- ids.each { |id| purge(id) }
40
- else
41
- ids.each { |id| delete(id) }
42
- end
60
+ # Generates an Imgix URL to the file. All options passed in will be
61
+ # transformed into URL parameters, check out the [reference] for all
62
+ # available query parameters.
63
+ #
64
+ # [reference]: https://www.imgix.com/docs/reference
65
+ def url(id, **options)
66
+ id = [*@storage.prefix, id].join("/") if @include_prefix
67
+
68
+ client.path(id).to_url(**options)
43
69
  end
44
70
 
45
71
  # Purges the deleted file.
@@ -56,15 +82,6 @@ class Shrine
56
82
  post(uri, "url" => url(id))
57
83
  end
58
84
 
59
- # Generates an Imgix URL to the file. All options passed in will be
60
- # transformed into URL parameters, check out the [reference] for all
61
- # available query parameters.
62
- #
63
- # [reference]: https://www.imgix.com/docs/reference
64
- def url(id, **options)
65
- client.path(id).to_url(**options)
66
- end
67
-
68
85
  private
69
86
 
70
87
  def post(uri, params = {})
@@ -1,23 +1,22 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "shrine-imgix"
3
- gem.version = "0.3.0"
3
+ gem.version = "0.5.2"
4
4
 
5
5
  gem.required_ruby_version = ">= 2.1"
6
6
 
7
7
  gem.summary = "Provides Imgix integration for Shrine."
8
- gem.homepage = "https://github.com/janko-m/shrine-imgix"
8
+ gem.homepage = "https://github.com/shrinerb/shrine-imgix"
9
9
  gem.authors = ["Janko Marohnić"]
10
10
  gem.email = ["janko.marohnic@gmail.com"]
11
11
  gem.license = "MIT"
12
12
 
13
- gem.files = Dir["README.md", "LICENSE.txt", "lib/**/*.rb", "shrine-imgix.gemspec"]
13
+ gem.files = Dir["README.md", "LICENSE.txt", "lib/**/*.rb", "*.gemspec"]
14
14
  gem.require_path = "lib"
15
15
 
16
- gem.add_dependency "shrine", "~> 2.0"
17
- gem.add_dependency "imgix", "~> 1.0"
16
+ gem.add_dependency "shrine", ">= 2.0", "< 4"
17
+ gem.add_dependency "imgix", ">= 1.2", "< 5"
18
18
 
19
19
  gem.add_development_dependency "rake"
20
20
  gem.add_development_dependency "minitest"
21
- gem.add_development_dependency "dotenv"
22
- gem.add_development_dependency "aws-sdk", "~> 2.1"
21
+ gem.add_development_dependency "mocha"
23
22
  end
metadata CHANGED
@@ -1,43 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shrine-imgix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.5.2
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-09-13 00:00:00.000000000 Z
11
+ date: 2020-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: shrine
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '2.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '4'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '2.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '4'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: imgix
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
- - - "~>"
37
+ - - ">="
32
38
  - !ruby/object:Gem::Version
33
- version: '1.0'
39
+ version: '1.2'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '5'
34
43
  type: :runtime
35
44
  prerelease: false
36
45
  version_requirements: !ruby/object:Gem::Requirement
37
46
  requirements:
38
- - - "~>"
47
+ - - ">="
39
48
  - !ruby/object:Gem::Version
40
- version: '1.0'
49
+ version: '1.2'
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '5'
41
53
  - !ruby/object:Gem::Dependency
42
54
  name: rake
43
55
  requirement: !ruby/object:Gem::Requirement
@@ -67,7 +79,7 @@ dependencies:
67
79
  - !ruby/object:Gem::Version
68
80
  version: '0'
69
81
  - !ruby/object:Gem::Dependency
70
- name: dotenv
82
+ name: mocha
71
83
  requirement: !ruby/object:Gem::Requirement
72
84
  requirements:
73
85
  - - ">="
@@ -80,20 +92,6 @@ dependencies:
80
92
  - - ">="
81
93
  - !ruby/object:Gem::Version
82
94
  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'
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'
97
95
  description:
98
96
  email:
99
97
  - janko.marohnic@gmail.com
@@ -103,9 +101,10 @@ extra_rdoc_files: []
103
101
  files:
104
102
  - LICENSE.txt
105
103
  - README.md
104
+ - lib/shrine/plugins/imgix.rb
106
105
  - lib/shrine/storage/imgix.rb
107
106
  - shrine-imgix.gemspec
108
- homepage: https://github.com/janko-m/shrine-imgix
107
+ homepage: https://github.com/shrinerb/shrine-imgix
109
108
  licenses:
110
109
  - MIT
111
110
  metadata: {}
@@ -124,8 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
123
  - !ruby/object:Gem::Version
125
124
  version: '0'
126
125
  requirements: []
127
- rubyforge_project:
128
- rubygems_version: 2.5.1
126
+ rubygems_version: 3.1.4
129
127
  signing_key:
130
128
  specification_version: 4
131
129
  summary: Provides Imgix integration for Shrine.