Class: Howlr::Controllers::Messages
- Inherits:
-
REST
- Object
- REST
- Howlr::Controllers::Messages
- Defined in:
- lib/howlr/controllers.rb
Overview
Messages are created and delivered via this resource.
Constant Summary collapse
- @@messages =
Contains a list of messages that were created. Note that this is not persistent! This value is wiped when the server is shut down.
[]
Instance Method Summary collapse
-
#create ⇒ Object
Create and send a new message.
-
#list ⇒ Object
Show some information about messages sent out since last reboot.
-
#new ⇒ Object
Render a form for manually inputing a new message.
-
#read(id) ⇒ Object
Show the message with the given id created by this server.
Instance Method Details
#create ⇒ Object
Create and send a new message.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/howlr/controllers.rb', line 44 def create if input['rest'] == '1' && input['0'] # for PHP Zend_Rest_Client compatibility data = input['0'] else data = input end data[:author] ||= @env['REMOTE_HOST'] $LOG.debug "Creating new message from: #{data.inspect}" @message = Howlr::Message.new(HashWithIndifferentAccess.new(data)) $LOG.debug "Sending message: #{@message.inspect}" @@messages << @message begin @message.send rescue Howlr::Message::CallbackError => e return _error("Error while executing callback: #{e.}", 500, e.) rescue => e return _error("Error while sending message: #{e.}", 500, e) end @headers['Location'] = "/messages/#{@message.id}?format=#{@format}" render :message end |
#list ⇒ Object
Show some information about messages sent out since last reboot.
76 77 78 79 |
# File 'lib/howlr/controllers.rb', line 76 def list @messages = @@messages render :message_list end |
#new ⇒ Object
Render a form for manually inputing a new message.
28 29 30 |
# File 'lib/howlr/controllers.rb', line 28 def new render :new_message end |
#read(id) ⇒ Object
Show the message with the given id created by this server.
33 34 35 36 37 38 39 40 41 |
# File 'lib/howlr/controllers.rb', line 33 def read(id) @message = @@messages.find{|m| m.id == id} puts @format if @message render :message else _error("There is no recently sent message with id #{id}.", 404) end end |