Sha256: e3fe73263031f923c970c69c664c96436f934d7e582b70dd82505f59ce69a4c6
Contents?: true
Size: 1.27 KB
Versions: 3
Compression:
Stored size: 1.27 KB
Contents
#!/usr/bin/env ruby require 'rack' require 'time' class NavelApp def call(env) send(:"handle_#{env['REQUEST_METHOD'].downcase}", Rack::Request.new(env)) end private def handle_get(request) case request.path_info when '/affirmation' return [200, {'Content-Type' => 'text/plain'}, ["yup\n"]] else handle_404(request) end end def handle_post(request) case request.path_info when '/dinner/new' body = request.body.read if body.split("\n").include?('soup=splitpea') return [201, {'Content-Type' => 'text/plain'}, ["soup is on!\n"]] else return [ 400, {'Content-Type' => 'text/plain'}, ["invalid dinner:\n" << body << "\n"] ] end else handle_404(request) end end def handle_delete(request) case request.path_info when '/pestilence' return [204, {'Content-Type' => 'text/plain'}, ["orphanage saved!\n"]] else handle_404(client) end end def handle_404(client) [404, {'Content-Type' => 'text/plain'} ["nope\n"]] end end def main(argv = []) port = Integer(argv.first || 19080) $stdout.sync = true $stderr.sync = true Rack::Handler::Thin.run(NavelApp.new, Port: port) end if __FILE__ == $0 main(ARGV) end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
mtbb-0.1.2 | test/navel |
mtbb-0.1.1 | test/navel |
mtbb-0.1.0 | test/navel |