Files
docuseal/app/jobs/send_form_viewed_webhook_request_job.rb
T

23 lines
697 B
Ruby
Raw Normal View History

2023-08-05 15:25:16 +03:00
# frozen_string_literal: true
2023-09-14 20:31:07 +03:00
class SendFormViewedWebhookRequestJob < ApplicationJob
2023-08-05 15:25:16 +03:00
USER_AGENT = 'DocuSeal.co Webhook'
def perform(submitter)
2023-10-08 12:04:32 +03:00
config = Accounts.load_webhook_configs(submitter.submission.account)
2023-08-05 15:25:16 +03:00
return if config.blank? || config.value.blank?
ActiveStorage::Current.url_options = Docuseal.default_url_options
Faraday.post(config.value,
{
2023-09-14 20:31:07 +03:00
event_type: 'form.viewed',
2023-10-08 12:04:32 +03:00
timestamp: Time.current,
2023-08-05 15:25:16 +03:00
data: Submitters::SerializeForWebhook.call(submitter)
}.to_json,
'Content-Type' => 'application/json',
'User-Agent' => USER_AGENT)
end
end