From 23d8a9babd4d90b7caba5c6904b1337799b009d9 Mon Sep 17 00:00:00 2001 From: Carlos Cordero Date: Fri, 2 Mar 2018 19:30:52 +0100 Subject: [PATCH 1/5] Pushover 3.0 api. Image attachment is now supported. Require babel-polyfill to fix object.entries error --- README.md | 14 ++++++++++++++ bin/pushover | 4 +++- lib/pushover-client.js | 14 +++++++++++++- package.json | 13 ++++++++++--- 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f406317..6d45239 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # node-pushover-client Send push notifications to iOS and Android using [Pushover][site]. +Compatible with Pushover 3.0 api, it now can send an attached image. + ## Usage [Register an application with Pushover.net][site-app] to get your application and user tokens. @@ -33,6 +35,18 @@ Pushover.send({ }); ``` +You also can attach an image. Full filepath must be specified. +Pushover's api limits must be followed: "Each message may only include one attachment, and attachments are currently limited to 2,621,440 bytes (2.5 megabytes)." + +```js +Pushover.send({ + token: 'KzGDORePK8gMaC0QOYAMyEEuzJnyUi', + user: 'uQiRzpo4DXghDmr9QzzfQu27cmVRsG', + message: 'Hello World', + attachment: FILEPATH +}); +``` + ## Command Line Usage ```sh $ npm -g install node-pushover-client diff --git a/bin/pushover b/bin/pushover index 5f74780..4ff0086 100755 --- a/bin/pushover +++ b/bin/pushover @@ -15,6 +15,7 @@ program .option('-i, --timestamp [timestamp]', 'a unix timestamp', parseInt) .option('-p, --priority [n]', 'priority (-1 to 2)', parseInt) .option('-d, --device [id]', 'device to send to', String) + .option('-f, --file [file]', 'file to attach', String) .parse(process.argv); new PushoverClient() @@ -26,7 +27,8 @@ new PushoverClient() expires: program.expires, retry: program.retry, timestamp: program.timestamp, - priority: program.priority + priority: program.priority, + attachment: program.attachment }) .then(function (res) { console.log(`Sent request: ${res.request}`); diff --git a/lib/pushover-client.js b/lib/pushover-client.js index 69cad27..f61eb28 100644 --- a/lib/pushover-client.js +++ b/lib/pushover-client.js @@ -1,6 +1,8 @@ +const fs = require('fs'); const fetch = require('node-fetch'); const FormData = require('form-data'); const snakeCase = require('lodash/snakeCase'); +require('babel-polyfill'); const endpoint = 'https://api.pushover.net/1/messages.json'; @@ -20,7 +22,17 @@ class Pushover { } for (let [key, value] of filterOptions(this.defaults, options)) { - form.append(key, value); + // If attachment is specified, create a file stream and include it into the form-data object + if (key === 'attachment') { + var stream = fs.readFileSync(value, options); + form.append(key, stream, { + filename: 'image.jpg', + contentType: stream.contentType, + knownLength: stream.byteLength + }); + } else { + form.append(key, value); + } } return fetch(endpoint, { diff --git a/package.json b/package.json index 0931299..440072c 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,10 @@ { "name": "node-pushover-client", - "version": "2.1.0", - "description": "Send push notifications to iOS and Android using Pushover.", + "version": "2.1.1", + "description": "Send push notifications to iOS and Android using Pushover. Include image attachment capabilities.", "main": "index.js", "dependencies": { + "babel-polyfill": "^6.26.0", "commander": "^2.9.0", "form-data": "^2.1.2", "lodash": "^4.17.2", @@ -17,9 +18,15 @@ }, "repository": { "type": "git", - "url": "git://github.com/dvdln/node-pushover-client.git" + "url": "git://github.com/ccorderor/node-pushover-client.git" }, "author": "David Lane ", + "contributors": [ + { + "name": "Carlos Cordero", + "url": "http://www.carloscordero.com" + } + ], "license": "ISC", "xo": { "space": true From 9919f47615ad011dc24964bfc02d7b02c5ca872c Mon Sep 17 00:00:00 2001 From: Carlos Cordero Date: Fri, 2 Mar 2018 19:36:01 +0100 Subject: [PATCH 2/5] Fix repository url --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 440072c..1c9c869 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ }, "repository": { "type": "git", - "url": "git://github.com/ccorderor/node-pushover-client.git" + "url": "git://github.com/dvdln/node-pushover-client.git" }, "author": "David Lane ", "contributors": [ From b039ad292f7c1f3a5ead39c8de756582c2e40260 Mon Sep 17 00:00:00 2001 From: Carlos Cordero Date: Fri, 2 Mar 2018 19:37:01 +0100 Subject: [PATCH 3/5] Fix package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1c9c869..3739c28 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "node-pushover-client", "version": "2.1.1", - "description": "Send push notifications to iOS and Android using Pushover. Include image attachment capabilities.", + "description": "Send push notifications to iOS and Android using Pushover. Include image attachment support.", "main": "index.js", "dependencies": { "babel-polyfill": "^6.26.0", From c9aa754fbf02a2a33a5f4db5b507de0d78129ace Mon Sep 17 00:00:00 2001 From: Carlos Cordero Date: Fri, 2 Mar 2018 19:38:05 +0100 Subject: [PATCH 4/5] Fix package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3739c28..b48f003 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ }, "repository": { "type": "git", - "url": "git://github.com/dvdln/node-pushover-client.git" + "url": "git://github.com/ccorderor/node-pushover-client.git" }, "author": "David Lane ", "contributors": [ From 5a00908b633f1d8e370a7bb1509e85d16547febd Mon Sep 17 00:00:00 2001 From: Carlos Cordero Date: Fri, 2 Mar 2018 19:38:46 +0100 Subject: [PATCH 5/5] Fix package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b48f003..3739c28 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ }, "repository": { "type": "git", - "url": "git://github.com/ccorderor/node-pushover-client.git" + "url": "git://github.com/dvdln/node-pushover-client.git" }, "author": "David Lane ", "contributors": [