Skip to content

Commit

Permalink
fixing issue with analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
brozeph committed Feb 23, 2017
1 parent 549f325 commit 7fb994f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
4 changes: 4 additions & 0 deletions history.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v1.1.9 - 2017/02/23

* Added support for `analytics` filters used in `device-api`

# v1.1.8 - 2017/02/23

* Fixed defect where when `token` was not supplied to `ensureAuthHeaders`, the method would fail
Expand Down
21 changes: 13 additions & 8 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,30 +64,35 @@ module.exports = (function (self) {
// apply filter parameters (requires special handling for bracket notation)
if (!validation.isEmpty(filters)) {
// apply mandatory and optional filter parameters
['mandatory', 'optional'].forEach((required) => {
if (!validation.isEmpty(filters[required])) {
Object.keys(filters[required]).forEach((match) => {
['mandatory', 'optional'].forEach((clause) => {
if (!validation.isEmpty(filters[clause])) {
Object.keys(filters[clause]).forEach((match) => {
// check for filters where the field name is the value
if (['exists', 'missing'].indexOf(match) >= 0) {
let value = filters[required][match];
let value = filters[clause][match];
if (!validation.isEmpty(value)) {
formatted[`filters[${required}][${match}]`] = value;
formatted[`filters[${clause}][${match}]`] = value;
}

return;
}

// apply filters where field name is part of the filter param
Object.keys(filters[required][match]).forEach((field) => {
let value = filters[required][match][field];
Object.keys(filters[clause][match]).forEach((field) => {
let value = filters[clause][match][field];
if (!validation.isEmpty(value)) {
formatted[`filters[${required}][${match}][${field}]`] = value;
formatted[`filters[${clause}][${match}][${field}]`] = value;
}
});
});
}
});

// apply analytics filter parameter (for device-api)
if (!validation.isEmpty(filters.analytics)) {
formatted['filters[analytics]'] = filters.analytics;
}

// apply diagnostics filter parameter (for device-api)
if (!validation.isEmpty(filters.diagnostics)) {
formatted['filters[diagnostics]'] = filters.diagnostics;
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": "playnetwork-sdk",
"version": "1.1.8",
"version": "1.1.9",
"contributors": [
{
"name": "Joshua Thomas",
Expand Down
3 changes: 3 additions & 0 deletions test/lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ describe('request', () => {
clientId : 'clientId',
count : 100,
filters : {
analytics : ['monitored'],
diagnostics : ['online', 'offline'],
field : ['field1', 'field2'],
keyword : 'keyword',
Expand Down Expand Up @@ -440,6 +441,8 @@ describe('request', () => {
requestInfo.query['filters[optional][lte][o.lte]'].should.equal(1);
should.exist(requestInfo.query['filters[optional][missing]']);
requestInfo.query['filters[optional][missing]'].should.equal('missing');
should.exist(requestInfo.query['filters[analytics]']);
requestInfo.query['filters[analytics]'].should.contain('monitored');
should.exist(requestInfo.query['filters[diagnostics]']);
requestInfo.query['filters[diagnostics]'].should.equal('online,offline');
should.exist(requestInfo.query['filters[field]']);
Expand Down

0 comments on commit 7fb994f

Please sign in to comment.