Class: Appcast::QueueHandler

Inherits:
BaseHandler
  • Object
show all
Defined in:
lib/appcast/handlers.rb

Instance Method Summary collapse

Methods inherited from BaseHandler

#initialize

Constructor Details

This class inherits a constructor from Appcast::BaseHandler

Instance Method Details

#process(request, response) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/appcast/handlers.rb', line 37

def process(request, response)
  case request.method
  when 'POST'
    msg = nil
    @guard.synchronize { msg = Message.create(:name => request.path, :content => request.body.read ) }
    response.start(201) { |head,out| head['Location'] = msg.location; out.write(msg.to_xml)  }
    puts "Added message at #{request.path}"
  when 'GET'
    msgs = nil
    @guard.synchronize { msgs = Message.get(request.path, request.query_params['limit'] || 10, request.query_params['lock_for'] || false) }
    response.start { |head,out| out.write(msgs.to_xml(:root => 'messages')) }
  end
rescue => e
  puts e.message
  puts e.backtrace.join("\n")
  response.start(500) {}
end