5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/qdocs/server.rb', line 5
def call(env)
req = Rack::Request.new(env)
params = req.params
case env["REQUEST_PATH"]
when "/"
body = JSON.pretty_generate(Qdocs.lookup(params["input"]))
[200, { "Content-Type" => "application/json; charset=utf-8" }, [body]]
else
[404, { "Content-Type" => "text/html; charset=utf-8" }, ["Not Found"]]
end
rescue Qdocs::UnknownClassError,
Qdocs::UnknownMethodTypeError,
Qdocs::UnknownMethodError,
Qdocs::UnknownPatternError => e
[404, { "Content-Type" => "text/html; charset=utf-8" }, ["Not found: #{e.message}"]]
rescue => e
[500, { "Content-Type" => "text/html; charset=utf-8" }, ["Error: #{e.message}"]]
end
|