Class: PdfMage::Workers::SendWebhook

Inherits:
Base
  • Object
show all
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.

Since:

  • 0.1.0

Constant Summary

Constants inherited from Base

Base::STRIP_STRING_OPTIONS

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

Since:

  • 0.1.0



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, meta = nil)
  LOGGER.info "Sending webhook to [#{callback_url}] for file [#{file_url_or_path}] and meta: #{meta.inspect}"
  params = {
    file: file_url_or_path,
    meta: 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