/**
 * Gazette.Rpc - Remote procedure call interface
 *
 * This interface should be used for all RPCs in Gazette.
 * Currently uses JQuery XMLRPC plugin.
 *
 * @see xmlrpc.js
 * @todo Implement JSON alternative
 * @author Andrew Markham <andrew.markham@sitepoint.com>
 */
var Gazette = Gazette || {};
Gazette.Rpc = Gazette.Rpc || {};
/**
 * Call a remote method and execute 'callback' on completion.
 * @param string    url 		url of RPC endpoint
 * @param string    method 		RPC method
 * @param array     params 		RPC params
 * @param function  callback 	function to execute on completion
 * @param async     boolean 	execute asynchronously (true) or synchronously (false)
 */
Gazette.Rpc.call = function(url, method, params, callback, async)
{
	$.xmlrpc(url, method, params, callback, async || true);
};	
/**
 * Parses the RPC response into a Javascript object
 * @param XMLHttpResponse response;
 * @return object
 */
Gazette.Rpc.parseResponse = function(response)
{
	var o = new Object;
	$(response.responseXML).find('member').each(function(){
		name    = $(this).find('name').text();
		o[name] = $(this).find('value').text();
	});
	return o;
};
/**
 * Call a remote method but don't wait for a response.
 * @param string url    url of RPC server
 * @param string method RPC method
 * @param array  params RPC params
 */
Gazette.Rpc.notify = function(url, method, params)
{
	$.xmlrpcNotify(url, method, params);
};
