blob: b38ae81abf0a4f247e68f3babf9e31f61f173594 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
require 'xmlrpc/marshal'
module WS
module Encoding
class XmlRpcError < WSError
end
class XmlRpcEncoding < AbstractEncoding
def encode_rpc_call(method_name, params)
XMLRPC::Marshal.dump_call(method_name, *params)
end
def decode_rpc_call(obj)
method_name, params = XMLRPC::Marshal.load_call(obj) rescue nil
unless method_name && params
raise(XmlRpcError, "Malformed XML-RPC request")
end
i = 0
params = params.map do |value|
param = XmlRpcDecodedParam.new("param#{i}", value)
i += 1
param
end
[method_name, params]
end
def encode_rpc_response(method_name, return_value)
if return_value.nil?
XMLRPC::Marshal.dump_response(true)
else
XMLRPC::Marshal.dump_response(return_value)
end
end
def decode_rpc_response(obj)
return_value = XMLRPC::Marshal.load_response(obj) rescue nil
if return_value.nil?
raise(XmlRpcError, "Malformed XML-RPC response")
end
[nil, XmlRpcDecodedParam.new('return', return_value)]
end
end
class XmlRpcDecodedParam
attr :param
def initialize(name, value)
info = ParamInfo.new(name, value.class)
@param = Param.new(value, info)
end
end
end
end
|