11#!/usr/bin/env node
22
33var http = require ( 'http' )
4+ var split = require ( 'split' ) ;
45var options = parseArgv ( process . argv )
56
67
78
89if ( options . hasOwnProperty ( 'help' ) ) {
910 help ( )
1011}
12+ else if ( options . hasOwnProperty ( 'stream' ) ) {
13+ process . stdin . pipe ( split ( ) )
14+ . on ( 'data' , function ( line ) {
15+ options . data = line ;
16+ go ( )
17+ } ) ;
18+ }
1119else if ( options . data ) {
1220 go ( )
1321}
@@ -26,14 +34,15 @@ function go() {
2634 var path = '/input/' + options . public_key +
2735 '?private_key=' + options . private_key +
2836 '&' + options . field_name + '=' + options . data ;
29- log ( path )
37+ log ( options . url + path )
3038 http . get ( { host : options . url , path : path } , function ( response ) {
3139 response . on ( 'error' , function ( ) {
3240 console . log ( 'error!' )
3341 process . exit ( 1 )
3442 } )
35- response . on ( 'data' , function ( ) {
43+ response . on ( 'data' , function ( chunk ) {
3644 console . log ( response . statusCode ) // 200
45+ console . log ( ( chunk + "" ) . replace ( / < (?: .| \n ) * ?> / gm, '' ) )
3746 process . exit ( 0 )
3847 } )
3948 } )
@@ -47,6 +56,8 @@ function help() {
4756 console . log ( ' --field_name <field_name> Example: temp' )
4857 console . log ( ' --data [data] This is optional because you can also pipe data to this command.' )
4958 console . log ( '' )
59+ console . log ( 'Example: push --verbose --url data.sparkfun.com --public_key lzELagraWDiMMRra0V6Q --private_key XXXXXXXXXX --field_name temp' )
60+ console . log ( '' )
5061}
5162// This is the standard function for parsing process.argv. It will return
5263// an object that where `--argumentName` is a property name and the
0 commit comments