buncher
v1.0.2
Published
node.js module that collects remote data from different sources and can check it with JSON Schema
Readme
buncher
buncher collects data from different sources and accumulates it into one object. Will not return keys for incorrect items: incorrect URL, code is not 200, invalid data. These keys will be in err object.
Example:
get([
{ name: 'name1', url: "http://url-to.json", schema: 'tests/schema/name.json' },
// type 'plain' means it will not be parsed as JSON
{ name: 'name2', url: "http://url-to.html/xml", type: 'plain' }
], function( err, results ) {
console.log( results.name1 ); // parsed and checked JSON from name1
console.log( results.name2 ); // plain HTML from name2
});Methods
get( links, callback[, options ] )
links
Type: Array
Array of objects with URLs to get data from:
{
"name" : "String, required. Property name in result object",
"url" : "Srting, required. URL to get data from",
"type" : "String, optional. Set it to 'plain', if the result shouldn't be parsed as JSON",
"schema" : "String, optional. Path to file with JSON Schema. Absolute or relative from process working directory, e.g. server.js",
"timeout" : "Number, optional. Request timeout for this exact link"
}callback
Type: Function
Gets err and results aas arguments. err contains errors in err[ link.name ].errors array and results contains data in results[ link.name ].
options
Type: Object
Optional.
{
"timeout" : "Number. HTTP request timeout. Default is 5000. Can be redefined for links",
"request" : "Object. 'Request' object to get cookies from",
"oninvalid": function( link, validationResult ) {
// called on every validation error
// send email, for example
}
}