Module: Shrine::Plugins::Transloadit::AttacherClassMethods

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

Instance Method Summary collapse

Instance Method Details

#transloadit_process(data) ⇒ Object

Loads the attacher from the data, and triggers Transloadit processing. Intended to be used in a background job.



46
47
48
49
50
51
# File 'lib/shrine/plugins/transloadit.rb', line 46

def transloadit_process(data)
  attacher = self.load(data)
  cached_file = attacher.uploaded_file(data["attachment"])
  attacher.transloadit_process(cached_file)
  attacher
end

#transloadit_save(params) ⇒ Object

This should be called when receiving a webhook, where arguments are params that Transloadit POSTed to the endpoint. It checks the signature, loads the attacher, saves processing results to the record.



56
57
58
59
60
61
62
63
64
# File 'lib/shrine/plugins/transloadit.rb', line 56

def transloadit_save(params)
  shrine_class.verify_transloadit_signature!(params)
  response = JSON.parse(params["transloadit"])
  data = response["fields"]["attacher"]
  attacher = self.load(data)
  cached_file = attacher.uploaded_file(data["attachment"])
  attacher.transloadit_save(response, valid: attacher.get == cached_file)
  attacher
end