aboutsummaryrefslogtreecommitdiffstats
path: root/lib/xmlrpc.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/xmlrpc.js')
-rw-r--r--lib/xmlrpc.js83
1 files changed, 44 insertions, 39 deletions
diff --git a/lib/xmlrpc.js b/lib/xmlrpc.js
index e038c4e..3991b04 100644
--- a/lib/xmlrpc.js
+++ b/lib/xmlrpc.js
@@ -3,41 +3,44 @@
// Modification of Matěj Cepl released under the MIT/X11 license
// http://www.opensource.org/licenses/mit-license.php
/*
- *
+ *
* xmlrpc.js beta version 1 Tool for creating XML-RPC formatted requests in
* JavaScript
- *
+ *
* Copyright 2001 Scott Andrew LePera scott@scottandrew.com
- *
- *
+ *
+ *
* License: You are granted the right to use and/or redistribute this code only
* if this license and the copyright notice are included and you accept that no
* warranty of any kind is made or implied by the author.
- *
+ *
*/
/**
* checks whether parameter is an array
- *
- * @param obj Object
+ *
+ * @param obj
+ * Object
* @return Boolean true if obj is array
- *
+ *
* The problem is that in different contexts, Array is not same, and so obj is
* not an instance of SAME Array.
*/
/**
* pads a single number with a leading zero. Heh.
- *
- * @param n String or Number
+ *
+ * @param n
+ * String or Number
* @return String with leading zero added if necessary
- *
+ *
* If the real parameter is not numerical, it is just returned as it is.
*/
var leadingZero = exports.leadingZero = function leadingZero(n) {
if (isNaN(Number(n))) {
return n;
- };
+ }
+ ;
var s = "0" + n;
if (s.length > 2) {
@@ -46,22 +49,24 @@ var leadingZero = exports.leadingZero = function leadingZero(n) {
return s;
};
-var dateToISO8601 = exports.dateToISO8601 = function dateToISO8601(date) {
+var dateToISO8601 = exports.dateToISO8601 = function dateToISO8601(
+ date) {
// wow I hate working with the Date object
console.log("date = " + date);
var year = date.getYear();
var month = leadingZero(date.getMonth());
var day = leadingZero(date.getDate());
- var time = leadingZero(date.getHours()) +
- ":" + leadingZero(date.getMinutes()) +
- ":" + leadingZero(date.getSeconds());
+ var time = leadingZero(date.getHours()) + ":"
+ + leadingZero(date.getMinutes()) + ":"
+ + leadingZero(date.getSeconds());
var converted = year + month + day + "T" + time;
console.log("date = " + converted);
return converted;
};
-var XMLRPCMessage = exports.XMLRPCMessage = function XMLRPCMessage(methodname) {
+var XMLRPCMessage = exports.XMLRPCMessage = function XMLRPCMessage(
+ methodname) {
this.method = methodname || "system.listMethods";
this.params = [];
return this;
@@ -71,20 +76,19 @@ XMLRPCMessage.prototype.myIsArray = function myIsArray(obj) {
return (typeof obj.sort === 'function');
};
-
-XMLRPCMessage.prototype.setMethod = function (methodName) {
+XMLRPCMessage.prototype.setMethod = function(methodName) {
if (methodName !== undefined) {
this.method = methodName;
}
};
-XMLRPCMessage.prototype.addParameter = function (data) {
+XMLRPCMessage.prototype.addParameter = function(data) {
if (data !== undefined) {
this.params.push(data);
}
};
-XMLRPCMessage.prototype.xml = function () {
+XMLRPCMessage.prototype.xml = function() {
var method = this.method;
@@ -97,11 +101,11 @@ XMLRPCMessage.prototype.xml = function () {
xml += "<params>\n";
// do individual parameters
- this.params.forEach(function (data) {
+ this.params.forEach(function(data) {
xml += "<param>\n";
- xml += "<value>" +
- this.getParamXML(this.dataTypeOf(data),
- data) + "</value>\n";
+ xml += "<value>"
+ + this.getParamXML(this.dataTypeOf(data), data)
+ + "</value>\n";
xml += "</param>\n";
}, this);
xml += "</params>\n";
@@ -110,7 +114,7 @@ XMLRPCMessage.prototype.xml = function () {
return xml; // for now
};
-XMLRPCMessage.prototype.dataTypeOf = function (o) {
+XMLRPCMessage.prototype.dataTypeOf = function(o) {
// identifies the data type
var type = typeof (o);
type = type.toLowerCase();
@@ -138,49 +142,50 @@ XMLRPCMessage.prototype.dataTypeOf = function (o) {
return type;
};
-XMLRPCMessage.prototype.doValueXML = function (type, data) {
+XMLRPCMessage.prototype.doValueXML = function(type, data) {
var xml = "<" + type + ">" + data + "</" + type + ">";
return xml;
};
-XMLRPCMessage.prototype.doBooleanXML = function (data) {
+XMLRPCMessage.prototype.doBooleanXML = function(data) {
var value = (data === true) ? 1 : 0;
var xml = "<boolean>" + value + "</boolean>";
return xml;
};
-XMLRPCMessage.prototype.doDateXML = function (data) {
+XMLRPCMessage.prototype.doDateXML = function(data) {
var xml = "<dateTime.iso8601>";
xml += dateToISO8601(data);
xml += "</dateTime.iso8601>";
return xml;
};
-XMLRPCMessage.prototype.doArrayXML = function (data) {
+XMLRPCMessage.prototype.doArrayXML = function(data) {
var xml = "<array><data>\n";
- for (var i = 0; i < data.length; i++) {
- xml += "<value>" +
- this.getParamXML(this.dataTypeOf(data[i]),
- data[i]) + "</value>\n";
+ for ( var i = 0; i < data.length; i++) {
+ xml += "<value>"
+ + this.getParamXML(this.dataTypeOf(data[i]), data[i])
+ + "</value>\n";
}
xml += "</data></array>\n";
return xml;
};
-XMLRPCMessage.prototype.doStructXML = function (data) {
+XMLRPCMessage.prototype.doStructXML = function(data) {
var xml = "<struct>\n";
- for (var i in data) {
+ for ( var i in data) {
xml += "<member>\n";
xml += "<name>" + i + "</name>\n";
- xml += "<value>" + this.getParamXML(this.dataTypeOf(data[i]),
- data[i]) + "</value>\n";
+ xml += "<value>"
+ + this.getParamXML(this.dataTypeOf(data[i]), data[i])
+ + "</value>\n";
xml += "</member>\n";
}
xml += "</struct>\n";
return xml;
};
-XMLRPCMessage.prototype.getParamXML = function (type, data) {
+XMLRPCMessage.prototype.getParamXML = function(type, data) {
var xml;
switch (type) {
case "date":