Class: PdfMage::Workers::SendWebhook
- Defined in:
- lib/pdf_mage/workers/send_webhook.rb
Overview
A Sidekiq job that sends a webhook after a PDF has been rendered or uploaded.
Constant Summary
Constants inherited from Base
Instance Method Summary collapse
Methods inherited from Base
#ensure_directory_exists_for_pdf, #pdf_filename, #secretize_url, #string_exists?, #strip_string
Instance Method Details
#perform(file_url_or_path, callback_url, meta = nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/pdf_mage/workers/send_webhook.rb', line 11 def perform(file_url_or_path, callback_url, = nil) LOGGER.info "Sending webhook to [#{callback_url}] for file [#{file_url_or_path}] and meta: #{.inspect}" params = { file: file_url_or_path, meta: } data = params.to_json headers = { 'content-type' => 'application/json', 'user-agent' => 'PdfMage/1.0' } headers['X-Pdf-Signature'] = OpenSSL::HMAC.hexdigest('sha256', CONFIG.api_secret, data) if CONFIG.api_secret response = Typhoeus.post(callback_url, headers: headers, body: data, ssl_verifypeer: !CONFIG.env.development) LOGGER.info "Received response with status [#{response.code}]: #{response.body}" end |