class PusherFake::Webhook
Webhook
triggering.
Public Class Methods
trigger(name, data = {})
click to toggle source
# File lib/pusher-fake/webhook.rb, line 7 def trigger(name, data = {}) payload = MultiJson.dump( events: [data.merge(name: name)], time_ms: Time.now.to_i ) PusherFake.log("HOOK: #{payload}") PusherFake.configuration.webhooks.each do |url| http = EventMachine::HttpRequest.new(url) http.post(body: payload, head: headers_for(payload)) end end
Private Class Methods
headers_for(payload)
click to toggle source
# File lib/pusher-fake/webhook.rb, line 22 def headers_for(payload) { "Content-Type" => "application/json", "X-Pusher-Key" => PusherFake.configuration.key, "X-Pusher-Signature" => signature_for(payload) } end
signature_for(payload)
click to toggle source
# File lib/pusher-fake/webhook.rb, line 30 def signature_for(payload) digest = OpenSSL::Digest.new("SHA256") secret = PusherFake.configuration.secret OpenSSL::HMAC.hexdigest(digest, secret, payload) end