Class: Rack::AMF::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/amf/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ Response

Returns a new instance of Response.



5
6
7
8
# File 'lib/rack/amf/response.rb', line 5

def initialize request
  @request = request
  @raw_response = ::AMF::Response.new
end

Instance Attribute Details

#raw_responseObject (readonly)

Returns the value of attribute raw_response.



3
4
5
# File 'lib/rack/amf/response.rb', line 3

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



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rack/amf/response.rb', line 12

def each_method_call &block
  @request.messages.each do |m|
    target_uri = m.response_uri

    rd = m.data
    if rd.is_a?(::AMF::Values::CommandMessage)
      if rd.operation == ::AMF::Values::CommandMessage::CLIENT_PING_OPERATION
        data = ::AMF::Values::AcknowledgeMessage.new(rd)
      else
        data == ::AMF::Values::ErrorMessage.new(Exception.new("CommandMessage #{rd.operation} not implemented"), rd)
      end
    elsif rd.is_a?(::AMF::Values::RemotingMessage)
      am = ::AMF::Values::AcknowledgeMessage.new(rd)
      body = dispatch_call(rd.source+'.'+rd.operation, rd.body, rd, block)
      if body.is_a?(::AMF::Values::ErrorMessage)
        data = body
      else
        am.body = body
        data = am
      end
    else
      data = dispatch_call(m.target_uri, rd, m, block)
    end

    target_uri += data.is_a?(::AMF::Values::ErrorMessage) ? '/onStatus' : '/onResult'
    @raw_response.messages << ::AMF::Message.new(target_uri, '', data)
  end
end

#to_sObject



41
42
43
# File 'lib/rack/amf/response.rb', line 41

def to_s
  raw_response.serialize
end