Send HTML to campfire instead of JSON
This commit is contained in:
@@ -103,7 +103,7 @@ class Webhook::Delivery < ApplicationRecord
|
||||
def headers
|
||||
{
|
||||
"User-Agent" => USER_AGENT,
|
||||
"Content-Type" => "application/json",
|
||||
"Content-Type" => content_type,
|
||||
"X-Webhook-Signature" => signature,
|
||||
"X-Webhook-Timestamp" => event.created_at.utc.iso8601
|
||||
}
|
||||
@@ -113,6 +113,14 @@ class Webhook::Delivery < ApplicationRecord
|
||||
OpenSSL::HMAC.hexdigest("SHA256", webhook.signing_secret, payload)
|
||||
end
|
||||
|
||||
def content_type
|
||||
if webhook.for_campfire?
|
||||
"text/html"
|
||||
else
|
||||
"application/json"
|
||||
end
|
||||
end
|
||||
|
||||
def payload
|
||||
@payload ||= if webhook.for_basecamp?
|
||||
{ line: { content: render_payload(formats: :html) } }.to_json
|
||||
|
||||
@@ -127,7 +127,8 @@ class Webhook::DeliveryTest < ActiveSupport::TestCase
|
||||
request_stub = stub_request(:post, webhook.url)
|
||||
.with do |request|
|
||||
body = JSON.parse(request.body)
|
||||
body.key?("line") && body["line"].key?("content") && body["line"]["content"].present?
|
||||
body.key?("line") && body["line"].key?("content") && body["line"]["content"].present? &&
|
||||
request.headers["Content-Type"] == "application/json"
|
||||
end
|
||||
.to_return(status: 200)
|
||||
|
||||
@@ -148,7 +149,8 @@ class Webhook::DeliveryTest < ActiveSupport::TestCase
|
||||
|
||||
request_stub = stub_request(:post, webhook.url)
|
||||
.with do |request|
|
||||
request.body.is_a?(String) && !request.body.start_with?("{") && request.body.present?
|
||||
request.body.is_a?(String) && !request.body.start_with?("{") && request.body.present? &&
|
||||
request.headers["Content-Type"] == "text/html"
|
||||
end
|
||||
.to_return(status: 200)
|
||||
|
||||
@@ -170,7 +172,8 @@ class Webhook::DeliveryTest < ActiveSupport::TestCase
|
||||
request_stub = stub_request(:post, webhook.url)
|
||||
.with do |request|
|
||||
body = JSON.parse(request.body)
|
||||
body.key?("text") && body["text"].present?
|
||||
body.key?("text") && body["text"].present? &&
|
||||
request.headers["Content-Type"] == "application/json"
|
||||
end
|
||||
.to_return(status: 200)
|
||||
|
||||
@@ -192,7 +195,8 @@ class Webhook::DeliveryTest < ActiveSupport::TestCase
|
||||
request_stub = stub_request(:post, webhook.url)
|
||||
.with do |request|
|
||||
body = JSON.parse(request.body)
|
||||
body.present? && !body.key?("line") && !body.key?("text")
|
||||
body.present? && !body.key?("line") && !body.key?("text") &&
|
||||
request.headers["Content-Type"] == "application/json"
|
||||
end
|
||||
.to_return(status: 200)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user