Skip to content

Instantly share code, notes, and snippets.

@tisba
Created June 10, 2012 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tisba/5a89f03432e140fa1626 to your computer and use it in GitHub Desktop.
Save tisba/5a89f03432e140fa1626 to your computer and use it in GitHub Desktop.
module Arango
class HttpRequest
attr_reader :body, :headers, :parameters, :request_type, :suffix
end
end
module Arango
class HttpResponse
attr_accessor :content_type, :body
attr_reader :status
def status=(new_status)
@status = case new_status
when :ok then 200
when :created then 201
when :method_not_allowed then 405
else new_status.to_i
end
end
end
end
module Arango
class AbstractServlet
HTTP_METHODS = [:get, :put, :post, :delete, :head]
def service(req, res)
requested_method = req.request_type.to_s.downcase.to_sym
if HTTP_METHODS.include? requested_method
self.send(requested_method, req, res)
else
self.unknown_method(req, res, requested_method)
end
end
HTTP_METHODS.each do |meth|
define_method(meth.to_sym) do |req, res|
res.status = :method_not_allowed
end
end
def unknown_method(req, res, method)
res.status = :method_not_allowed
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment