Module: Shrine::Plugins::Transloadit::ClassMethods

Defined in:
lib/shrine/plugins/transloadit.rb

Instance Method Summary collapse

Instance Method Details

#transloaditObject

Creates a new Transloadit client, so that the expiration timestamp is refreshed on new processing requests.



139
140
141
142
143
144
# File 'lib/shrine/plugins/transloadit.rb', line 139

def transloadit
  ::Transloadit.new(
    key:    opts[:transloadit_auth_key],
    secret: opts[:transloadit_auth_secret],
  )
end

#verify_transloadit_signature!(params) ⇒ Object

Checks if the webhook has indeed been triggered by Transloadit, by checking if sent signature matches the calculated signature, and raising a ‘Shrine::Plugins::Transloadit::Error` if signatures don’t match.

Raises:



150
151
152
153
154
155
156
157
# File 'lib/shrine/plugins/transloadit.rb', line 150

def verify_transloadit_signature!(params)
  sent_signature = params["signature"]
  payload = params["transloadit"]
  algorithm = OpenSSL::Digest.new('sha1')
  secret = opts[:transloadit_auth_secret]
  calculated_signature = OpenSSL::HMAC.hexdigest(algorithm, secret, payload)
  raise Error, "Received signature doesn't match the calculated signature" if calculated_signature != sent_signature
end