Class: Rack::AMF::Response
- Inherits:
-
Object
- Object
- Rack::AMF::Response
- Defined in:
- lib/rack/amf/response.rb
Overview
Rack specific wrapper around AMF::Response
Constant Summary collapse
Instance Attribute Summary collapse
-
#raw_response ⇒ Object
readonly
Returns the value of attribute raw_response.
Instance Method Summary collapse
-
#each_method_call(&block) ⇒ Object
Builds response, iterating over each method call and using the return value as the method call’s return value – Iterate over all the sent messages.
-
#initialize(request) ⇒ Response
constructor
A new instance of Response.
-
#to_s ⇒ Object
Return the serialized response as a string.
Constructor Details
#initialize(request) ⇒ Response
Returns a new instance of Response.
8 9 10 11 12 |
# File 'lib/rack/amf/response.rb', line 8 def initialize request @request = request @raw_response = ::AMF::Response.new @raw_response.amf_version = @request.version == 3 ? 3 : 0 # Can't just copy version because FMS sends version as 1 end |
Instance Attribute Details
#raw_response ⇒ Object (readonly)
Returns the value of attribute raw_response.
4 5 6 |
# File 'lib/rack/amf/response.rb', line 4 def raw_response @raw_response end |
Instance Method Details
#each_method_call(&block) ⇒ Object
Builds response, iterating over each method call and using the return value as the method call’s return value – Iterate over all the sent messages. If they’re somthing we can handle, like a command message, then simply add the response message ourselves. If it’s a method call, then call the block with the method and args, catching errors for handling. Then create the appropriate response message using the return value of the block as the return value for the method call.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/rack/amf/response.rb', line 22 def each_method_call &block raise 'Response already constructed' if @constructed @request..each do |m| # What's the request body? case m.data when V::CommandMessage # Pings should be responded to with an AcknowledgeMessage built using the ping # Everything else is unsupported command_msg = m.data if command_msg.operation == V::CommandMessage::CLIENT_PING_OPERATION response_value = V::AcknowledgeMessage.new(command_msg) else response_value = V::ErrorMessage.new(Exception.new("CommandMessage #{command_msg.operation} not implemented"), command_msg) end when V::RemotingMessage # Using RemoteObject style message calls remoting_msg = m.data acknowledge_msg = V::AcknowledgeMessage.new(remoting_msg) body = dispatch_call :method => remoting_msg.source+'.'+remoting_msg.operation, :args => remoting_msg.body, :source => remoting_msg, :block => block # Response should be the bare ErrorMessage if there was an error if body.is_a?(V::ErrorMessage) response_value = body else acknowledge_msg.body = body response_value = acknowledge_msg end else # Standard response message response_value = dispatch_call :method => m.target_uri, :args => m.data, :source => m, :block => block end target_uri = m.response_uri target_uri += response_value.is_a?(V::ErrorMessage) ? '/onStatus' : '/onResult' @raw_response. << ::AMF::Message.new(target_uri, '', response_value) end @constructed = true end |
#to_s ⇒ Object
Return the serialized response as a string
64 65 66 |
# File 'lib/rack/amf/response.rb', line 64 def to_s raw_response.serialize end |