Skip to content

Commit 7d05161

Browse files
committed
adapted for stream input
1 parent 7ce5a72 commit 7d05161

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"test": "push"
88
},
99
"dependencies": {
10-
"commander": "2.6.0"
10+
"commander": "2.6.0",
11+
"split": "1.0.0"
1112
},
1213
"repository": {
1314
"type": "git",

push

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
#!/usr/bin/env node
22

33
var http = require('http')
4+
var split = require('split');
45
var options = parseArgv(process.argv)
56

67

78

89
if (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+
}
1119
else 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

Comments
 (0)