17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/konstant/web.rb', line 17
def route
if request.path.match(/^\/projects$/)
[200, {"Content-type" => "application/json"}, [Konstant::Project.all.to_json]]
elsif m = request.path.match(/^\/projects\/([^\/]+)\/builds\/(\d+)$/)
project = Konstant::Project.new m[1]
build = Konstant::Build.new project, m[2]
[200, {"Content-type" => "application/json"}, [build.to_json]]
elsif request.path.match(/^\/config$/)
[200, {"Content-type" => "application/json"}, [Konstant.config.to_json]]
elsif m = request.path.match(/^\/projects\/([^\/]+)\/builds$/)
project = Konstant::Project.new m[1]
[200, {"Content-type" => "application/json"}, [project.builds.to_json]]
elsif m = request.path.match(/^\/projects\/([^\/]+)\/build$/)
project = Konstant::Project.new m[1]
project.build!
message = {"message" => "ok"}
[200, {"Content-type" => "application/json"}, [message.to_json]]
else
[404, {"Content-type" => "text/plain"}, ["not found"]]
end
end
|