7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/slanger/webhook.rb', line 7
def post(payload)
return unless Slanger::Config.webhook_url
payload = {
time_ms: Time.now.strftime("%s%L"), events: [payload],
}
payload = Oj.dump(payload, mode: :compat)
digest = OpenSSL::Digest::SHA256.new
hmac = OpenSSL::HMAC.hexdigest(digest, Slanger::Config.secret, payload)
content_type = "application/json"
EM::HttpRequest.new(Slanger::Config.webhook_url).
post(body: payload, head: {
"X-Pusher-Key" => Slanger::Config.app_key,
"X-Pusher-Signature" => hmac,
"Content-Type" => content_type,
})
end
|