Created
August 17, 2016 18:06
-
-
Save eibrahim/bcf8117de0910e87e0101f601f5c7f3f to your computer and use it in GitHub Desktop.
Notify zapier with firebase changes
This file contains hidden or 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
var firebase = require("firebase"); | |
var request = require("request"); | |
var db = require('./database'); | |
var notifyZapierOfJobPost = function(snapshot){ | |
var job = snapshot.val(); | |
var key = snapshot.key; | |
var email = job.email; | |
if(job.sent_to_zapier) return; //ignore if already sent | |
if(!email) return; //ignore if email is blank | |
var zapierNewJobPost = 'https://hooks.zapier.com/hooks/catch/xxx/xxx/'; | |
request({ | |
url: zapierNewJobPost, | |
method: "POST", | |
json: job | |
}); | |
db.ref('jobs/'+ key +'/sent_to_zapier').set(true); | |
} | |
var jobsRef = db.ref('jobs'); | |
jobsRef.orderByChild('sent_to_zapier').equalTo(null).on('child_changed', notifyZapierOfJobPost); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment