pushover-notifications
Advanced tools
Comparing version 0.2.4 to 1.0.0
@@ -1,1 +0,1 @@ | ||
module.exports = require( './lib/pushover' ); | ||
module.exports = require('./lib/pushover') |
@@ -1,194 +0,194 @@ | ||
var https = require('https'), | ||
http = require('http'), | ||
url = require('url'), | ||
qs = require('querystring'), | ||
p_url = 'https://api.pushover.net/1/messages.json'; | ||
var https = require('https') | ||
var http = require('http') | ||
var url = require('url') | ||
var qs = require('querystring') | ||
var pUrl = 'https://api.pushover.net/1/messages.json' | ||
function setDefaults(o) { | ||
var def = [ | ||
'device', | ||
'title', | ||
'url', | ||
'url_title', | ||
'priority', | ||
'timestamp', | ||
'sound' | ||
]; | ||
function setDefaults (o) { | ||
var def = [ | ||
'device', | ||
'title', | ||
'url', | ||
'url_title', | ||
'priority', | ||
'timestamp', | ||
'sound' | ||
] | ||
var i = 0; l = def.length; | ||
for (; i < l; i++) { | ||
if (!o[def[i]]) { | ||
o[def[i]] = ''; | ||
} | ||
var i = 0 | ||
var l = def.length | ||
for (; i < l; i++) { | ||
if (!o[def[i]]) { | ||
o[def[i]] = '' | ||
} | ||
} | ||
return o; | ||
return o | ||
} | ||
function Pushover(opts) { | ||
var self = this; | ||
this.token = opts.token; | ||
this.user = opts.user; | ||
this.httpOptions = opts.httpOptions; | ||
this.sounds = { | ||
"pushover":"Pushover (default)", | ||
"bike":"Bike", | ||
"bugle":"Bugle", | ||
"cashregister":"Cash Register", | ||
"classical":"Classical", | ||
"cosmic":"Cosmic", | ||
"falling":"Falling", | ||
"gamelan":"Gamelan", | ||
"incoming":"Incoming", | ||
"intermission":"Intermission", | ||
"magic":"Magic", | ||
"mechanical":"Mechanical", | ||
"pianobar":"Piano Bar", | ||
"siren":"Siren", | ||
"spacealarm":"Space Alarm", | ||
"tugboat":"Tug Boat", | ||
"alien":"Alien Alarm (long)", | ||
"climb":"Climb (long)", | ||
"persistent":"Persistent (long)", | ||
"echo":"Pushover Echo (long)", | ||
"updown":"Up Down (long)", | ||
"none":"None (silent)" | ||
}; | ||
function Pushover (opts) { | ||
var self = this | ||
this.token = opts.token | ||
this.user = opts.user | ||
this.httpOptions = opts.httpOptions | ||
this.sounds = { | ||
'pushover': 'Pushover (default)', | ||
'bike': 'Bike', | ||
'bugle': 'Bugle', | ||
'cashregister': 'Cash Register', | ||
'classical': 'Classical', | ||
'cosmic': 'Cosmic', | ||
'falling': 'Falling', | ||
'gamelan': 'Gamelan', | ||
'incoming': 'Incoming', | ||
'intermission': 'Intermission', | ||
'magic': 'Magic', | ||
'mechanical': 'Mechanical', | ||
'pianobar': 'Piano Bar', | ||
'siren': 'Siren', | ||
'spacealarm': 'Space Alarm', | ||
'tugboat': 'Tug Boat', | ||
'alien': 'Alien Alarm (long)', | ||
'climb': 'Climb (long)', | ||
'persistent': 'Persistent (long)', | ||
'echo': 'Pushover Echo (long)', | ||
'updown': 'Up Down (long)', | ||
'none': 'None (silent)' | ||
} | ||
if (opts.debug) { | ||
this.debug = opts.debug; | ||
} | ||
if (opts.debug) { | ||
this.debug = opts.debug | ||
} | ||
if (opts.onerror) { | ||
this.onerror = opts.onerror; | ||
} | ||
if (opts.onerror) { | ||
this.onerror = opts.onerror | ||
} | ||
if (opts.update_sounds) { | ||
self.updateSounds(); | ||
setInterval(function() { | ||
self.updateSounds(); | ||
}, 86400000); | ||
} | ||
if (opts.update_sounds) { | ||
self.updateSounds() | ||
setInterval(function () { | ||
self.updateSounds() | ||
}, 86400000) | ||
} | ||
} | ||
Pushover.prototype.errors = function(d) { | ||
if (typeof d === 'string') { | ||
d = JSON.parse(d); | ||
} | ||
Pushover.prototype.errors = function (d, res) { | ||
if (typeof d === 'string') { | ||
d = JSON.parse(d) | ||
} | ||
if (d.errors) { | ||
if (this.onerror) { | ||
this.onerror.call(null, d.errors[0]); | ||
} else { | ||
throw new Error(d.errors[0]); | ||
} | ||
if (d.errors) { | ||
if (this.onerror) { | ||
this.onerror(d.errors[0], res) | ||
} else { | ||
throw new Error(d.errors[0], res) | ||
} | ||
}; | ||
} | ||
} | ||
Pushover.prototype.updateSounds = function() { | ||
var self = this, data = ''; | ||
var surl = 'https://api.pushover.net/1/sounds.json?token=' + self.token; | ||
var req = https.request(url.parse(surl) , function(res) { | ||
res.on('end', function() { | ||
var j = JSON.parse(data); | ||
self.errors(data); | ||
self.sounds = j.sounds; | ||
}); | ||
Pushover.prototype.updateSounds = function () { | ||
var self = this | ||
var data = '' | ||
var surl = 'https://api.pushover.net/1/sounds.json?token=' + self.token | ||
var req = https.request(url.parse(surl), function (res) { | ||
res.on('end', function () { | ||
var j = JSON.parse(data) | ||
self.errors(data, res) | ||
self.sounds = j.sounds | ||
}) | ||
res.on('data', function(chunk) { | ||
data += chunk; | ||
}); | ||
res.on('data', function (chunk) { | ||
data += chunk | ||
}) | ||
}) | ||
}); | ||
req.on('error', function (e) { | ||
self.errors(e) | ||
}) | ||
req.on('error', function(e) { | ||
err = e; | ||
}); | ||
req.write('') | ||
req.end() | ||
} | ||
req.write(''); | ||
req.end(); | ||
}; | ||
Pushover.prototype.send = function (obj, fn) { | ||
var self = this | ||
var o = url.parse(pUrl) | ||
var proxy | ||
o.method = 'POST' | ||
Pushover.prototype.send = function(obj, fn) { | ||
var self = this; | ||
var o = url.parse(p_url); | ||
var proxy; | ||
o.method = "POST"; | ||
obj = setDefaults(obj) | ||
obj = setDefaults(obj); | ||
var reqString = { | ||
token: self.token || obj.token, | ||
user: self.user || obj.user | ||
} | ||
var req_string = { | ||
token: self.token || obj.token, | ||
user: self.user || obj.user | ||
}; | ||
var p | ||
for (p in obj) { | ||
reqString[ p ] = obj[p] | ||
} | ||
var p; | ||
for (p in obj) { | ||
req_string[ p ] = obj[p]; | ||
} | ||
reqString = qs.stringify(reqString) | ||
req_string = qs.stringify(req_string); | ||
o.headers = { | ||
'Content-Length': reqString.length | ||
} | ||
o.headers = { | ||
'Content-Length': req_string.length | ||
}; | ||
var httpOpts = self.httpOptions || {} | ||
if (httpOpts) { | ||
Object.keys(httpOpts).forEach(function (key) { | ||
if (key !== 'proxy') { | ||
o[key] = httpOpts[key] | ||
} | ||
}) | ||
} | ||
var httpOpts = self.httpOptions || {}; | ||
if (httpOpts) { | ||
Object.keys(httpOpts).forEach(function(key) { | ||
if (key !== 'proxy') { | ||
o[key] = httpOpts[key]; | ||
} | ||
}); | ||
} | ||
if (httpOpts.hasOwnProperty('proxy') && httpOpts.proxy && httpOpts.proxy !== '') { | ||
proxy = url.parse(httpOpts.proxy) | ||
o.headers.Host = o.host | ||
o.host = proxy.hostname | ||
o.protocol = proxy.protocol | ||
} | ||
if (httpOpts.hasOwnProperty('proxy') && httpOpts.proxy !== "") { | ||
proxy = url.parse(httpOpts.proxy); | ||
o.headers.Host = o.host; | ||
o.host = proxy.hostname; | ||
o.port = proxy.port; | ||
o.protocol = proxy.protocol; | ||
} | ||
var request | ||
if (httpOpts.proxy && httpOpts.proxy !== '') { | ||
request = http.request | ||
} else { | ||
request = https.request | ||
} | ||
var request; | ||
if (httpOpts.proxy && httpOpts.proxy !== "") { | ||
request = http.request; | ||
} else { | ||
request = https.request; | ||
var req = request(o, function (res) { | ||
if (self.debug) { | ||
console.log(res.statusCode) | ||
} | ||
var err | ||
var data = '' | ||
res.on('end', function () { | ||
self.errors(data, res) | ||
if (fn) { | ||
fn(err, data, res) | ||
} | ||
}) | ||
req = request(o, function(res) { | ||
if (self.debug) { | ||
console.log(res.statusCode); | ||
} | ||
var err; | ||
var data = ''; | ||
res.on('end', function() { | ||
self.errors(data); | ||
if (fn) { | ||
fn.call(null, err, data); | ||
} | ||
}); | ||
res.on('data', function (chunk) { | ||
data += chunk | ||
}) | ||
}) | ||
res.on('data', function(chunk) { | ||
data += chunk; | ||
}); | ||
}); | ||
req.on('error', function (err) { | ||
if (fn) { | ||
fn(err) | ||
} | ||
// In the tests the "end" event did not get emitted if "error" was emitted, | ||
// but to be sure that the callback is not get called twice, null the callback function | ||
fn = null | ||
}) | ||
req.on('error', function(err) { | ||
if (fn) { | ||
fn.call(null, err); | ||
} | ||
// In the tests the "end" event did not get emitted if "error" was emitted, | ||
// but to be sure that the callback is not get called twice, null the callback function | ||
fn = null; | ||
}); | ||
if (self.debug) { | ||
console.log(reqString.replace(self.token, 'XXXXX').replace(self.user, 'XXXXX')) | ||
} | ||
req.write(reqString) | ||
req.end() | ||
} | ||
if (self.debug) { | ||
console.log (req_string.replace(self.token, 'XXXXX').replace(self.user, 'XXXXX')); | ||
} | ||
req.write(req_string); | ||
req.end(); | ||
}; | ||
exports = module.exports = Pushover; | ||
exports = module.exports = Pushover |
@@ -5,3 +5,3 @@ { | ||
"description": "Pushover API for node.js", | ||
"version": "0.2.4", | ||
"version": "1.0.0", | ||
"homepage": "http://github.com/qbit/node-pushover", | ||
@@ -19,4 +19,4 @@ "repository": { | ||
"scripts": { | ||
"test": "node test/test.js" | ||
"test": "standard && pkill tinyproxy ; tinyproxy -c test/tinyproxy.conf && set -e; for t in test/*.js; do node $t; done" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
![Pushover](https://pushover.net/assets/pushover-header-0f47af8e08d8bef658a999a9e6584fcc.png) | ||
![Pushover](img/pushover-header.png) | ||
@@ -6,4 +6,7 @@ Send [pushover.net](http://pushover.net) notifications from Node.JS | ||
[![Build Status](https://travis-ci.org/qbit/node-pushover.svg?branch=master)](https://travis-ci.org/qbit/node-pushover) | ||
[![Coverity Scan Build Status](https://img.shields.io/coverity/scan/10939.svg)](https://scan.coverity.com/projects/qbit-node-pushover) | ||
[![Coverity Scan Build Status](https://scan.coverity.com/projects/10939/badge.svg)](https://scan.coverity.com/projects/qbit-node-pushover) | ||
[![NPM](https://nodei.co/npm/pushover-notifications.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/pushover-notifications/) | ||
## Usage | ||
@@ -14,3 +17,3 @@ | ||
npm install pushover-notifications | ||
### Pushover API values | ||
@@ -21,10 +24,10 @@ | ||
var msg = { | ||
message: "This is a message", | ||
title: "Well - this is fantastic", | ||
sound: 'magic', | ||
device: 'test_device', | ||
priority: 2, | ||
url: "http://pushover.net", | ||
url_title: "Pushover Website" | ||
}; | ||
message: "This is a message", | ||
title: "Well - this is fantastic", | ||
sound: 'magic', | ||
device: 'test_device', | ||
priority: 2, | ||
url: "http://pushover.net", | ||
url_title: "Pushover Website" | ||
} | ||
``` | ||
@@ -36,35 +39,36 @@ ## Examples | ||
var push = require( 'pushover-notifications' ); | ||
var Push = require( 'pushover-notifications' ) | ||
var p = new push( { | ||
user: process.env['PUSHOVER_USER'], | ||
token: process.env['PUSHOVER_TOKEN'], | ||
// httpOptions: { | ||
// proxy: process.env['http_proxy'], | ||
//}, | ||
// onerror: function(error) {}, | ||
// update_sounds: true // update the list of sounds every day - will | ||
// prevent app from exiting. | ||
}); | ||
var p = new Push( { | ||
user: process.env['PUSHOVER_USER'], | ||
token: process.env['PUSHOVER_TOKEN'], | ||
// httpOptions: { | ||
// proxy: process.env['http_proxy'], | ||
//}, | ||
// onerror: function(error) {}, | ||
// update_sounds: true // update the list of sounds every day - will | ||
// prevent app from exiting. | ||
}) | ||
var msg = { | ||
// These values correspond to the parameters detailed on https://pushover.net/api | ||
// 'message' is required. All other values are optional. | ||
message: 'omg node test', // required | ||
title: "Well - this is fantastic", | ||
sound: 'magic', | ||
device: 'devicename', | ||
priority: 1 | ||
}; | ||
// These values correspond to the parameters detailed on https://pushover.net/api | ||
// 'message' is required. All other values are optional. | ||
message: 'omg node test', // required | ||
title: "Well - this is fantastic", | ||
sound: 'magic', | ||
device: 'devicename', | ||
priority: 1 | ||
} | ||
p.send( msg, function( err, result ) { | ||
if ( err ) { | ||
throw err; | ||
} | ||
if ( err ) { | ||
throw err | ||
} | ||
console.log( result ); | ||
}); | ||
console.log( result ) | ||
}) | ||
``` | ||
### Sending a message to multiple users | ||
```javascript | ||
@@ -76,3 +80,3 @@ | ||
'token3' | ||
]; | ||
] | ||
@@ -84,7 +88,6 @@ var msg = { | ||
priority: 1 // optional, | ||
}; | ||
} | ||
for ( var i = 0, l = users.length; i < l; i++ ) { | ||
msg.user = users[i]; | ||
msg.user = users[i] | ||
// token can be overwritten as well. | ||
@@ -94,9 +97,8 @@ | ||
if ( err ) { | ||
throw err; | ||
throw err | ||
} | ||
console.log( result ); | ||
}); | ||
console.log( result ) | ||
}) | ||
} | ||
``` |
@@ -1,21 +0,21 @@ | ||
var push = require( '../lib/pushover.js' ); | ||
var Push = require('../lib/pushover.js') | ||
var p = new push( { | ||
// user: process.env['PUSHOVER_USER'], | ||
token: process.env['PUSHOVER_TOKEN'], | ||
debug: true | ||
}); | ||
var p = new Push({ | ||
// user: process.env['PUSHOVER_USER'], | ||
token: process.env['PUSHOVER_TOKEN'], | ||
debug: true | ||
}) | ||
var msg = { | ||
message: 'test from ' + process.argv[1], | ||
title: "Well - this is fantastic", | ||
message: 'test from ' + process.argv[1], | ||
title: 'Well - this is fantastic', | ||
user: process.env['PUSHOVER_USER'] | ||
}; | ||
} | ||
// console.log( p ); | ||
p.send( msg, function( err, result ) { | ||
console.log( err ); | ||
console.log( result ); | ||
process.exit(0); | ||
}); | ||
p.send(msg, function (err, result) { | ||
console.log(err) | ||
console.log(result) | ||
process.exit(0) | ||
}) |
@@ -1,25 +0,25 @@ | ||
var push = require( '../lib/pushover.js' ); | ||
var Push = require('../lib/pushover.js') | ||
var p = new push( { | ||
user: process.env['PUSHOVER_USER'], | ||
token: process.env['PUSHOVER_TOKEN'], | ||
httpOptions: { | ||
proxy: process.env['http_proxy'], | ||
}, | ||
update_sounds: false, | ||
debug: true | ||
}); | ||
var p = new Push({ | ||
user: process.env['PUSHOVER_USER'], | ||
token: process.env['PUSHOVER_TOKEN'], | ||
httpOptions: { | ||
proxy: process.env['http_proxy'] | ||
}, | ||
update_sounds: false, | ||
debug: true | ||
}) | ||
var msg = { | ||
message: 'test from ' + process.argv[1], | ||
sound: 'magic', | ||
title: "test from", | ||
}; | ||
message: 'test from ' + process.argv[1], | ||
sound: 'magic', | ||
title: 'test from' | ||
} | ||
// console.log( p ); | ||
p.send( msg, function( err, result ) { | ||
console.log( 'error', err ); | ||
console.log( 'result', result ); | ||
// process.exit(0); | ||
}); | ||
p.send(msg, function (err, result) { | ||
console.log('error', err) | ||
console.log('result', result) | ||
// process.exit(0); | ||
}) |
@@ -1,25 +0,31 @@ | ||
var push = require( '../lib/pushover.js' ); | ||
var Push = require('../lib/pushover.js') | ||
var p = new push( { | ||
user: process.env['PUSHOVER_USER'], | ||
token: process.env['PUSHOVER_TOKEN'], | ||
update_sounds: false, | ||
debug: true, | ||
onerror: function(err) { | ||
console.log('ERROR!', err); | ||
} | ||
}); | ||
var p = new Push({ | ||
user: process.env['PUSHOVER_USER'], | ||
token: process.env['PUSHOVER_TOKEN'] + 'ERROR_TEST', | ||
update_sounds: false, | ||
debug: true, | ||
onerror: function (err, res) { | ||
console.log('ERROR!', err) | ||
if (err.match('application token is invalid')) { | ||
if (res) { | ||
console.log(res.headers) | ||
} | ||
process.exit(0) | ||
} else { | ||
process.exit(1) | ||
} | ||
} | ||
}) | ||
var msg = { | ||
message: 'test from ' + process.argv[1], | ||
sound: 'magic', | ||
title: "Well - this is fantastic", | ||
}; | ||
message: 'test from ' + process.argv[1], | ||
sound: 'magic', | ||
title: 'Well - this is fantastic' | ||
} | ||
// console.log( p ); | ||
p.send( msg, function( err, result ) { | ||
console.log( 'error', err ); | ||
console.log( 'result', result ); | ||
// process.exit(0); | ||
}); | ||
p.send(msg, function (err, result, res) { | ||
console.log('error', err) | ||
console.log('result', result) | ||
console.log('res.headers', res.headers) | ||
}) |
@@ -1,22 +0,23 @@ | ||
var push = require( '../lib/pushover.js' ); | ||
var Push = require('../lib/pushover.js') | ||
var p = new push( { | ||
user: process.env['PUSHOVER_USER'], | ||
token: process.env['PUSHOVER_TOKEN'], | ||
update_sounds: false, | ||
debug: true | ||
}); | ||
var p = new Push({ | ||
user: process.env['PUSHOVER_USER'], | ||
token: process.env['PUSHOVER_TOKEN'], | ||
update_sounds: false, | ||
debug: true | ||
}) | ||
var msg = { | ||
message: 'test from ' + process.argv[1], | ||
sound: 'magic', | ||
title: "Well - this is fantastic", | ||
}; | ||
message: 'test from ' + process.argv[1], | ||
sound: 'magic', | ||
title: 'Well - this is fantastic' | ||
} | ||
// console.log( p ); | ||
p.send( msg, function( err, result ) { | ||
console.log( 'error', err ); | ||
console.log( 'result', result ); | ||
// process.exit(0); | ||
}); | ||
p.send(msg, function (err, result, res) { | ||
console.log('error', err) | ||
console.log('result', result) | ||
console.log('res.headers', res.headers) | ||
// process.exit(0); | ||
}) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
238256
14
253
0
98
3