Skip to content

Commit

Permalink
Merge pull request #1 from databox/attributes
Browse files Browse the repository at this point in the history
Adding additional attributes
  • Loading branch information
otobrglez committed Jul 22, 2015
2 parents f06f71d + f415e37 commit ffbb218
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,18 @@ client.insertAll([
{
key: 'js.prices.gas',
value: 100,

// With date
date: '2015-06-23 09:00:00'
},
{
key: 'js.prices.gas',
value: 200,

// With additional attributes
attributes: {
'station': 'ny-main'
}
}
], function(result){
console.log(result);
Expand Down Expand Up @@ -68,6 +79,11 @@ client.lastPushes(10, function (pushes) {

git clone ...
npm test

## Debugging

# Add "debugger" keyword anywhere and run
mocha debug test

## Author & Licence
- [Oto Brglez](https://github.com/otobrglez)
Expand Down
5 changes: 5 additions & 0 deletions lib/databox.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ Databox.prototype._processKPI = function (kpi) {
//TODO: If it's some kind of Date/Time instance do "casting".
}

if (kpi.hasOwnProperty('attributes') || typeof(kpi.attributes) != "undefined") {
for(var k in kpi.attributes)
out[k] = kpi.attributes[k];
}

return out;
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "databox",
"version": "0.2.0",
"version": "0.2.1",
"description": "Node.js bindings bindings for Databox",
"author": {
"name": "Oto Brglez",
Expand Down
21 changes: 21 additions & 0 deletions test/databox.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,27 @@ describe('Databox', function () {
});
});

it('Should push KPI w/ #push and additional attributes', function (done) {
var key = 'test';
var value = 300;

Databox.prototype._pushJSONRequest = function (options, data, cb) {
var i_value = data[0][util.format('$%s', key)];
assert.equal(i_value, value);
assert.equal(data[0].me, 'Oto');
done();
};

databox.push({
key: key,
value: value,
attributes: {
'me': 'Oto'
}
});

});

it('Should push KPI w/ #push & callback', function (done) {
var key = 'me.key';
var value = 299;
Expand Down

0 comments on commit ffbb218

Please sign in to comment.