module Shrine::Plugins::Transloadit::ClassMethods

Public Instance Methods

transloadit() click to toggle source

Creates a new Transloadit client each time. This way the expiration timestamp is refreshed on new processing requests.

# File lib/shrine/plugins/transloadit.rb, line 116
def transloadit
  ::Transloadit.new(**opts[:transloadit][:auth])
end
transloadit_credentials(storage_key) click to toggle source
# File lib/shrine/plugins/transloadit.rb, line 120
def transloadit_credentials(storage_key)
  opts[:transloadit][:credentials][storage_key] or
    fail Error, "credentials not registered for storage #{storage_key.inspect}"
end
transloadit_step(name, robot, use: nil, **options) click to toggle source
# File lib/shrine/plugins/transloadit.rb, line 95
def transloadit_step(name, robot, use: nil, **options)
  if Array(use).first.is_a?(::Transloadit::Step)
    step = transloadit.step(name, robot, **options)
    step.use(use) if use
    step
  else
    transloadit.step(name, robot, use: use, **options)
  end
end
transloadit_verify!(params) click to toggle source

Verifies the Transloadit signature of a webhook request. Raises `Shrine::Plugins::Transloadit::InvalidSignature` if signatures don't match.

# File lib/shrine/plugins/transloadit.rb, line 108
def transloadit_verify!(params)
  if transloadit_sign(params["transloadit"]) != params["signature"]
    raise InvalidSignature, "received signature doesn't match calculated"
  end
end

Private Instance Methods

transloadit_sign(string) click to toggle source

Signs given string with Transloadit secret key.

# File lib/shrine/plugins/transloadit.rb, line 128
def transloadit_sign(string)
  algorithm  = OpenSSL::Digest::SHA1.new
  secret_key = opts[:transloadit][:auth][:secret]

  OpenSSL::HMAC.hexdigest(algorithm, secret_key, string)
end