Created
November 30, 2013 03:42
-
-
Save reynaldot/7715079 to your computer and use it in GitHub Desktop.
Adds a single event to a collection and queries the analytics API for a simple event count.
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
var should = require('should') | |
, assert = require('assert') | |
, request = require('request') | |
, qs = require('querystring'); | |
describe('keen api', function () { | |
var projectId = 'my_project_id' | |
, masterKey = 'my_master_key' | |
, writeKey = 'my_write_key' | |
, readKey = 'my_read_key' | |
, baseURL = 'https://api.keen.io/3.0/projects/' + projectId | |
, collection = 'mycollection' | |
, keen; | |
before( function () { | |
keen = require('keen.io').configure({ | |
projectId: projectId, | |
writeKey: writeKey | |
}); | |
}); | |
describe('add event', function () { | |
it ('should add one event to mycollection', function (done) { | |
keen.addEvent(collection, {foo: 'foo'}, function (err, res) { | |
should.not.exist(err); | |
done(); | |
}); | |
}); | |
it ('should count one event on mycollection', function (done) { | |
var url = baseURL +'/queries/count?' | |
var params = { | |
api_key: readKey, | |
event_collection: collection, | |
interval: 'hourly', | |
timeframe: 'this_hour' | |
}; | |
url += qs.stringify(params); | |
request.get({url: url}, function (err, res, body) { | |
var result = JSON.parse(body).result; | |
result[0].value.should.equal(1); | |
done(); | |
}); | |
}); | |
}); | |
after( function (done) { | |
var url = baseURL +'/events/' + collection | |
var headers = { | |
Authorization: masterKey | |
}; | |
request.del({url: url, headers: headers}, function (err, res, body) { | |
should.not.exist(err); | |
done(); | |
}); | |
}); | |
}); |
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
{ | |
"name": "keen-test", | |
"version": "0.0.0", | |
"description": "Keen.io API test", | |
"main": "index.js", | |
"scripts": { | |
"test": "mocha keen-test.js" | |
}, | |
"author": "Reynaldo Tortoledo", | |
"license": "BSD-2-Clause", | |
"dependencies": { | |
"keen.io": "0.0.3", | |
"request": "~2.27.0", | |
"should": "~2.1.0", | |
"mocha": "~1.14.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Most of the times this test fails, meaning collections in Keen.io do not appear to have / provide immedate access to newly added events.
Is Keen.io suitable for realtime applications?