Skip to content

Instantly share code, notes, and snippets.

@katowulf
Last active February 16, 2016 13:58
Show Gist options
  • Save katowulf/6996553 to your computer and use it in GitHub Desktop.
Save katowulf/6996553 to your computer and use it in GitHub Desktop.
Node.js process to queue from Firebase to Urban Airship.
// UNTESTED; THEORETICAL, based on http://docs.urbanairship.com/connect/ios_push.html
https://github.com/mikeal/request
var request = require('request');
/** Presumably the snapshot will contain something like this:
*
{
"audience": {"device_token": "FE66489F304DC75B8D6E8200DFF8A456E8DAEACEC428B427E9518741C92C6660"},
"notification": {
"ios": {
"alert" : {
"body" : "Bob wants to play poker",
"action-loc-key" : "PLAY"
},
},
"device_types": ["ios"]
}
*
*/
queuePushNotificationPath.on('child_added', function(snap) {
request.request({
uri: 'https://go.urbanairship.com/api/push/',
headers: {
'Accept': 'application/vnd.urbanairship+json; version=3;'
},
json: true,
auth: {
user: '<application key>',
pass: '<application master secret>'
},
body: JSON.stringify(snap.val());
}, function (error, response, body) {
if(response.statusCode == 201){
console.log('pushed successfully')
// remove the queue entry on success
snap.ref().remove();
} else {
console.log('error: '+ response.statusCode)
/* retry?? */
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment