Module: Appcelerator::Dispatcher
- Defined in:
- lib/appcelerator/dispatcher.rb
Defined Under Namespace
Classes: Message
Class Method Summary collapse
-
.dispatch_message(request, response, session, message_type, params, request_id) ⇒ Object
dispatch a message that was generated in some other way, like the upload_controller.
-
.dispatch_request(request, response, session) ⇒ Object
dispatch a standard request, called by the service_broker_controller.
- .extract_messages(request, session) ⇒ Object
- .serialize(message_queue, session_id, output) ⇒ Object
Class Method Details
.dispatch_message(request, response, session, message_type, params, request_id) ⇒ Object
dispatch a message that was generated in some other way, like the upload_controller
17 18 19 20 21 22 23 |
# File 'lib/appcelerator/dispatcher.rb', line 17 def self.(request, response, session, , params, request_id) msg = Message.new(request, session, , params, request_id) = ServiceBroker.send(msg) serialize(, session.session_id, response.body) end |
.dispatch_request(request, response, session) ⇒ Object
dispatch a standard request, called by the service_broker_controller
6 7 8 9 10 11 12 13 |
# File 'lib/appcelerator/dispatcher.rb', line 6 def self.dispatch_request(request, response, session) = [] (request, session) do || = ServiceBroker.send() .concat() end serialize(, session.session_id, response.body) end |
.extract_messages(request, session) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/appcelerator/dispatcher.rb', line 25 def self.(request, session) body = request.env['RAW_POST_DATA'] if body and body != '' node = REXML::Document.new(body) node.root.each_element('//message') do || request_id = .attributes['requestid'] = .attributes['type'] params = JSON.parse(.text) yield Message.new(request, session, , params, request_id) end end end |
.serialize(message_queue, session_id, output) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/appcelerator/dispatcher.rb', line 40 def self.serialize(, session_id, output) output << '<?xml version="1.0"?>' output << "<messages version='1.0' sessionid='#{session_id}'>" .compact! .each do |msg| if msg.response_type output << "<message requestid='#{msg.request_id}' direction='OUTGOING' datatype='JSON' type='#{msg.response_type}'><![CDATA[" output << msg.response.to_json output << ']]></message>' end end output << '</messages>' end |