-
Notifications
You must be signed in to change notification settings - Fork 9
/
hookable.rb
50 lines (41 loc) · 918 Bytes
/
hookable.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
require "bundler/setup"
ENV["RACK_ENV"] ||= "development"
Bundler.require(:default, ENV["RACK_ENV"].to_sym)
Dotenv.load
require "./hook_delivery"
configure do
MongoMapper.setup({'production' => {'uri' => ENV['MONGOLAB_URI']}}, 'production')
end
post "/" do
headers = {
"X-GitHub-Event" => env["HTTP_X_GITHUB_EVENT"],
"X-GitHub-Delivery" => env["HTTP_X_GITHUB_DELIVERY"],
"X-Hub-Signature" => env["HTTP_X_HUB_SIGNATURE"]
}.to_json
payload = request.body.read
HookDelivery.create(
:payload => payload,
:headers => headers
)
status 200
end
get "/" do
@hook_deliveries = HookDelivery.sort(:created_at.desc).limit(8)
erb :index
end
delete "/" do
HookDelivery.destroy_all
status 200
end
####
# Simple presentation helper
####
helpers do
def seconds_ago(number)
if number == 1
"#{number} second ago"
else
"#{number} seconds ago"
end
end
end