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