Created
December 13, 2012 11:27
-
-
Save korayal/4275847 to your computer and use it in GitHub Desktop.
Sending notification to your Android device via "Notify my Android" on Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// install these before (via 'npm install') | |
// https://github.com/Leonidas-from-XIV/node-xml2js | |
var xml2js = require('xml2js'); | |
// https://github.com/mikeal/request | |
var request = require('request'); | |
// fill in here with your api key from http://www.notifymyandroid.com/account.jsp | |
var apikey = ""; | |
// send a notification command to your device: | |
notifyMA(apikey, "News Crow", "Winter is Coming!", "It's been -4C degrees here, so Winter is coming for sure!", 4 ); | |
function notifyMA(keystring, appname, eventtitle, descriptiontext, priorityvalue){ | |
var parser = new xml2js.Parser(); | |
// you can also use (http|https).request but this was easier for me | |
var r = request.post('http://www.notifymyandroid.com/publicapi/notify', {form : {apikey: keystring, | |
application: appname, | |
event: eventtitle, | |
description: descriptiontext, | |
priority: priorityvalue}}, function (error, response, body) { | |
if (!error && response.statusCode == 200) { | |
parser.parseString(body.toString(), function(err, result){ | |
var success = result.nma.success[0].$; | |
// you can use these to manage your notification cases | |
console.log("response : " + success.code); | |
console.log("remaining : " + success.remaining); | |
console.log("resettimer : " + success.resettimer); | |
}); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment