Mootools XMLRPC 0.0.1
An implementation of XMLRPC, following the specs on "http://www.xmlrpc.com/spec". Tested using the XML_RPC2 class in PHPs PEAR and "XML-RPC for PHP" (http://phpxmlrpc.sourceforge.net/).
Details
- Author
- Alex Hofbauer
- Current version
- 0.0.1
- GitHub
- aleho/mootools-xmlrpc
- Downloads
- 3595
- Category
- Request
- Tags
- Report
- GitHub Issues
Releases
Dependencies
- _self_/_current_: XMLRPC
-
core/1.2.4:
- Native
- Class
- Class.Extras
- Event
- Request
How to use
Usage is similar to MooTools' Request class (it has events for onSuccess and onRequest).
var rpc = new XMLRPC.call({
url: 'http://someurl/somescript.php',
// will not add an empty params tag to the method call
addEmptyParams: false
});
You could also customize the request further (in this example it can be accessed as rpc.Request).
To send the request, use the method send(). It's first parameter is the name of the remote method to call. The second parameter can be empty (for remote methods that don't expect any parameters) or an Array of datatypes representing each parameter of the method containing the data to parse and send as XML.
rpc.send('TestClass.test', [
new Hash({
integer: 22,
bool: true,
double: (23).setTag('double')
}),
false
]);
For each call to send with a method the XML is stored so you can later use send() without parameters to resend the request, the default link-behaviour for the Request is 'chain'.
Options
Most parameters set options of the Request-object.
- url: Default: '/'.
- method: Default: 'post'.
- encoding: Default: 'utf-8'.
- headers: Headers of the Request. Defaults to: {'Content-Type': 'text/xml', 'Accept': 'text/xml, application/xml, text/html' }
- addEmptyParams: Default: true. Some servers expect an empty params-tag for methods without parameters.
Events
onSuccess / onFailure, see: http://mootools.net/docs/core/Request/Request
Methods
- send(remoteMethod, params), if no parameters are passed stored XML will be resent (if available)
- methodCall(method, params), returns the body of an XMLRPC call (used by send())
Properties
- Request, the MooTools Request object
- storedXML, the XML after using send()
Complete Example
window.addEvent('domready', function() {
var rpc = new XMLRPC.call({
url: '/mootools-xmlrpc/server.php',
onSuccess: function(response, responseText) {
var debug = response.debug();
if (Browser.Engine.gecko && typeof console == 'object') {
console.log(response);
}
try {
if (Browser.Engine.trident) {
var newline = '<br>\n';
debug = debug.toString().replace(/\n/g, '<br>');
} else {
var newline = '\n';
}
$('response').set('html',
debug +
newline + newline +
XMLRPC.encode(responseText.replace(/>/g, '>'))
);
} catch (err) {
$('response').set('html', 'error: setting debug-output\n'+err);
}
},
onFailure: function(xhr) {
if (Browser.Engine.gecko && typeof console == 'object') {
console.log(xhr);
}
}
}).send('TestClass.test', [
new Hash({
integer: 22,
bool: true,
string: '<Vienna & al >',
date: new Date(2009, 12, 20, 15, 16, 00).setTimezone('Z')
}),
// try setting this to false
true
]);
});
Discuss
A note on comments here: These comments are moderated. No comments will show up until they are approved. Comments that are not productive (i.e. inflammatory, rude, etc) will not be approved.
Found a bug in this plugin? Please report it this repository's Github Issues.
blog comments powered by Disqus