/*

Lists Nitro masterbrands (channels)

*/

function processResponse(obj) {
	for (var m in obj.nitro.results.items) {
		var mb = obj.nitro.results.items[m];
		//if (mb.partner != 's0000001') {
		console.log(mb.mid+','+mb.url_key+','+(mb.title ? mb.title : mb.name)+','+mb.partner);
		//}
	}
	var dest = {};
	if ((obj.nitro.pagination) && (obj.nitro.pagination.next)) {
		dest.query = nitro.queryFrom(obj.nitro.pagination.next.href,true);
		dest.path = path;
		dest.callback = processResponse;
	}
	nitro.setReturn(dest);
	return true;
}

var nitro = require('./nitroSdk');
var api = require('./nitroApi/api');

var config = require('./config.json');
var host = config.nitro.host;
var api_key = config.nitro.api_key;

var path = api.nitroMasterbrands;

var query = nitro.newQuery();
query.add(api.fMasterbrandsPartnerPid,'*',true);

nitro.make_request(host,path,api_key,query,{},processResponse);

process.on('exit', function(code) {
	//console.log('About to exit with code:', code);
});
@@ -70,17 +70,18 @@
 (obj) %7B%0A
-%09
+  
 for (var
@@ -113,18 +113,20 @@
 tems) %7B%0A
-%09%09
+    
 var mb =
@@ -158,46 +158,12 @@
 m%5D;%0A
-%09%09//if (mb.partner != 's0000001') %7B%0A%09%09
+    
 cons
@@ -181,16 +181,17 @@
 mid+','+
+(
 mb.url_k
@@ -192,16 +192,21 @@
 .url_key
+%7C%7C'')
 +','+(mb
@@ -229,15 +229,23 @@
 e : 
+(
 mb.name
+ %7C%7C '')
 )+',
@@ -263,18 +263,14 @@
 r);%0A
-%09%09//%7D%0A%09%7D%0A%09
+  %7D%0A  
 var 
@@ -280,17 +280,18 @@
 t = %7B%7D;%0A
-%09
+  
 if ((obj
@@ -343,18 +343,20 @@
 ext)) %7B%0A
-%09%09
+    
 dest.que
@@ -414,18 +414,20 @@
 ,true);%0A
-%09%09
+    
 dest.pat
@@ -440,10 +440,12 @@
 th;%0A
-%09%09
+    
 dest
@@ -477,12 +477,14 @@
 se;%0A
-%09%7D%0A%09
+  %7D%0A  
 nitr
@@ -502,17 +502,18 @@
 (dest);%0A
-%09
+  
 return t
@@ -919,9 +919,10 @@
 ) %7B%0A
-%09
+  
 //co
@@ -969,8 +969,9 @@
 de);%0A%7D);
+%0A

clean up output