class Shrine::Storage::Imgix
Constants
- PURGE_URL
Attributes
client[R]
storage[R]
Public Class Methods
new(storage:, include_prefix: false, **options)
click to toggle source
We initialize the Imgix
client, and save the storage. We additionally save the token as well, because `Imgix::Client` doesn't provide a reader for the token.
# File lib/shrine/storage/imgix.rb, line 17 def initialize(storage:, include_prefix: false, **options) @client = ::Imgix::Client.new(options) @api_key = options.fetch(:api_key) @storage = storage @include_prefix = include_prefix instance_eval do # Purges the file from the source storage after moving it. def move(io, id, **options) @storage.move(io, id, **options) io.storage.purge(io.id) if io.storage.is_a?(Storage::Imgix) end if @storage.respond_to?(:move) def movable?(io, id) @storage.movable?(io, id) end if @storage.respond_to?(:movable?) def download(id) @storage.download(id) end if @storage.respond_to?(:download) def presign(*args) @storage.presign(*args) end if @storage.respond_to?(:presign) def clear!(*args) @storage.clear!(*args) end if @storage.respond_to?(:clear!) end end
Public Instance Methods
clear!(*args)
click to toggle source
# File lib/shrine/storage/imgix.rb, line 42 def clear!(*args) @storage.clear!(*args) end
delete(id)
click to toggle source
Purges the deleted file.
# File lib/shrine/storage/imgix.rb, line 72 def delete(id) @storage.delete(id) purge(id) end
download(id)
click to toggle source
# File lib/shrine/storage/imgix.rb, line 34 def download(id) @storage.download(id) end
exists?(id)
click to toggle source
# File lib/shrine/storage/imgix.rb, line 56 def exists?(id) @storage.exists?(id) end
movable?(io, id)
click to toggle source
# File lib/shrine/storage/imgix.rb, line 30 def movable?(io, id) @storage.movable?(io, id) end
move(io, id, **options)
click to toggle source
Purges the file from the source storage after moving it.
# File lib/shrine/storage/imgix.rb, line 25 def move(io, id, **options) @storage.move(io, id, **options) io.storage.purge(io.id) if io.storage.is_a?(Storage::Imgix) end
open(id)
click to toggle source
# File lib/shrine/storage/imgix.rb, line 52 def open(id) @storage.open(id) end
presign(*args)
click to toggle source
# File lib/shrine/storage/imgix.rb, line 38 def presign(*args) @storage.presign(*args) end
purge(id)
click to toggle source
Removes the file from Imgix
, along with the generated versions.
# File lib/shrine/storage/imgix.rb, line 78 def purge(id) uri = URI.parse(PURGE_URL) uri.user = @api_key post(uri, "url" => url(id)) end
upload(io, id, **options)
click to toggle source
# File lib/shrine/storage/imgix.rb, line 48 def upload(io, id, **options) @storage.upload(io, id, **options) end
url(id, **options)
click to toggle source
Generates an Imgix
URL to the file. All options passed in will be transformed into URL parameters, check out the [reference] for all available query parameters.
[reference]: www.imgix.com/docs/reference
# File lib/shrine/storage/imgix.rb, line 65 def url(id, **options) id = [*@storage.prefix, id].join("/") if @include_prefix client.path(id).to_url(**options) end
Private Instance Methods
post(uri, params = {})
click to toggle source
# File lib/shrine/storage/imgix.rb, line 87 def post(uri, params = {}) response = Net::HTTP.post_form(uri, params) response.error! if (400..599).cover?(response.code.to_i) response end