Module: JsonRpc

Defined in:
lib/json-rpc.rb

Defined Under Namespace

Modules: Rpc

Instance Method Summary collapse

Instance Method Details

#rpc_call(env, &ecb) ⇒ Object

Call the correct method for each query The method should be prefixed by rpc_ If the method doesn’t exists, an error will be return in JSON More details in groups.google.com/group/json-rpc/web/json-rpc-2-0



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/json-rpc.rb', line 11

def rpc_call env, &ecb
  begin
    request = Rpc::parse env
    status = Rpc::validate request
    result = Rpc::route request, self
  rescue Exception, Rpc::Error => e
    ecb.call(e) if ecb
   unless e.is_a?(Rpc::Error)
      e = Rpc::error :internal_error
    end
    status = e.status
    result = e.result
  end

  header = {'Content-Type' => Rpc::ContentType}

  if result.is_a?(Rpc::AsyncResult)
    result.env = env
    result.status = status
    result.header = header
    return [-1, {}, result]
  end

  [status, header, result]
end