lib/webhook_system/job.rb in webhook_system-1.0.4 vs lib/webhook_system/job.rb in webhook_system-2.0.0
- old
+ new
@@ -39,11 +39,11 @@
request = build_request(client, subscription, event)
response =
begin
client.builder.build_response(client, request)
- rescue Exception => exception # we do want to catch all exceptions
+ rescue RuntimeError => exception
ErrorResponse.new(exception)
end
log_response(subscription, event, request, response)
ensure_success(response)
@@ -55,15 +55,19 @@
raise RequestFailed.new("request failed with code: #{status}", status)
end
end
def self.build_request(client, subscription, event)
- payload = Encoder.encode(subscription.secret, event)
+ payload, headers = Encoder.encode(subscription.secret, event, format: format_for_subscription(subscription))
client.build_request(:post) do |req|
req.url subscription.url
- req.headers['Content-Type'] = 'application/json; base64+aes256'
+ req.headers.merge!(headers)
req.body = payload.to_s
end
+ end
+
+ def self.format_for_subscription(subscription)
+ subscription.encrypt ? 'base64+aes256' : 'json'
end
def self.log_response(subscription, event, request, response)
event_log = EventLog.construct(subscription, event, request, response)