oups payload.cr

master
Izimic 2020-11-26 16:34:39 +01:00
parent f0951210f2
commit 577c7ba5d7
1 changed files with 25 additions and 0 deletions

25
src/payload.cr Normal file
View File

@ -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