Skip to content

Instantly share code, notes, and snippets.

@huangjs
Created December 13, 2012 01:54
Show Gist options
  • Save huangjs/4273403 to your computer and use it in GitHub Desktop.
Save huangjs/4273403 to your computer and use it in GitHub Desktop.
Example code for using FullContact influencer notification in iced-coffee-script on node.js.
# This is example code for influencer notification using FullContact on node.js
# Programming language used here is iced-coffee-script
# Author: Maptia
# License: public domain
_ = require 'underscore'
iced = require('iced-coffee-script').iced
request = require 'request'
fullContactAPIKey = '<your-fullcontact-api-key>'
# settings for notification emails
nodemailer = require("nodemailer")
smtpTransport = nodemailer.createTransport "SMTP",
service: "Gmail",
auth: {user: "[email protected]", pass: "xxxx"}
mailOptions =
from: "[email protected]"
to: "[email protected]"
subject: "Notification for influencer sign-up"
# extracting influencer key indices
# 1) number of twitter follows and 2) klout score
extractInfluencerIndex = (fullcontact) ->
twitter = _(fullcontact?.socialProfiles).where({type: 'twitter'})[0]
twitterFollowers = twitter?.followers
klout = _(fullcontact?.digitalFootprint?.scores).where({provider: 'klout', type: 'general'})[0]
kloutScore = klout?.value
return [twitterFollowers, kloutScore]
# retrieving FullContact info for the input email
getFullContactByEmail = (email, cb) ->
await request.get {url: fullContactUrl, qs: {prettyPrint: false, apiKey: fullContactAPIKey, email: email}, json: true}, defer err, res, body
if err or res.statusCode != 200
cb(err || {status: res.statusCode}) # could report more info here
else
cb(null, body)
# reserving user account and sending notifications
# here we identify influencers who have more than 5000 twitter followers or have klout score greater than 50
reserveUserAccount = (username, email) ->
...<your user registration code here>...
# influencer identification and email notification
await getFullContactByEmail email, defer err, result
fullcontact = result
[twitterFollowers, kloutScore] = extractInfluencerIndex(fullcontact)
if err then console.log "Cannot get FullContact info", err
if (twitterFollowers and twitterFollowers >= 5000) or (kloutScore and kloutScore >= 50.0)
console.log "Send influencer notification email for user: #{username}, twitter-followers: #{twitterFollowers}, klout score: #{kloutScore}"
await smtpTransport.sendMail _.extend(mailOptions, {text: "Username: #{username}, Email: #{email}, TwitterFollowers: #{twitterFollowers}, kloutScore: #{kloutScore}\n FullContact: #{fullcontact}"}), defer err, res
if err
console.log err
else
console.log "Influencer notification sent"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment