add a bit more documentation to it

This commit is contained in:
Damien Churchill 2008-11-08 11:09:54 +00:00
parent 83875bf7f2
commit 1dfdcdf1f3
1 changed files with 32 additions and 12 deletions

View File

@ -1,16 +1,10 @@
/* /*
* Script: Rpc.js Script: Rpc.js
* A JSON-RPC proxy built ontop of mootools. A JSON-RPC proxy built ontop of mootools.
*
* Copyright: Copyright:
* Damien Churchill (c) 2008 <damoxc@gmail.com> Damien Churchill (c) 2008 <damoxc@gmail.com>
*/
/*
* A class that creates a proxy for sending remote procedure calls over JSON
*/
/*
Class: JSON.RPC Class: JSON.RPC
Class to create a proxy to a json-rpc interface on a server. Class to create a proxy to a json-rpc interface on a server.
@ -21,7 +15,7 @@
alert(result); alert(result);
} }
}); });
alert(client.hello_world({async: true;})); alert(client.hello_world({async: false;}));
client.add_name('Damien', { client.add_name('Damien', {
onSuccess: function(result) { onSuccess: function(result) {
alert(result); alert(result);
@ -52,6 +46,17 @@ JSON.RPC = new Class({
} }
}, },
/*
Property: _parseargs
Internal method for parsing the arguments given to the method
Arguments:
args - A list of the methods arguments
Returns:
An options object with the arguments set as options.params
*/
_parseargs: function(args) { _parseargs: function(args) {
var params = $A(args), options = params.getLast() var params = $A(args), options = params.getLast()
if ($type(options) == 'object') { if ($type(options) == 'object') {
@ -75,6 +80,21 @@ JSON.RPC = new Class({
return options return options
}, },
/*
Property: _execute
An internal method to make the call to the rpc page
Arguements:
method - the name of the method
options - An options dict providing any additional options for the
call.
Example:
alert(client.hello_world({async: false;}));
Returns:
If not async returns the json result
*/
_execute: function(method, options) { _execute: function(method, options) {
options = $pick(options, {}) options = $pick(options, {})
options.params = $pick(options.params, []) options.params = $pick(options.params, [])