Skip to content

Instantly share code, notes, and snippets.

@korayal
Created December 13, 2012 11:27
Show Gist options
  • Save korayal/4275847 to your computer and use it in GitHub Desktop.
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
// 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