module Shrine::Plugins::Transloadit::InstanceMethods
Public Instance Methods
transloadit_export_step(name = "export", **options)
click to toggle source
# File lib/shrine/plugins/transloadit.rb, line 166 def transloadit_export_step(name = "export", **options) unless options.key?(:credentials) options[:credentials] = self.class.transloadit_credentials(storage_key).to_s end if defined?(Storage::S3) && storage.is_a?(Storage::S3) transloadit_s3_store_step(name, **options) elsif defined?(Storage::GoogleCloudStorage) && storage.is_a?(Storage::GoogleCloudStorage) transloadit_google_store_step(name, **options) elsif defined?(Storage::YouTube) && storage.is_a?(Storage::YouTube) transloadit_youtube_store_step(name, **options) else fail Error, "cannot construct export step for #{storage.inspect}" end end
transloadit_file(result)
click to toggle source
# File lib/shrine/plugins/transloadit.rb, line 141 def transloadit_file(result) result = result.first if result.is_a?(Array) uri = URI.parse(result.fetch("url")) if defined?(Storage::S3) && storage.is_a?(Storage::S3) prefix = "#{storage.prefix}/" if storage.prefix id = uri.path.match(%r{^/#{prefix}})&.post_match or fail Error, "URL path doesn't start with storage prefix: #{uri}" elsif defined?(Storage::Url) && storage.is_a?(Storage::Url) id = uri.to_s else fail Error, "storage not supported: #{storage.inspect}" end self.class::UploadedFile.new( id: id, storage: storage_key, metadata: result.fetch("meta").merge( "filename" => result.fetch("name"), "size" => result.fetch("size"), "mime_type" => result.fetch("mime"), ) ) end
transloadit_files(results)
click to toggle source
# File lib/shrine/plugins/transloadit.rb, line 137 def transloadit_files(results) results.map { |result| transloadit_file(result) } end
Private Instance Methods
transloadit_google_store_step(name, path: DEFAULT_PATH, **options)
click to toggle source
# File lib/shrine/plugins/transloadit.rb, line 190 def transloadit_google_store_step(name, path: DEFAULT_PATH, **options) transloadit_step name, "/google/store", path: [*storage.prefix, path].join("/"), **options end
transloadit_s3_store_step(name, path: DEFAULT_PATH, **options)
click to toggle source
# File lib/shrine/plugins/transloadit.rb, line 184 def transloadit_s3_store_step(name, path: DEFAULT_PATH, **options) transloadit_step name, "/s3/store", path: [*storage.prefix, path].join("/"), **options end
transloadit_step(*args)
click to toggle source
# File lib/shrine/plugins/transloadit.rb, line 201 def transloadit_step(*args) self.class.transloadit_step(*args) end
transloadit_youtube_store_step(name, **options)
click to toggle source
# File lib/shrine/plugins/transloadit.rb, line 196 def transloadit_youtube_store_step(name, **options) transloadit_step name, "/youtube/store", **options end