Class: ActionWebService::Protocol::XmlRpc::XmlRpcProtocol
Overview
Class Method Summary
collapse
Instance Method Summary
collapse
-
#decode_action_pack_request(action_pack_request) ⇒ Object
-
#decode_request(raw_request, service_name) ⇒ Object
-
#decode_response(raw_response) ⇒ Object
-
#encode_multicall_response(responses, protocol_options = {}) ⇒ Object
-
#encode_request(method_name, params, param_types) ⇒ Object
-
#encode_response(method_name, return_value, return_type, protocol_options = {}) ⇒ Object
-
#protocol_client(api, protocol_name, endpoint_uri, options = {}) ⇒ Object
-
#value_to_xmlrpc_wire_format(value, value_type) ⇒ Object
#encode_action_pack_request, #register_api, #setup
Class Method Details
.create(controller) ⇒ Object
36
37
38
|
# File 'lib/action_web_service/protocol/xmlrpc_protocol.rb', line 36
def self.create(controller)
XmlRpcProtocol.new
end
|
Instance Method Details
#decode_action_pack_request(action_pack_request) ⇒ Object
40
41
42
43
|
# File 'lib/action_web_service/protocol/xmlrpc_protocol.rb', line 40
def decode_action_pack_request(action_pack_request)
service_name = action_pack_request.parameters['action']
decode_request(action_pack_request.raw_post, service_name)
end
|
#decode_request(raw_request, service_name) ⇒ Object
45
46
47
48
49
50
|
# File 'lib/action_web_service/protocol/xmlrpc_protocol.rb', line 45
def decode_request(raw_request, service_name)
method_name, params = XMLRPC::Marshal.load_call(raw_request)
Request.new(self, method_name, params, service_name)
rescue
return nil
end
|
#decode_response(raw_response) ⇒ Object
60
61
62
|
# File 'lib/action_web_service/protocol/xmlrpc_protocol.rb', line 60
def decode_response(raw_response)
[nil, XMLRPC::Marshal.load_response(raw_response)]
end
|
#encode_multicall_response(responses, protocol_options = {}) ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/action_web_service/protocol/xmlrpc_protocol.rb', line 73
def encode_multicall_response(responses, protocol_options={})
result = responses.map do |return_value, return_type|
if return_value && return_type
return_value = value_to_xmlrpc_wire_format(return_value, return_type)
return_value = [return_value] unless return_value.nil?
end
return_value = false if return_value.nil?
return_value
end
raw_response = XMLRPC::Marshal.dump_response(result)
Response.new(raw_response, 'text/xml', result)
end
|
#encode_request(method_name, params, param_types) ⇒ Object
52
53
54
55
56
57
58
|
# File 'lib/action_web_service/protocol/xmlrpc_protocol.rb', line 52
def encode_request(method_name, params, param_types)
if param_types
params = params.dup
param_types.each_with_index{ |type, i| params[i] = value_to_xmlrpc_wire_format(params[i], type) }
end
XMLRPC::Marshal.dump_call(method_name, *params)
end
|
#encode_response(method_name, return_value, return_type, protocol_options = {}) ⇒ Object
64
65
66
67
68
69
70
71
|
# File 'lib/action_web_service/protocol/xmlrpc_protocol.rb', line 64
def encode_response(method_name, return_value, return_type, protocol_options={})
if return_value && return_type
return_value = value_to_xmlrpc_wire_format(return_value, return_type)
end
return_value = false if return_value.nil?
raw_response = XMLRPC::Marshal.dump_response(return_value)
Response.new(raw_response, 'text/xml', return_value)
end
|
#protocol_client(api, protocol_name, endpoint_uri, options = {}) ⇒ Object
86
87
88
89
|
# File 'lib/action_web_service/protocol/xmlrpc_protocol.rb', line 86
def protocol_client(api, protocol_name, endpoint_uri, options={})
return nil unless protocol_name == :xmlrpc
ActionWebService::Client::XmlRpc.new(api, endpoint_uri, options)
end
|
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/action_web_service/protocol/xmlrpc_protocol.rb', line 91
def value_to_xmlrpc_wire_format(value, value_type)
if value_type.array?
value.map{ |val| value_to_xmlrpc_wire_format(val, value_type.element_type) }
else
if value.is_a?(ActionWebService::Struct)
struct = {}
value.class.members.each do |name, type|
member_value = value[name]
next if member_value.nil?
struct[name.to_s] = value_to_xmlrpc_wire_format(member_value, type)
end
struct
elsif value.is_a?(ActiveRecord::Base)
struct = {}
value.attributes.each do |key, member_value|
next if member_value.nil?
struct[key.to_s] = member_value
end
struct
elsif value.is_a?(ActionWebService::Base64)
XMLRPC::Base64.new(value)
elsif value.is_a?(Exception) && !value.is_a?(XMLRPC::FaultException)
XMLRPC::FaultException.new(2, value.message)
else
value
end
end
end
|