Merge pull request #1 from philskents/addPushNotifications

Added push notification support to app
This commit is contained in:
Phil Skentelbery
2017-11-14 20:07:53 -06:00
committed by GitHub
2 changed files with 24 additions and 1 deletions

View File

@ -2,6 +2,7 @@
const fetch = require('node-fetch'); const fetch = require('node-fetch');
const commandLineArgs = require('command-line-args'); const commandLineArgs = require('command-line-args');
const getUsage = require('command-line-usage'); const getUsage = require('command-line-usage');
const push = require( 'pushover-notifications' );
// Get partNumbers from json file. // Get partNumbers from json file.
const partNumbers = require('./partNumbers.json'); const partNumbers = require('./partNumbers.json');
@ -101,6 +102,13 @@ const endpoint = `https://www.apple.com/shop/retail/pickup-message?pl=true&cppar
// Keep track of the last request time. // Keep track of the last request time.
let lastRequestTimestamp = null; let lastRequestTimestamp = null;
// Construct push endpoint
const p = new push ( {
user: process.env.PUSHOVER_USER,
token: process.env.PUSHOVER_TOKEN
});
/** /**
* Update program status display * Update program status display
* *
@ -175,6 +183,15 @@ function displayStoresAvailable(storesAvailable) {
console.log(storesAvailableStr); console.log(storesAvailableStr);
} }
// Build the message
const msg = {
message: 'iPhone X stock available nearby!',
title: 'Important News!',
priority: 2,
retry: 60,
expire: 1800
};
/** /**
* The main program loop * The main program loop
* *
@ -193,6 +210,11 @@ async function requestLoop() {
} else { } else {
// The device is available. Show that information to the user and exit the program. // The device is available. Show that information to the user and exit the program.
displayStoresAvailable(storesAvailable); displayStoresAvailable(storesAvailable);
p.send (msg, function (err, result){
if (err) {
throw err;
}
})
process.exit(); process.exit();
} }
} }

View File

@ -12,7 +12,8 @@
"dependencies": { "dependencies": {
"command-line-args": "^4.0.7", "command-line-args": "^4.0.7",
"command-line-usage": "^4.0.1", "command-line-usage": "^4.0.1",
"node-fetch": "^1.7.3" "node-fetch": "^1.7.3",
"pushover-notifications": "^0.2.4"
}, },
"devDependencies": { "devDependencies": {
"eslint": "^4.10.0", "eslint": "^4.10.0",