From 55d9a312fbba91f1bcf5e3f3291b7bece8abb178 Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Thu, 28 Apr 2011 13:28:55 +0200 Subject: Reformatting to MoFo coding style --- lib/xmlrpc.js | 83 +++++++++++++++++++++++++++++++---------------------------- 1 file changed, 44 insertions(+), 39 deletions(-) (limited to 'lib/xmlrpc.js') 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 += "\n"; // do individual parameters - this.params.forEach(function (data) { + this.params.forEach(function(data) { xml += "\n"; - xml += "" + - this.getParamXML(this.dataTypeOf(data), - data) + "\n"; + xml += "" + + this.getParamXML(this.dataTypeOf(data), data) + + "\n"; xml += "\n"; }, this); xml += "\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 + ""; return xml; }; -XMLRPCMessage.prototype.doBooleanXML = function (data) { +XMLRPCMessage.prototype.doBooleanXML = function(data) { var value = (data === true) ? 1 : 0; var xml = "" + value + ""; return xml; }; -XMLRPCMessage.prototype.doDateXML = function (data) { +XMLRPCMessage.prototype.doDateXML = function(data) { var xml = ""; xml += dateToISO8601(data); xml += ""; return xml; }; -XMLRPCMessage.prototype.doArrayXML = function (data) { +XMLRPCMessage.prototype.doArrayXML = function(data) { var xml = "\n"; - for (var i = 0; i < data.length; i++) { - xml += "" + - this.getParamXML(this.dataTypeOf(data[i]), - data[i]) + "\n"; + for ( var i = 0; i < data.length; i++) { + xml += "" + + this.getParamXML(this.dataTypeOf(data[i]), data[i]) + + "\n"; } xml += "\n"; return xml; }; -XMLRPCMessage.prototype.doStructXML = function (data) { +XMLRPCMessage.prototype.doStructXML = function(data) { var xml = "\n"; - for (var i in data) { + for ( var i in data) { xml += "\n"; xml += "" + i + "\n"; - xml += "" + this.getParamXML(this.dataTypeOf(data[i]), - data[i]) + "\n"; + xml += "" + + this.getParamXML(this.dataTypeOf(data[i]), data[i]) + + "\n"; xml += "\n"; } xml += "\n"; return xml; }; -XMLRPCMessage.prototype.getParamXML = function (type, data) { +XMLRPCMessage.prototype.getParamXML = function(type, data) { var xml; switch (type) { case "date": -- cgit