Class: RubyRest::Webrick::Servlet
- Inherits:
-
WEBrick::HTTPServlet::AbstractServlet
- Object
- WEBrick::HTTPServlet::AbstractServlet
- RubyRest::Webrick::Servlet
- Defined in:
- lib/rubyrest/webrick.rb
Overview
A REST servlet for Webrick adapter
Instance Method Summary collapse
- #args(request) ⇒ Object
- #decode_path(path) ⇒ Object
- #do_DELETE(request, response) ⇒ Object
- #do_GET(request, response) ⇒ Object
- #do_POST(request, response) ⇒ Object
- #do_PUT(request, response) ⇒ Object
-
#get_instance(server) ⇒ Object
A single servlet instance will be used for all requests.
-
#initialize(server) ⇒ Servlet
constructor
Builds a new servlet, taking the application from it.
Constructor Details
#initialize(server) ⇒ Servlet
Builds a new servlet, taking the application from it
34 35 36 |
# File 'lib/rubyrest/webrick.rb', line 34 def initialize( server ) @app = server.app end |
Instance Method Details
#args(request) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rubyrest/webrick.rb', line 48 def args( request ) args = Hash.new url_tokens = decode_path( request.path ).split( "/") args[:authkey] = request["token"] args[:target] = url_tokens[2] if url_tokens.length>2 args[:property] = url_tokens[3] if url_tokens.length>3 args[:path] = request.path args[:body] = RubyRest::Atom::Document.new( request.body ) if request.body return args end |
#decode_path(path) ⇒ Object
44 45 46 |
# File 'lib/rubyrest/webrick.rb', line 44 def decode_path( path ) path.gsub( "+", " ") end |
#do_DELETE(request, response) ⇒ Object
86 87 88 89 90 91 |
# File 'lib/rubyrest/webrick.rb', line 86 def do_DELETE( request, response ) params = args(request ) response.status = 200 params[:action]=:delete @app.delete( params ) end |
#do_GET(request, response) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/rubyrest/webrick.rb', line 59 def do_GET( request, response ) params = args(request ) response.status = 200 params[:action]=:retrieve xml = @app.retrieve( params ) response["content-type"]=params[:content_type] xml.write( response.body ) end |
#do_POST(request, response) ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/rubyrest/webrick.rb', line 68 def do_POST( request, response ) params = args(request ) response.status = 201 params[:action]=:create xml = @app.create( params ) response["content-type"]=params[:content_type] xml.write( response.body ) end |
#do_PUT(request, response) ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/rubyrest/webrick.rb', line 77 def do_PUT( request, response ) params = args(request ) response.status = 200 params[:action]=:update xml = @app.update( params ) response["content-type"]=params[:content_type] xml.write( response.body ) end |
#get_instance(server) ⇒ Object
A single servlet instance will be used for all requests
40 41 42 |
# File 'lib/rubyrest/webrick.rb', line 40 def get_instance( server ) self end |