Permalink
Browse files

adding stream rest respons support for cli

  • Loading branch information...
1 parent be8e6b9 commit 74b103880147ad33aa3f142d3f82f5573571c6da @soldair soldair committed Feb 25, 2014
Showing with 31 additions and 10 deletions.
  1. +1 −1 bin/pinoccio.js
  2. +1 −1 browser.js
  3. +13 −5 index.js
  4. +4 −0 lib/api.js
  5. +10 −2 lib/commands/rest.js
  6. +2 −1 package.json
View
@@ -56,7 +56,7 @@ conf(function(err,config){
if(err) {
console.error(err);
- } else {
+ } else if(data) {
//console.log('OK');
//process.exit(0);
}
View
@@ -84,7 +84,7 @@ module.exports = window.pinoccioAPI = function(opts){
// if multiple reports are provided they
api.stats = function(obj){
//
- return a.stats(obj);
+ return a.stats(api.token,obj);
}
return api;
View
@@ -76,14 +76,22 @@ module.exports = function(config){
var req = hyperquest(uri,opts,function(err,res){
if(err) return cb(err);
+
+
res.on('error',function(err){
cb(err);
cb = function(){};
- }).pipe(concat(function(data){
- //console.log(data.toString());
- var parsed = json(data)||{};
- cb(parsed.error,parsed.data,data);
- }))
+ })
+
+ if(res.headers['x-stream']) {
+ cb(false,res);// return response stream.
+ } else {
+ res.pipe(concat(function(data){
+ //console.log(data.toString());
+ var parsed = json(data)||{};
+ cb(parsed.error,parsed.data,data);
+ }))
+ }
});
if(opts.method != 'GET') {
View
@@ -75,6 +75,10 @@ module.exports = function(config,reconnect){
done(false,con.mdm.createReadStream(obj));
});
});
+ s.on('data',function(d){
+ // on reconnect start sync from where i left off.
+ obj.args.data.start = d.time;
+ })
return s;
},
// stream stats data
View
@@ -1,5 +1,8 @@
var qs = require('querystring');
-
+var through = require('through');
+var repipe = require('repipe');
+var backoff = require('backoff');
+var bwrap = require('../backoffwrap')
module.exports = function(args,api,config,cb){
@@ -26,9 +29,14 @@ module.exports = function(args,api,config,cb){
api.rest(method,service,data,function(err,data){
if(err) return cb(JSON.stringify({error:err.message}));
- console.log(JSON.stringify(data));
+ if(data && typeof data.pipe === "function") {
+ data.pipe(process.stdout);
+ } else {
+ console.log(JSON.stringify(data));
+ }
cb();
});
+
}
module.exports.usage = "rest\n"
View
@@ -46,7 +46,8 @@
"reconnect": "~2.0.0",
"cookie": "~0.1.0",
"engine.io-options-from-url": "0.0.3",
- "repipe": "~0.0.0"
+ "repipe": "0.0.0",
+ "backoff": "~2.3.0"
},
"devDependencies": {
"tape": "~2.3.2",

0 comments on commit 74b1038

Please sign in to comment.