From 577c7ba5d7cfdc077d7adb149ff2f847547344d7 Mon Sep 17 00:00:00 2001 From: Izimic Date: Thu, 26 Nov 2020 16:34:39 +0100 Subject: [PATCH] oups payload.cr --- src/payload.cr | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/payload.cr diff --git a/src/payload.cr b/src/payload.cr new file mode 100644 index 0000000..c1655f1 --- /dev/null +++ b/src/payload.cr @@ -0,0 +1,25 @@ +require "json" + +class Payload + include JSON::Serializable + + property kind : String + property content : String + + def initialize(req : HTTP::Request) + + agent = req.headers.fetch("User-Agent", "None") + if agent == "GiteaServer" && req.headers.has_key?("X-Gitea-Event") + @kind = "gitea" + elsif agent.starts_with?("GitHub-Hookshot/") && req.headers.has_key?("X-Github-Event") + @kind = "github" + elsif req.headers.has_key?("X-Gitlab-Event") + @kind = "gitlab" + else + @kind = "undefined" + end + + @content = req.body.not_nil!.gets_to_end.to_s + + end +end