Module: Slanger::Webhook
Instance Method Summary collapse
Instance Method Details
#post(payload) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/slanger/webhook.rb', line 6 def post payload return unless Slanger::Config.webhook_url payload = { time_ms: Time.now.strftime('%s%L'), events: [payload] }.to_json digest = OpenSSL::Digest::SHA256.new hmac = OpenSSL::HMAC.hexdigest(digest, Slanger::Config.secret, payload) EM::HttpRequest.new(Slanger::Config.webhook_url). post(body: payload, head: { "X-Pusher-Key" => Slanger::Config.app_key, "X-Pusher-Secret" => hmac }) # TODO: Exponentially backed off retries for errors end |