mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-12 20:44:50 +00:00
update to allow for passing in a methods list when initialising
This commit is contained in:
parent
911d95815f
commit
b6dee74dd5
@ -52,25 +52,39 @@ JSON.RPC = new Class({
|
|||||||
this.setOptions(options)
|
this.setOptions(options)
|
||||||
this.url = url
|
this.url = url
|
||||||
if (this.options.methods.length == 0) {
|
if (this.options.methods.length == 0) {
|
||||||
var methodNames = this._execute('system.listMethods', {async: false});
|
this._setMethods(this._execute('system.listMethods', {async: false}));
|
||||||
var components = new Hash();
|
} else {
|
||||||
|
this._setMethods(this.options.methods);
|
||||||
methodNames.forEach(function(method) {
|
|
||||||
var parts = method.split('.');
|
|
||||||
var component = $pick(components[parts[0]], new Hash());
|
|
||||||
var fn = function() {
|
|
||||||
var options = this._parseargs(arguments);
|
|
||||||
return this._execute(method, options);
|
|
||||||
}.bind(this);
|
|
||||||
component[parts[1]] = fn;
|
|
||||||
components[parts[0]] = component;
|
|
||||||
}, this);
|
|
||||||
|
|
||||||
components.each(function(methods, name) {
|
|
||||||
this[name] = methods;
|
|
||||||
}, this);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Property: _setMethods
|
||||||
|
Internal method for settings the methods up
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
methodNames - A list of the method names available.
|
||||||
|
|
||||||
|
*/
|
||||||
|
_setMethods: function(methodNames) {
|
||||||
|
var components = new Hash();
|
||||||
|
|
||||||
|
methodNames.forEach(function(method) {
|
||||||
|
var parts = method.split('.');
|
||||||
|
var component = $pick(components[parts[0]], new Hash());
|
||||||
|
var fn = function() {
|
||||||
|
var options = this._parseargs(arguments);
|
||||||
|
return this._execute(method, options);
|
||||||
|
}.bind(this);
|
||||||
|
component[parts[1]] = fn;
|
||||||
|
components[parts[0]] = component;
|
||||||
|
}, this);
|
||||||
|
|
||||||
|
components.each(function(methods, name) {
|
||||||
|
this[name] = methods;
|
||||||
|
}, this);
|
||||||
|
},
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Property: _parseargs
|
Property: _parseargs
|
||||||
|
Loading…
x
Reference in New Issue
Block a user