Comparing version 1.0.0 to 1.0.1
289
centroid.js
@@ -10,10 +10,10 @@ /* | ||
Service name: Centroid Media (http://www.centroid.nl) | ||
Service docs: http://api.centroidmedia.com/documentation.html | ||
Service name: Centroid Media (http://www.centroid.nl) | ||
Service docs: http://api.centroidmedia.com/documentation.html | ||
*/ | ||
var crypto = require('crypto') | ||
var http = require('http') | ||
var querystring = require('querystring') | ||
var http = require ('httpreq'); | ||
var crypto = require ('crypto'); | ||
// Defaults | ||
@@ -25,87 +25,54 @@ var app = { | ||
privatekey: null, | ||
timeout: 20000 | ||
timeout: 10000 | ||
}, | ||
currentRate: 0 | ||
} | ||
}; | ||
// Persons | ||
app.persons = {} | ||
app.persons = {}; | ||
app.getCurrentRate = function( callback ) { | ||
talk( 'persons', 'getCurrentRate', function( err, data ) { | ||
if( ! err ) { | ||
if( data.query === undefined || data.query.currentRate === undefined ) { | ||
callback( new Error('Invalid response') ) | ||
} else { | ||
callback( null, data.query.currentRate ) | ||
} | ||
} else { | ||
callback( err ) | ||
} | ||
}) | ||
} | ||
app.getCurrentRate = function (callback) { | ||
talk ('persons', 'getCurrentRate', function (err, data) { | ||
fixData (err, data, ['query', 'currentRate'], callback); | ||
}); | ||
}; | ||
app.persons.getActiveSources = function( params, callback ) { | ||
talk( 'persons', 'getActiveSources', params, function( err, data ) { | ||
if( ! err ) { | ||
if( ! data.sources instanceof Array ) { | ||
callback( new Error('Invalid response') ) | ||
} else if( data.sources.length === 0 ) { | ||
callback( new Error('No results') ) | ||
} else { | ||
callback( null, data.sources ) | ||
} | ||
} else { | ||
callback( err ) | ||
} | ||
}) | ||
} | ||
app.persons.getActiveSources = function (params, callback) { | ||
talk ('persons', 'getActiveSources', params, function (err, data) { | ||
fixData (err, data, ['sources'], callback); | ||
}); | ||
}; | ||
app.persons.getPopularSources = function( params, callback ) { | ||
talk( 'persons', 'getPopularSources', params, function( err, data ) { | ||
if( ! err ) { | ||
if( ! data.sources instanceof Array ) { | ||
callback( new Error('Invalid response') ) | ||
} else if( data.sources.length === 0 ) { | ||
callback( new Error('No results') ) | ||
} else { | ||
callback( null, data.sources ) | ||
} | ||
} else { | ||
callback( err ) | ||
} | ||
}) | ||
} | ||
app.persons.getPopularSources = function (params, callback) { | ||
talk ('persons', 'getPopularSources', params, function (err, data) { | ||
fixData (err, data, ['sources'], callback); | ||
}); | ||
}; | ||
app.persons.getCategories = function( params, callback ) { | ||
talk( 'persons', 'getCategories', params, function( err, data ) { | ||
if( ! err ) { | ||
if( ! data.categories instanceof Array ) { | ||
callback( new Error('Invalid response') ) | ||
} else if( data.categories.length === 0 ) { | ||
callback( new Error('No results') ) | ||
} else { | ||
callback( null, data.categories ) | ||
} | ||
} else { | ||
callback( err ) | ||
} | ||
}) | ||
} | ||
app.persons.getCategories = function (params, callback) { | ||
talk ('persons', 'getCategories', params, function (err, data) { | ||
fixData (err, data, ['categories'], callback); | ||
}); | ||
}; | ||
app.persons.search = function( params, callback ) { | ||
talk( 'persons', 'search', params, function( err, data ) { | ||
if( ! err ) { | ||
if( ! data.sources instanceof Array ) { | ||
callback( new Error('Invalid response') ) | ||
} else if( data.sources.length === 0 ) { | ||
callback( new Error('No results') ) | ||
} else { | ||
callback( null, data.sources ) | ||
} | ||
app.persons.search = function (params, callback) { | ||
talk ('persons', 'search', params, function (err, data) { | ||
fixData (err, data, ['sources'], callback); | ||
}); | ||
}; | ||
// fix data | ||
function fixData (err, data, props, callback) { | ||
if (err) { return callback (err); } | ||
var i; | ||
for (i = 0; i < props.length; i++) { | ||
if (data && data [props [i]]) { | ||
data = data [props [i]]; | ||
} else { | ||
callback( err ) | ||
return callback (new Error ('Invalid Response')); | ||
} | ||
}) | ||
} | ||
callback (null, data); | ||
} | ||
@@ -115,121 +82,75 @@ | ||
// communicate | ||
function talk( category, path, params, callback ) { | ||
if( typeof params === 'function' ) { | ||
var callback = params | ||
var params = {} | ||
function talk (category, path, params, callback) { | ||
if (typeof params === 'function') { | ||
var callback = params; | ||
var params = {}; | ||
} | ||
// check credentials | ||
if( !app.set.apikey || typeof app.set.apikey !== 'string' || app.set.apikey === '' ) { | ||
callback( new Error('No API key') ) | ||
return | ||
if (!app.set.apikey) { | ||
return callback (new Error ('No API key')); | ||
} | ||
if( !app.set.privatekey || typeof app.set.privatekey !== 'string' || app.set.privatekey === '' ) { | ||
callback( new Error('No private key') ) | ||
return | ||
if( !app.set.privatekey) { | ||
return callback (new Error ('No private key')); | ||
} | ||
// sign | ||
var signature = Date.now() | ||
var md5 = crypto.createHash('md5') | ||
md5.update( app.set.privatekey + signature ) | ||
var api_sig = md5.digest('hex') | ||
var signature = Date.now (); | ||
var api_sig = crypto | ||
.createHash ('md5') | ||
.update (app.set.privatekey + signature) | ||
.digest ('hex'); | ||
// build request | ||
params.api_key = app.set.apikey | ||
params.api_sig = api_sig | ||
params.signature = signature | ||
params.format = 'json' | ||
params.api_key = app.set.apikey; | ||
params.api_sig = api_sig; | ||
params.signature = signature; | ||
params.format = 'json'; | ||
var options = { | ||
host: category +'.'+ app.set.apihost, | ||
path: '/'+ path +'?'+ querystring.stringify( params ), | ||
method: 'GET', | ||
headers: { | ||
'User-Agent': 'centroid.js (https://github.com/fvdm/nodejs-centroid)' | ||
} | ||
} | ||
http.get ( | ||
'http://'+ category +'.'+ app.set.apihost +'/'+ path, | ||
{ | ||
parameters: params, | ||
timeout: app.set.timeout, | ||
headers: { | ||
'User-Agent': 'centroid.js (https://github.com/fvdm/nodejs-centroid)' | ||
} | ||
}, | ||
function (err, res) { | ||
if (err) { return callback (err); } | ||
var data = null; | ||
var error = null; | ||
var request = http.request( options ) | ||
try { | ||
data = JSON.parse (res.body); | ||
} catch (e) { | ||
error = new Error ('Invalid response'); | ||
} | ||
// process response | ||
request.on( 'response', function( response ) { | ||
var data = '' | ||
var complete = false | ||
if (data && !(data instanceof Object)) { | ||
error = new Error ('Invalid response'); | ||
} | ||
response.on( 'data', function( ch ) { data += ch }) | ||
if (data && data.errorCode) { | ||
error = new Error ('API error'); | ||
error.errorCode = data.errorCode; | ||
error.errorString = data.errorString; | ||
} | ||
response.on( 'close', function() { | ||
if( ! complete ) { | ||
complete = true | ||
callback( new Error('Disconnected') ) | ||
// store rate limit | ||
if (data && data.query && data.query.currentRate) { | ||
app.currentRate = data.query.currentRate; | ||
} | ||
}) | ||
response.on( 'end', function() { | ||
if( ! complete ) { | ||
complete = true | ||
data = data.toString('utf8').trim() | ||
var err = null | ||
// API error | ||
if( response.statusCode >= 300 ) { | ||
var err = new Error('HTTP error') | ||
} else if( data == '' ) { | ||
var err = new Error('No response') | ||
} else if( ! data.match( /^\{.*\}$/ ) ) { | ||
var err = new Error('Invalid response') | ||
} else { | ||
data = JSON.parse( data ) | ||
if( data.errorCode !== undefined ) { | ||
var err = new Error('API error') | ||
err.errorCode = data.errorCode | ||
err.errorString = data.errorString | ||
} | ||
// store rate limit | ||
if( data.query !== undefined && data.query.currentRate !== undefined ) { | ||
app.currentRate = data.query.currentRate | ||
} | ||
} | ||
if( err instanceof Error ) { | ||
err.httpCode = response.statusCode | ||
err.httpHeaders = response.headers | ||
err.request = options | ||
err.response = data | ||
callback( err ) | ||
} else { | ||
callback( null, data ) | ||
} | ||
if (error instanceof Error) { | ||
error.httpCode = res.statusCode; | ||
error.httpHeaders = res.headers; | ||
error.response = data; | ||
callback (error); | ||
} else { | ||
callback (null, data); | ||
} | ||
}) | ||
}) | ||
// request timeout | ||
request.on( 'socket', function( socket ) { | ||
if( app.set.timeout ) { | ||
socket.setTimeout( app.set.timeout ) | ||
socket.on( 'timeout', function() { | ||
request.abort() | ||
}) | ||
} | ||
}) | ||
// request failed | ||
request.on( 'error', function( error ) { | ||
if( error.code === 'ECONNRESET' ) { | ||
var err = new Error('Request timeout') | ||
} else { | ||
var err = new Error('Request failed') | ||
} | ||
err.request = options | ||
err.requestError = error | ||
callback( err ) | ||
}) | ||
// finish | ||
request.end() | ||
); | ||
} | ||
@@ -239,7 +160,7 @@ | ||
// setup | ||
module.exports = function( apikey, privatekey, timeout ) { | ||
app.set.apikey = apikey || null | ||
app.set.privatekey = privatekey || null | ||
app.set.timeout = timeout || app.set.timeout | ||
return app | ||
} | ||
module.exports = function (apikey, privatekey, timeout) { | ||
app.set.apikey = apikey || null; | ||
app.set.privatekey = privatekey || null; | ||
app.set.timeout = parseInt (timeout || app.set.timeout); | ||
return app; | ||
}; |
{ | ||
"author": { | ||
"name": "Franklin van de Meent", | ||
"email": "fr@nkl.in", | ||
"url": "https://frankl.in" | ||
"name": "Franklin van de Meent", | ||
"email": "fr@nkl.in", | ||
"url": "https://frankl.in" | ||
}, | ||
"name": "centroid", | ||
"description": "Search persons in many public sources.", | ||
"version": "1.0.0", | ||
"homepage": "https://frankl.in/code/centroid-api-for-node-js", | ||
"name": "centroid", | ||
"description": "DEPRECATED - Search persons in many public sources with Centroid Media API.", | ||
"version": "1.0.1", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/fvdm/nodejs-centroid.git" | ||
"type": "git", | ||
"url": "git://github.com/fvdm/nodejs-centroid.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/fvdm/nodejs-centroid/issues" | ||
"url": "https://github.com/fvdm/nodejs-centroid/issues" | ||
}, | ||
"main": "centroid.js", | ||
"dependencies": {}, | ||
"devDependencies": {}, | ||
"main": "centroid.js", | ||
"dependencies": { | ||
"httpreq": "^0.4.22" | ||
}, | ||
"devDependencies": {}, | ||
"optionalDependencies": {}, | ||
"engines": { | ||
"node": "*" | ||
"node": ">0.12.0" | ||
}, | ||
"keywords": ["centroid", "search", "pse", "people", "social", "api"], | ||
"license": { | ||
"type": "Public Domain", | ||
"url": "https://github.com/fvdm/nodejs-centroid/raw/master/UNLICENSE" | ||
}, | ||
"keywords": [ | ||
"centroid", | ||
"search", | ||
"pse", | ||
"people", | ||
"social", | ||
"api" | ||
], | ||
"license": "Unlicense", | ||
"scripts": { | ||
"test": "node test.js" | ||
"pre-install": "node deprecated.js", | ||
"test": "echo 'DEPRECATED - Centroid API is no longer available'; exit 1" | ||
} | ||
} |
239
README.md
@@ -1,3 +0,3 @@ | ||
nodejs-centroid | ||
=============== | ||
centroid | ||
======== | ||
@@ -8,25 +8,40 @@ Unofficial node.js module for the Centroid Media API. | ||
[Centroid Media](http://www.centroid.nl/) | ||
* ~~[Centroid Media](http://www.centroid.nl/)~~ | ||
* ~~[API documentation](http://api.centroidmedia.com/documentation.html)~~ | ||
[API documentation](http://api.centroidmedia.com/documentation.html) | ||
DEPRECATED | ||
---------- | ||
Installation | ||
------------ | ||
The `centroid` module is deprecated because the remote API is no longer available. | ||
All described methods will fail. | ||
### With NPM | ||
The version in the [NPM registry](https://npmjs.org/) is always the latest *stable* release. | ||
This also allows easy updating. | ||
Example | ||
------- | ||
npm install centroid | ||
```js | ||
var centroid = require ('centroid') ('apikey', 'privatekey'); | ||
### From Github source | ||
centroid.persons.search ( | ||
{ | ||
country: 'us', | ||
lang: 'en', | ||
fullname: 'Barack Obama', | ||
sources: 'linkedin' | ||
}, | ||
function (err, res) { | ||
if (err) { return console.log (err); } | ||
console.log (res); | ||
} | ||
); | ||
``` | ||
The Github repository is the most recent code, but may be *unstable*. | ||
npm install git+https://github.com/fvdm/nodejs-centroid | ||
Installation | ||
------------ | ||
`npm install centroid` | ||
Configuration | ||
@@ -40,9 +55,10 @@ ------------- | ||
```js | ||
var centroid = require('centroid')( 'apiKey', 'privateKey', 10000 ) | ||
var centroid = require ('centroid') ('apiKey', 'privateKey', 10000); | ||
``` | ||
apiKey required Your API key | ||
privateKey required Your private key | ||
timeout option Time limit to wait for response, | ||
default 20000 ms (20 sec) | ||
param | type | required | description | ||
:----------|:--------|:---------|:---------------- | ||
apiKey | string | yes | Your API key | ||
privateKey | string | yes | Your private key | ||
timeout | integer | no | Time limit to wait for response, default `10000` ms (20 sec) | ||
@@ -54,20 +70,2 @@ | ||
Example | ||
------- | ||
```js | ||
var centroid = require('centroid')( 'apikey', 'privatekey' ) | ||
centroid.persons.find( | ||
{ | ||
country: 'us', | ||
lang: 'en', | ||
fullname: 'Barack Obama', | ||
sources: 'linkedin' | ||
}, | ||
callback | ||
) | ||
``` | ||
Methods | ||
@@ -86,8 +84,8 @@ ------- | ||
callbackFunction( err, data ) { | ||
if( ! err ) { | ||
console.log( data ) | ||
} else { | ||
console.log( err ) | ||
console.log( err.stack ) | ||
} | ||
if (!err) { | ||
console.log (data); | ||
} else { | ||
console.log (err); | ||
console.log (err.stack); | ||
} | ||
} | ||
@@ -98,13 +96,15 @@ ``` | ||
The `err` parameter can received these errors: | ||
The `err` parameter can receive these errors: | ||
Error: No API key No apikey was provided | ||
Error: No private key No privatekey was provided | ||
Error: Disconnected The API disconnected too early | ||
Error: HTTP error The API returned a HTTP error | ||
Error: No response The API returned no data | ||
Error: Invalid response The API returned invalid data | ||
Error: API error The API returned an error | ||
Error: Request failed The request cannot be made | ||
Error: No results No results were returned | ||
message | description | ||
:----------------|:------------------------------ | ||
No API key | No apikey was provided | ||
No private key | No privatekey was provided | ||
Disconnected | The API disconnected too early | ||
HTTP error | The API returned a HTTP error | ||
No response | The API returned no data | ||
Invalid response | The API returned invalid data | ||
API error | The API returned an error | ||
Request failed | The request cannot be made | ||
No results | No results were returned | ||
@@ -117,12 +117,14 @@ | ||
.stack The stack trace | ||
.message The error message | ||
.httpCode ie. 404 | ||
.httpHeaders Object with http headers | ||
.request Object with request spec | ||
.requestError The .request error | ||
.response API response body | ||
.errorCode API error code | ||
.errorString API error message | ||
property | description | ||
:---------------|:------------------------ | ||
.stack | The stack trace | ||
.message | The error message | ||
| | ||
.httpCode | ie. `404` | ||
.httpHeaders | Object with http headers | ||
.requestError | The .request error | ||
.response | API response body | ||
.errorCode | API error code | ||
.errorString | API error message | ||
.code | Error code from HTTP module | ||
@@ -136,3 +138,3 @@ | ||
```js | ||
centroid.getCurrentRate( callback ) | ||
centroid.getCurrentRate (callback); | ||
``` | ||
@@ -154,9 +156,10 @@ | ||
``` | ||
country required Two-letter ISO country code, i.e. 'us'. | ||
lang required Two-letter ISO language code, i.e. 'en'. | ||
``` | ||
property | type | required | description | ||
:--------|:-------|:---------|:--------------------------------------- | ||
country | string | required | Two-letter ISO country code, i.e. 'us' | ||
lang | string | required | Two-letter ISO language code, i.e. 'en' | ||
```js | ||
centroid.getActiveSources ( props, callback ) | ||
centroid.getActiveSources (props, callback); | ||
``` | ||
@@ -167,10 +170,16 @@ | ||
```js | ||
[ { name: 'Twitter', | ||
[ | ||
{ | ||
name: 'Twitter', | ||
id: 'twitter', | ||
category: 'socialnetworks', | ||
popular: 1 }, | ||
{ name: 'LinkedIn', | ||
popular: 1 | ||
}, | ||
{ | ||
name: 'LinkedIn', | ||
id: 'linkedin', | ||
category: 'socialnetworks', | ||
popular: 1 } ] | ||
popular: 1 | ||
} | ||
] | ||
``` | ||
@@ -186,9 +195,10 @@ | ||
``` | ||
country required Two-letter ISO country code, i.e. 'us'. | ||
lang required Two-letter ISO language code, i.e. 'en'. | ||
``` | ||
property | type | required | description | ||
:--------|:-------|:---------|:--------------------------------------- | ||
country | string | required | Two-letter ISO country code, i.e. 'us' | ||
lang | string | required | Two-letter ISO language code, i.e. 'en' | ||
```js | ||
centroid.getPopularSources ( props, callback ) | ||
centroid.getPopularSources (props, callback); | ||
``` | ||
@@ -199,6 +209,8 @@ | ||
```js | ||
[ { name: 'Twitter', id: 'twitter', category: 'socialnetworks' }, | ||
[ | ||
{ name: 'Twitter', id: 'twitter', category: 'socialnetworks' }, | ||
{ name: 'LinkedIn', id: 'linkedin', category: 'socialnetworks' }, | ||
{ name: 'Facebook', id: 'facebook', category: 'socialnetworks' }, | ||
{ name: 'MySpace', id: 'myspace', category: 'socialnetworks' } ] | ||
{ name: 'MySpace', id: 'myspace', category: 'socialnetworks' } | ||
] | ||
``` | ||
@@ -214,9 +226,10 @@ | ||
``` | ||
country required Two-letter ISO country code, i.e. 'us'. | ||
lang required Two-letter ISO language code, i.e. 'en'. | ||
``` | ||
property | type | required | description | ||
:--------|:-------|:---------|:--------------------------------------- | ||
country | string | required | Two-letter ISO country code, i.e. 'us' | ||
lang | string | required | Two-letter ISO language code, i.e. 'en' | ||
```js | ||
centroid.getCategories ( props, callback ) | ||
centroid.getCategories (props, callback); | ||
``` | ||
@@ -227,6 +240,8 @@ | ||
```js | ||
[ { name: 'Personal', | ||
[ | ||
{ name: 'Personal', | ||
id: 'wow_data', | ||
sources: | ||
[ { name: 'Related persons', id: 'related', popular: 1 }, | ||
[ | ||
{ name: 'Related persons', id: 'related', popular: 1 }, | ||
{ name: 'Facts', id: 'facts', popular: 1 }, | ||
@@ -236,3 +251,6 @@ { name: 'Tags', id: 'tags', popular: 1 }, | ||
{ name: 'Phone numbers', id: 'phonenumbers', popular: 1 }, | ||
{ name: 'Documents', id: 'docs', popular: 1 } ] } ] | ||
{ name: 'Documents', id: 'docs', popular: 1 } | ||
] | ||
} | ||
] | ||
``` | ||
@@ -248,20 +266,25 @@ | ||
``` | ||
country required Two-letter ISO country code, i.e. 'us'. | ||
lang required Two-letter ISO language code, i.e. 'en'. | ||
property | type | required | description | ||
:--------|:-------|:---------|:--------------------------------------- | ||
country | string | required | Two-letter ISO country code, i.e. 'us' | ||
lang | string | required | Two-letter ISO language code, i.e. 'en' | ||
Requires at least one of: | ||
categories Comma-separated list of category IDs. | ||
sources Comma-separated list of source IDs. | ||
set 'popular' (default) or 'all'. | ||
``` | ||
categories Comma-separated list of category IDs. | ||
sources Comma-separated list of source IDs. | ||
set 'popular' (default) or 'all'. | ||
``` | ||
Requires at least one of: | ||
firstname Person's firstname. | ||
fullname Person's first and last names. | ||
``` | ||
firstname Person's firstname. | ||
fullname Person's first and last names. | ||
``` | ||
```js | ||
centroid.persons.search( | ||
centroid.persons.search ( | ||
{ | ||
@@ -274,3 +297,3 @@ country: 'us', | ||
output | ||
) | ||
); | ||
``` | ||
@@ -281,3 +304,5 @@ | ||
```js | ||
[ { name: 'LinkedIn', | ||
[ | ||
{ | ||
name: 'LinkedIn', | ||
id: 'linkedin', | ||
@@ -288,3 +313,5 @@ category: 'socialnetworks', | ||
results: | ||
[ { name: 'Barack Obama', | ||
[ | ||
{ | ||
name: 'Barack Obama', | ||
photo: 'https://media.licdn.com/mpr/mpr/shrink_120_120/p/2/000/1a3/129/3a73f4c.jpg', | ||
@@ -297,3 +324,7 @@ headline: 'President of the United States of America', | ||
industry: 'Administración gubernamental', | ||
url: 'http://www.linkedin.com/in/barackobama' } ] } ] | ||
url: 'http://www.linkedin.com/in/barackobama' | ||
} | ||
] | ||
} | ||
] | ||
``` | ||
@@ -329,1 +360,7 @@ | ||
For more information, please refer to <http://unlicense.org> | ||
Author | ||
------ | ||
[Franklin van de Meent](https://frankl.in) |
248
test.js
@@ -1,135 +0,141 @@ | ||
var util = require('util') | ||
var util = require ('util'); | ||
// Setup | ||
// set env CENTROID_APIKEY and CENTROID_PRIVATEKEY (Travis CI) | ||
// or use cli arguments: npm test --centroid_apikey=abc123 --centroid_privatekey | ||
var centroid = require('./')( | ||
process.env.npm_config_centroid_apikey || process.env.CENTROID_APIKEY || null, | ||
process.env.npm_config_centroid_privatekey || process.env.CENTROID_PRIVATEKEY || null, | ||
process.env.npm_config_centroid_timeout || process.env.CENTROID_TIMEOUT || 20000 | ||
) | ||
var centroid = require ('./') ( | ||
process.env.CENTROID_APIKEY || null, | ||
process.env.CENTROID_PRIVATEKEY || null, | ||
process.env.CENTROID_TIMEOUT || 10000 | ||
); | ||
// handle exits | ||
var errors = 0 | ||
process.on( 'exit', function() { | ||
if( errors == 0 ) { | ||
console.log('\n\033[1mDONE, no errors.\033[0m\n') | ||
process.exit(0) | ||
} else { | ||
console.log('\n\033[1mFAIL, '+ errors +' error'+ (errors > 1 ? 's' : '') +' occurred!\033[0m\n') | ||
process.exit(1) | ||
} | ||
}) | ||
var errors = 0; | ||
process.on ('exit', function () { | ||
if (errors === 0) { | ||
console.log ('\n\033 [1mDONE, no errors.\033 [0m\n'); | ||
process.exit (0); | ||
} else { | ||
console.log ('\n\033 [1mFAIL, '+ errors +' error'+ (errors > 1 ? 's' : '') +' occurred!\033 [0m\n'); | ||
process.exit (1); | ||
} | ||
}); | ||
// prevent errors from killing the process | ||
process.on( 'uncaughtException', function( err ) {} ) | ||
process.on ('uncaughtException', function (err) { | ||
console.log (); | ||
console.error (err.stack); | ||
console.trace (); | ||
console.log (); | ||
errors++; | ||
}); | ||
// Queue to prevent flooding | ||
var queue = [] | ||
var next = 0 | ||
var queue = []; | ||
var next = 0; | ||
function doNext() { | ||
next++ | ||
if( queue[next] ) { | ||
queue[next]() | ||
} | ||
function doNext () { | ||
next++; | ||
if (queue [next]) { | ||
queue [next] (); | ||
} | ||
} | ||
// doTest( passErr, 'methods', [ | ||
// doTest (passErr, 'methods', [ | ||
// ['feeds', typeof feeds === 'object'] | ||
// ]) | ||
function doTest( err, label, tests ) { | ||
if( !err ) { | ||
var testErrors = [] | ||
tests.forEach( function( test ) { | ||
if( test[1] !== true ) { | ||
testErrors.push(test[0]) | ||
errors++ | ||
} | ||
}) | ||
if( testErrors.length == 0 ) { | ||
console.log( label +': \033[1mok\033[0m' ) | ||
} else { | ||
console.error( label +': \033[1m\033[31mfailed\033[0m ('+ testErrors.join(', ') +')' ) | ||
} | ||
} else { | ||
console.error( label +': \033[1m\033[31mERROR\033[0m\n' ) | ||
console.error( util.inspect(err, false, 10, true) ) | ||
console.log() | ||
console.error( err.stack ) | ||
console.log() | ||
errors++ | ||
} | ||
doNext() | ||
//]) | ||
function doTest (err, label, tests) { | ||
if (err instanceof Error) { | ||
console.error (label +': \033 [1m\033 [31mERROR\033 [0m\n'); | ||
console.error (util.inspect (err, false, 10, true)); | ||
console.log (); | ||
console.error (err.stack); | ||
console.log (); | ||
errors++; | ||
} else { | ||
var testErrors = []; | ||
tests.forEach (function (test) { | ||
if (test [1] !== true) { | ||
testErrors.push (test [0]); | ||
errors++; | ||
} | ||
}); | ||
if (testErrors.length === 0) { | ||
console.log (label +': \033 [1m\033 [32mok\033 [0m'); | ||
} else { | ||
console.error (label +': \033 [1m\033 [31mfailed\033 [0m ('+ testErrors.join (', ') +')'); | ||
} | ||
} | ||
doNext (); | ||
} | ||
// API ACCESS | ||
queue.push( function() { | ||
centroid.getCurrentRate( function( err, data ) { | ||
if(err) { | ||
console.log('API access: failed ('+ err.message +')') | ||
console.log() | ||
console.log(err.stack) | ||
errors++ | ||
process.exit(1) | ||
} else { | ||
console.log('API access: \033[1mok\033[0m') | ||
doNext() | ||
} | ||
}) | ||
}) | ||
queue.push (function () { | ||
centroid.getCurrentRate (function (err, data) { | ||
if (err) { | ||
console.log ('API access: failed ('+ err.message +')'); | ||
console.log (); | ||
console.log (err.stack); | ||
errors++; | ||
process.exit (1); | ||
} else { | ||
console.log ('API access: \033 [1mok\033 [0m'); | ||
doNext (); | ||
} | ||
}); | ||
}); | ||
queue.push( function() { | ||
centroid.set.timeout = 1 | ||
centroid.getCurrentRate( function( err, data ) { | ||
if( !err || err.message !== 'Request timeout' ) { | ||
console.log('Timeout: failed ('+ centroid.set.timeout +' sec)') | ||
console.log() | ||
console.log(err.stack) | ||
errors++ | ||
process.exit(1) | ||
} else { | ||
console.log('Timeout: \033[1mok\033[0m') | ||
centroid.set.timeout = 10000 | ||
doNext() | ||
} | ||
}) | ||
}) | ||
queue.push (function () { | ||
centroid.set.timeout = 1; | ||
centroid.getCurrentRate (function (err, data) { | ||
if (!err || err.message !== 'Request timeout') { | ||
console.log ('Timeout: failed ('+ centroid.set.timeout +' sec)'); | ||
console.log (); | ||
console.log (err.stack); | ||
errors++; | ||
process.exit (1); | ||
} else { | ||
console.log ('Timeout: \033 [1mok\033 [0m'); | ||
centroid.set.timeout = 10000; | ||
doNext (); | ||
} | ||
}); | ||
}); | ||
queue.push( function() { | ||
centroid.persons.getActiveSources( {country:'nl', lang:'nl'}, function( err, data ) { | ||
doTest( err, 'persons.getActiveSources', [ | ||
queue.push (function () { | ||
centroid.persons.getActiveSources ({country:'nl', lang:'nl'}, function (err, data) { | ||
doTest (err, 'persons.getActiveSources', [ | ||
['type', data instanceof Array], | ||
['length', data.length >= 1], | ||
['item type', data[0] instanceof Object], | ||
['item prop', typeof data[0].name === 'string'] | ||
]) | ||
}) | ||
}) | ||
['item type', data [0] instanceof Object], | ||
['item prop', typeof data [0] .name === 'string'] | ||
]); | ||
}); | ||
}); | ||
queue.push( function() { | ||
centroid.persons.getPopularSources( {country:'nl', lang:'nl'}, function( err, data ) { | ||
doTest( err, 'persons.getPopularSources', [ | ||
queue.push (function () { | ||
centroid.persons.getPopularSources ({country:'nl', lang:'nl'}, function (err, data) { | ||
doTest (err, 'persons.getPopularSources', [ | ||
['type', data instanceof Array], | ||
['length', data.length >= 1], | ||
['item type', data[0] instanceof Object], | ||
['item prop', typeof data[0].name === 'string'] | ||
]) | ||
}) | ||
}) | ||
['item type', data [0] instanceof Object], | ||
['item prop', typeof data [0] .name === 'string'] | ||
]); | ||
}); | ||
}); | ||
queue.push( function() { | ||
centroid.persons.getCategories( {country:'nl', lang:'nl'}, function( err, data ) { | ||
doTest( err, 'persons.getCategories', [ | ||
queue.push (function () { | ||
centroid.persons.getCategories ({country:'nl', lang:'nl'}, function (err, data) { | ||
doTest (err, 'persons.getCategories', [ | ||
['type', data instanceof Array], | ||
['length', data.length >= 1], | ||
['item type', data[0] instanceof Object], | ||
['item prop', typeof data[0].name === 'string'] | ||
]) | ||
}) | ||
}) | ||
['item type', data [0] instanceof Object], | ||
['item prop', typeof data [0] .name === 'string'] | ||
]); | ||
}); | ||
}); | ||
queue.push( function() { | ||
queue.push (function () { | ||
centroid.persons.search( | ||
@@ -142,22 +148,22 @@ { | ||
}, | ||
function( err, data ) { | ||
doTest( err, 'persons.search', [ | ||
function (err, data) { | ||
doTest (err, 'persons.search', [ | ||
['type', data instanceof Array], | ||
['length', data.length >= 1], | ||
['item type', data[0] instanceof Object], | ||
['item prop', typeof data[0].name === 'string'], | ||
['item results', data[0].results instanceof Array], | ||
['item result', data[0].results[0] instanceof Object], | ||
['item result url', typeof data[0].results[0].url === 'string'] | ||
]) | ||
['item type', data [0] instanceof Object], | ||
['item prop', typeof data [0] .name === 'string'], | ||
['item results', data [0] .results instanceof Array], | ||
['item result', data [0] .results [0] instanceof Object], | ||
['item result url', typeof data [0] .results [0] .url === 'string'] | ||
]); | ||
} | ||
) | ||
}) | ||
); | ||
}); | ||
// Start the tests | ||
queue[0]() | ||
queue [0] (); | ||
function output( err, data ) { | ||
console.log( require('util').inspect( err || data, false, 10 ) ) | ||
} | ||
function output (err, data) { | ||
console.log (require ('util') .inspect (err || data, {depth: 10, colors: true})); | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
7
347
3
19297
1
286
2
+ Addedhttpreq@^0.4.22
+ Addedhttpreq@0.4.24(transitive)