You must have node and npm installed. From Terminal:
> brew install node
Then, after pulling down the project from git, run npm in from the project's root directory:
> npm start
The app expects the documents in the mongo collection to have this format:
{
"_id" : ObjectId("xxxxxxxxx"), // unique object id, auto-generated by mongo
"name" : "xxxxxxxxx", // unique client name
"apiKey" : "xxxxxxxxx", // BV API key for Tweeviews use
"encodingKey" : "xxxxxxxxx", // BV shared encoding key
"twitterHandle" : "xxxxxxxxx", // client's Twitter account
"consumerKey": "xxxxxxxxx", // client-specific Twitter API consumer key
"consumerSecret": "xxxxxxxxx", // client-specific Twitter API consumer secret
"accessTokenKey": "xxxxxxxxx", // client-specific Twitter API access token key
"accessTokenSecret": "xxxxxxxxx", // client-specific Twitter API access token secret
"searchInterval" : 0, // milliseconds between Twitter searches (0 to stop searching)
"products" : [ // array of products with Teeviews campaigns
{
"externalId" : "0000", // BV product id
"hashTag" : "tag", // hashtag to identify the product on Twitter (note: no hash sign)
"start" : 0000000000000, // start date of the campaign (milliseconds since Unix epoch)
"end" : 0000000000000 // end date of the campaign (milliseconds since Unix epoch)
},
{
"externalId" : "0001",
"hashTag" : "tag2",
"start" : 0000000000000,
"end" : null // note: end may be null
}
]
}
-
To work in the db, directly, launch
mongoin Terminal, connecting to the hackathon server instance. Ask around for the server URL. Then, run mongo commands against the tweeviews database and clients collection. See the mongodb reference for mongo operations. -
In node.js, we use the mongodb npm package with singleton db and collections objects created at server start via dbConnection.js. You probably will never need to access the db object; just use the collections object. To work on documents, do this:
var dbConnection = require("dbConnection.js"); dbConnection.getCollection(function(clientsCollection) { // find a client by name clientsCollection.find({ "name" : "clientName" // loop over each client found with the given name }).each(function(err, clientDoc) { if (err) { throw err; } if (clientDoc) { // do stuff with the client document console.log(JSON.stringify(clientDoc, null, " ")); } }); });
To add or update a client: http://localhost:3000/clients/. To add, update, or end a campaign: http://localhost:3000/campaigns/.
To turn the Twitter poller on or off, set data.twitterPoller.pollingInterval = n in config.js where n is some time value in milliseconds (0 = off).
Place configuration settings in config.js.