Created
September 2, 2015 20:26
-
-
Save KyleAMathews/de4441013692093e7cdf to your computer and use it in GitHub Desktop.
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
config = require 'config' | |
redis = require 'redis' | |
mysql = require 'mysql' | |
request = require 'request' | |
assign = require 'object-assign' | |
_ = require 'underscore' | |
graphql = require('../utils/graphql') | |
# Listen to Kafka for new pageOpens, pageCreates | |
# Load past pageOpens from MySQL | |
# Load events from DB and run through aggregators. | |
db = config.database | |
connection = mysql.createConnection({ | |
host: db.host | |
user: db.username | |
password: db.password | |
database: db.database | |
}) | |
graphql(""" | |
query fetchInsightlyInformation { | |
organization(id: "ff05ec48-f825-47fa-8e24-9612dd0de8e1") { | |
name | |
domain | |
integrations { | |
insightly { | |
api_key | |
} | |
} | |
} | |
} | |
""", (err, error, results) -> | |
console.log err, error | |
console.log JSON.stringify results, null, 4 | |
apiKey = results.data.organization?.integrations?.insightly?.api_key | |
console.log apiKey | |
console.log apiKey = new Buffer(apiKey).toString('base64') | |
request({ | |
method: 'get' | |
gzip: true | |
headers: | |
'Authorization': 'Basic ' + apiKey | |
url: 'https://api.insight.ly/v2.1/Contacts?email=kyle@getpantheon.com' | |
}, (err, res, body) -> | |
console.log err | |
console.log contact = JSON.parse(body)[0] | |
console.log contact.CONTACT_ID | |
contact.CUSTOMFIELDS.push { | |
TESTING_TESTING: "Just testing yo" | |
FIELD_VALUE: "Pizza" | |
} | |
contact = _.pick contact, 'CONTACT_ID', "CUSTOMFIELDS" | |
console.log JSON.stringify contact, null, 4 | |
request({ | |
method: 'put' | |
gzip: true | |
headers: | |
'Authorization': 'Basic ' + apiKey | |
url: "https://api.insight.ly/v2.1/Contacts" | |
json: contact | |
}, (err, res, body) -> | |
console.log JSON.stringify res, null, 4 | |
console.log err, body | |
) | |
) | |
) | |
#connection.query( | |
#""" | |
#select * | |
#from events | |
#where event_type='pageOpened' | |
#order by timestamp | |
#limit 100 | |
#""", (err, events) -> | |
##console.log events | |
#for event in events | |
#graphql(""" | |
#query fetchHubspotAPIKey { | |
#page(id: "#{event.entity_id}") { | |
#absolute_url | |
#recipient { | |
#hubspot_contact_id | |
#person { | |
#} | |
#} | |
#organization { | |
#name | |
#domain | |
#integrations { | |
#insightly { | |
#api_key | |
#} | |
#} | |
#} | |
#} | |
#} | |
#""", (err, error, result) -> | |
#console.log err, error | |
#if result.data?.page?.organization?.name? | |
#console.log JSON.stringify result, null, 4 | |
#) | |
#) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment