Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix ident

  • Loading branch information...
commit 1f2c4c903c9667e143fce4418d211a991490e3d0 1 parent 0f6eb32
@gierschv authored
Showing with 206 additions and 203 deletions.
  1. +1 −1  .jshintrc
  2. +20 −16 README.md
  3. +122 −123 ovh.js
  4. +48 −48 tests/01_checkWS.js
  5. +15 −15 tests/02_calls.js
View
2  .jshintrc
@@ -115,5 +115,5 @@
//"anotherCoolGlobal",
//"iLoveDouglas"
],
- "indent" : 4 // Specify indentation spacing
+ "indent" : 2 // Specify indentation spacing
}
View
36 README.md
@@ -8,26 +8,30 @@ node-ovh is a Node.js helper library for OVH web services. The module usage is s
Installation
------------
- npm install ovh
+```javascript
+$ npm install ovh
+```
Example
--------
- var ovh = require('ovh');
-
- // Instance a new OVH WS with used WS. Keys must be the WS prefixes
- var Ows = ovh({
- sessionHandler: 'sessionHandler/r4',
- cloudInstance: 'cloud/public/instance/r3'
- });
-
- // Example of a WS Call (https://ws.ovh.com/sessionHandler/r4/documentation.html)
- Ows.sessionHandler.getAnonymousSession.call({
- language : 'fr',
- secured : false
- }, function (success, reponse) {
- console.log(!success || reponse.session.id);
- });
+```javascript
+var ovh = require('ovh');
+
+// Instance a new OVH WS with used WS. Keys must be the WS prefixes
+var Ows = ovh({
+ sessionHandler: 'sessionHandler/r4',
+ cloudInstance: 'cloud/public/instance/r3'
+});
+
+// Example of a WS Call (https://ws.ovh.com/sessionHandler/r4/documentation.html)
+Ows.sessionHandler.getAnonymousSession.call({
+ language : 'fr',
+ secured : false
+}, function (success, reponse) {
+ console.log(!success || reponse.session.id);
+});
+```
Changelog
---------
View
245 ovh.js
@@ -11,144 +11,143 @@ var https = require('https'),
handlerMaker = require("./handler-maker");
(function () {
- "use strict";
-
- function OVHWS(wsList, wsServer) {
- this.wsList = wsList;
- this.wsMetas = {};
- this.wsServer = wsServer;
-
- var handler = handlerMaker(this),
- _this = this;
+ "use strict";
+
+ function OVHWS(wsList, wsServer) {
+ this.wsList = wsList;
+ this.wsMetas = {};
+ this.wsServer = wsServer;
+
+ var handler = handlerMaker(this),
+ _this = this;
+
+ // Catch WS name get
+ handler.get = function (target, name) {
+ if (typeof _this[name] !== "undefined") {
+ return _this[name];
+ }
+
+ if (_this.wsList[name] === undefined) {
+ return undefined;
+ }
+
+ // Catch the WS methods calls
+ var handler = handlerMaker();
+ handler.ws = name;
+ handler.get = function (target, name) {
+ var ws = this.ws;
+ return {
+ call: function (params, callback) {
+ return _this.call(ws, name, params, callback);
+ }
+ };
+ };
- // Catch WS name get
- handler.get = function (target, name) {
- if (typeof _this[name] !== "undefined") {
- return _this[name];
- }
+ return proxy.create(handler);
+ };
- if (_this.wsList[name] === undefined) {
- return undefined;
- }
+ return proxy.create(handler);
+ }
- // Catch the WS methods calls
- var handler = handlerMaker();
- handler.ws = name;
- handler.get = function (target, name) {
- var ws = this.ws;
- return {
- call: function (params, callback) {
- return _this.call(ws, name, params, callback);
- }
- };
- };
-
- return proxy.create(handler);
- };
+ // Call a ws method
+ OVHWS.prototype.call = function (ws, method, params, callback) {
+ var options = {
+ host: this.wsServer,
+ port: 443,
+ method: 'GET',
+ path: '/' + this.wsList[ws] + '/rest.dispatcher/' + method + '?' + querystring.stringify({ params: JSON.stringify(params) })
+ };
- return proxy.create(handler);
- }
+ var req = https.request(options, function (res) {
+ if (res.statusCode !== 200) {
+ callback(false, 'HTTP error code ' + res.statusCode);
+ }
+ else {
+ var body = '';
+ res.on('data', function (chunk) {
+ body += chunk;
+ });
- // Call a ws method
- OVHWS.prototype.call = function (ws, method, params, callback) {
- var options = {
- host: this.wsServer,
- port: 443,
- method: 'GET',
- path: '/' + this.wsList[ws] + '/rest.dispatcher/' + method + '?' + querystring.stringify({ params: JSON.stringify(params) })
- };
+ res.on('end', function () {
+ try {
+ var response = JSON.parse(body);
- var req = https.request(options, function (res) {
- if (res.statusCode !== 200) {
- callback(false, 'HTTP error code ' + res.statusCode);
+ if (response.error) {
+ callback(false, response.error);
}
else {
- var body = '';
- res.on('data', function (chunk) {
- body += chunk;
- });
-
- res.on('end', function () {
- try {
- var response = JSON.parse(body);
-
- if (response.error) {
- callback(false, response.error);
- }
- else {
- callback(true, response.answer);
- }
- } catch (e) {
- callback(false, 'Unable to parse JSON reponse');
- }
- });
+ callback(true, response.answer);
}
+ } catch (e) {
+ callback(false, 'Unable to parse JSON reponse');
+ }
});
+ }
+ });
+
+ req.on('error', function (e) {
+ callback(false, e.errno);
+ });
+
+ req.end();
+ };
+
+ // Check the existence of WS schemas
+ // @param callback(wsPrefix, success, errorMsg)
+ OVHWS.prototype.checkWS = function (callback) {
+ var _this = this;
+
+ var checkWS = function (k) {
+ var options = {
+ host: _this.wsServer,
+ port: 443,
+ method: 'GET',
+ path: '/' + _this.wsList[k] + '/schema.json'
+ };
+
+ var _k = k;
+
+ var req = https.request(options, function (res) {
+ if (res.statusCode !== 200) {
+ callback(k, false, 'Unable to find WS ' + _this.wsList[k]);
+ }
+ else {
+ var body = '';
+ res.on('data', function (chunk) {
+ body += chunk;
+ });
+
+ res.on('end', function () {
+ var wsMeta = JSON.parse(body);
+ if (wsMeta.servicesInformations.prefix !== k) {
+ callback(k, false, 'Your WS prefix should be ' + wsMeta.servicesInformations.prefix + ' instead of ' + k);
+ }
+ else {
+ callback(k, true);
+ }
+ _this.wsMetas[k] = wsMeta;
+ });
+ }
+ });
- req.on('error', function (e) {
- callback(false, e.errno);
- });
+ req.on('error', function (e) {
+ callback(k, false, 'Unable to fetch WS schema ' + _this.wsList[k]);
+ });
- req.end();
+ req.end();
};
- // Check the existence of WS schemas
- // @param callback(wsPrefix, success, errorMsg)
- OVHWS.prototype.checkWS = function (callback) {
- var _this = this;
-
- var checkWS = function (k) {
- var options = {
- host: _this.wsServer,
- port: 443,
- method: 'GET',
- path: '/' + _this.wsList[k] + '/schema.json'
- };
-
- var _k = k;
-
- var req = https.request(options, function (res) {
- if (res.statusCode !== 200) {
- callback(k, false, 'Unable to find WS ' + _this.wsList[k]);
- }
- else {
- var body = '';
- res.on('data', function (chunk) {
- body += chunk;
- });
-
- res.on('end', function () {
- var wsMeta = JSON.parse(body);
- if (wsMeta.servicesInformations.prefix !== k) {
- callback(k, false, 'Your WS prefix should be ' + wsMeta.servicesInformations.prefix + ' instead of ' + k);
- }
- else {
- callback(k, true);
- }
-
- _this.wsMetas[k] = wsMeta;
- });
- }
- });
-
- req.on('error', function (e) {
- callback(k, false, 'Unable to fetch WS schema ' + _this.wsList[k]);
- });
-
- req.end();
- };
-
- for (var k in this.wsList) {
- if (this.wsList.hasOwnProperty(k)) {
- checkWS(k);
- }
- }
- };
+ for (var k in this.wsList) {
+ if (this.wsList.hasOwnProperty(k)) {
+ checkWS(k);
+ }
+ }
+ };
- module.exports = function (wsList, wsServer) {
- wsServer = wsServer || 'ws.ovh.com';
+ module.exports = function (wsList, wsServer) {
+ wsServer = wsServer || 'ws.ovh.com';
- return new OVHWS(wsList, wsServer);
- };
+ return new OVHWS(wsList, wsServer);
+ };
}).call(this);
View
96 tests/01_checkWS.js
@@ -5,52 +5,52 @@
var ovh = require('../../node-ovh/ovh.js');
exports.checkWS = {
- 'checkWS': function (test) {
- "use strict";
-
- test.expect(3);
-
- var remaining = 3;
- var Ows = ovh({
- sessionHandler: 'sessionHandler/r4',
- cloudInstance: 'cloud/public/instance/r3',
- xdsl: 'xdsl/trunk'
- });
-
- Ows.checkWS(function (wsPrefix, success, errorMsg) {
- test.ok(success, 'Test WS ' + wsPrefix);
-
- if (--remaining === 0) {
- test.done();
- }
- });
- },
- 'checkWSNonExistant': function (test) {
- "use strict";
-
- test.expect(1);
-
- var Ows = ovh({
- nonExistant: 'foo/bar/r0'
- });
-
- Ows.checkWS(function (wsPrefix, success, errorMsg) {
- test.ok(!success, 'Test WS ' + wsPrefix);
- test.done();
- });
- },
- 'checkWSBadPrefix': function (test) {
- "use strict";
-
- test.expect(1);
-
- var Ows = ovh({
- adsl: 'xdsl/trunk'
- });
-
- Ows.checkWS(function (wsPrefix, success, errorMsg) {
- test.ok(!success, 'Test WS ' + wsPrefix);
- test.done();
- });
- }
+ 'checkWS': function (test) {
+ "use strict";
+
+ test.expect(3);
+
+ var remaining = 3;
+ var Ows = ovh({
+ sessionHandler: 'sessionHandler/r4',
+ cloudInstance: 'cloud/public/instance/r3',
+ xdsl: 'xdsl/trunk'
+ });
+
+ Ows.checkWS(function (wsPrefix, success, errorMsg) {
+ test.ok(success, 'Test WS ' + wsPrefix);
+
+ if (--remaining === 0) {
+ test.done();
+ }
+ });
+ },
+ 'checkWSNonExistant': function (test) {
+ "use strict";
+
+ test.expect(1);
+
+ var Ows = ovh({
+ nonExistant: 'foo/bar/r0'
+ });
+
+ Ows.checkWS(function (wsPrefix, success, errorMsg) {
+ test.ok(!success, 'Test WS ' + wsPrefix);
+ test.done();
+ });
+ },
+ 'checkWSBadPrefix': function (test) {
+ "use strict";
+
+ test.expect(1);
+
+ var Ows = ovh({
+ adsl: 'xdsl/trunk'
+ });
+
+ Ows.checkWS(function (wsPrefix, success, errorMsg) {
+ test.ok(!success, 'Test WS ' + wsPrefix);
+ test.done();
+ });
+ }
};
View
30 tests/02_calls.js
@@ -5,23 +5,23 @@
var ovh = require('../../node-ovh/ovh.js');
exports.calls = {
- 'getAnonymousSession': function (test) {
- "use strict";
+ 'getAnonymousSession': function (test) {
+ "use strict";
- test.expect(1);
+ test.expect(1);
- var Ows = ovh({
- sessionHandler: 'sessionHandler/r4',
- cloudInstance: 'cloud/public/instance/r3'
- });
+ var Ows = ovh({
+ sessionHandler: 'sessionHandler/r4',
+ cloudInstance: 'cloud/public/instance/r3'
+ });
- Ows.sessionHandler.getAnonymousSession.call({
- language : 'fr',
- secured : false
- }, function (success, reponse) {
- test.ok(success && reponse.session.id.match('^classic/anonymous-'), 'Except an anonymous session');
- test.done();
- });
- }
+ Ows.sessionHandler.getAnonymousSession.call({
+ language : 'fr',
+ secured : false
+ }, function (success, reponse) {
+ test.ok(success && reponse.session.id.match('^classic/anonymous-'), 'Except an anonymous session');
+ test.done();
+ });
+ }
};
Please sign in to comment.
Something went wrong with that request. Please try again.