Skip to content

Commit

Permalink
Merge pull request #13 from PlayNetwork/v1.0.13
Browse files Browse the repository at this point in the history
V1.0.13
  • Loading branch information
brozeph committed May 13, 2016
2 parents 9e174f8 + 82186d6 commit 4c379d1
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 120 deletions.
4 changes: 4 additions & 0 deletions history.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v1.0.13 - 2016/05/12

* Added support for additional request option for each sub-module (timeout)

# v1.0.12 - 2016/05/06

* Fixed defect where date objects could be viewed as empty
Expand Down
18 changes: 1 addition & 17 deletions lib/claim.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,7 @@ module.exports = function (claimOptions, ensureAuthHeaders, self) {
claimOptions.secure;

// apply additional optional settings if supplied
if (!validation.isEmpty(claimOptions)) {
if (!validation.isEmpty(claimOptions.agent)) {
settings.agent = claimOptions.agent;
}

if (!validation.isEmpty(claimOptions.maxRetries)) {
settings.maxRetries = claimOptions.maxRetries;
}

if (!validation.isEmpty(claimOptions.port)) {
settings.port = claimOptions.port;
}

if (!validation.isEmpty(claimOptions.rejectUnauthorized)) {
settings.rejectUnauthorized = claimOptions.rejectUnauthorized;
}
}
settings = validation.applyOptionalParameters(claimOptions, settings);

// ensure request is setup
req = new request.Request(settings);
Expand Down
18 changes: 1 addition & 17 deletions lib/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,7 @@ module.exports = function (contentOptions, ensureAuthHeaders, self) {
contentOptions.secure;

// apply additional optional settings if supplied
if (!validation.isEmpty(contentOptions)) {
if (!validation.isEmpty(contentOptions.agent)) {
settings.agent = contentOptions.agent;
}

if (!validation.isEmpty(contentOptions.maxRetries)) {
settings.maxRetries = contentOptions.maxRetries;
}

if (!validation.isEmpty(contentOptions.port)) {
settings.port = contentOptions.port;
}

if (!validation.isEmpty(contentOptions.rejectUnauthorized)) {
settings.rejectUnauthorized = contentOptions.rejectUnauthorized;
}
}
settings = validation.applyOptionalParameters(contentOptions, settings);

// ensure request is setup
req = new request.Request(settings);
Expand Down
18 changes: 1 addition & 17 deletions lib/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,7 @@ module.exports = function (deviceOptions, ensureAuthHeaders, self) {
deviceOptions.secure;

// apply additional optional settings if supplied
if (!validation.isEmpty(deviceOptions)) {
if (!validation.isEmpty(deviceOptions.agent)) {
settings.agent = deviceOptions.agent;
}

if (!validation.isEmpty(deviceOptions.maxRetries)) {
settings.maxRetries = deviceOptions.maxRetries;
}

if (!validation.isEmpty(deviceOptions.port)) {
settings.port = deviceOptions.port;
}

if (!validation.isEmpty(deviceOptions.rejectUnauthorized)) {
settings.rejectUnauthorized = deviceOptions.rejectUnauthorized;
}
}
settings = validation.applyOptionalParameters(deviceOptions, settings);

// ensure request is setup
req = new request.Request(settings);
Expand Down
18 changes: 1 addition & 17 deletions lib/key.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,7 @@ module.exports = function (keyOptions, self) {
keyOptions.secure;

// apply additional optional settings if supplied
if (!validation.isEmpty(keyOptions)) {
if (!validation.isEmpty(keyOptions.agent)) {
settings.agent = keyOptions.agent;
}

if (!validation.isEmpty(keyOptions.maxRetries)) {
settings.maxRetries = keyOptions.maxRetries;
}

if (!validation.isEmpty(keyOptions.port)) {
settings.port = keyOptions.port;
}

if (!validation.isEmpty(keyOptions.rejectUnauthorized)) {
settings.rejectUnauthorized = keyOptions.rejectUnauthorized;
}
}
settings = validation.applyOptionalParameters(keyOptions, settings);

// ensure request is setup
req = new request.Request(settings);
Expand Down
18 changes: 1 addition & 17 deletions lib/music.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,7 @@ module.exports = function (musicOptions, ensureAuthHeaders, self) {
musicOptions.secure;

// apply additional optional settings if supplied
if (!validation.isEmpty(musicOptions)) {
if (!validation.isEmpty(musicOptions.agent)) {
settings.agent = musicOptions.agent;
}

if (!validation.isEmpty(musicOptions.maxRetries)) {
settings.maxRetries = musicOptions.maxRetries;
}

if (!validation.isEmpty(musicOptions.port)) {
settings.port = musicOptions.port;
}

if (!validation.isEmpty(musicOptions.rejectUnauthorized)) {
settings.rejectUnauthorized = musicOptions.rejectUnauthorized;
}
}
settings = validation.applyOptionalParameters(musicOptions, settings);

// ensure request is setup
req = new request.Request(settings);
Expand Down
18 changes: 1 addition & 17 deletions lib/playback.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,7 @@ module.exports = function (playbackOptions, ensureAuthHeaders, self) {
playbackOptions.secure;

// apply additional optional settings if supplied
if (!validation.isEmpty(playbackOptions)) {
if (!validation.isEmpty(playbackOptions.agent)) {
settings.agent = playbackOptions.agent;
}

if (!validation.isEmpty(playbackOptions.maxRetries)) {
settings.maxRetries = playbackOptions.maxRetries;
}

if (!validation.isEmpty(playbackOptions.port)) {
settings.port = playbackOptions.port;
}

if (!validation.isEmpty(playbackOptions.rejectUnauthorized)) {
settings.rejectUnauthorized = playbackOptions.rejectUnauthorized;
}
}
settings = validation.applyOptionalParameters(playbackOptions, settings);

// ensure request is setup
req = new request.Request(settings);
Expand Down
18 changes: 1 addition & 17 deletions lib/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,7 @@ module.exports = function (settingsOptions, ensureAuthHeaders, self) {
settingsOptions.secure;

// apply additional optional settings if supplied
if (!validation.isEmpty(settingsOptions)) {
if (!validation.isEmpty(settingsOptions.agent)) {
settings.agent = settingsOptions.agent;
}

if (!validation.isEmpty(settingsOptions.maxRetries)) {
settings.maxRetries = settingsOptions.maxRetries;
}

if (!validation.isEmpty(settingsOptions.port)) {
settings.port = settingsOptions.port;
}

if (!validation.isEmpty(settingsOptions.rejectUnauthorized)) {
settings.rejectUnauthorized = settingsOptions.rejectUnauthorized;
}
}
settings = validation.applyOptionalParameters(settingsOptions, settings);

// ensure request is setup
req = new request.Request(settings);
Expand Down
34 changes: 34 additions & 0 deletions lib/validation.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,40 @@
module.exports = (function (self) {
'use strict';

self.applyOptionalParameters = (inputOptions, outputOptions) => {
// ensure outputOptions are defined...
if (self.isEmpty(outputOptions)) {
outputOptions = {};
}

// apply additional optional settings if supplied
if (self.isEmpty(inputOptions)) {
return outputOptions;
}

if (!self.isEmpty(inputOptions.agent)) {
outputOptions.agent = inputOptions.agent;
}

if (!self.isEmpty(inputOptions.maxRetries) && !isNaN(inputOptions.maxRetries)) {
outputOptions.maxRetries = parseInt(inputOptions.maxRetries, 10);
}

if (!self.isEmpty(inputOptions.port) && !isNaN(inputOptions.port)) {
outputOptions.port = parseInt(inputOptions.port, 10);
}

if (!self.isEmpty(inputOptions.rejectUnauthorized)) {
outputOptions.rejectUnauthorized = inputOptions.rejectUnauthorized;
}

if (!self.isEmpty(inputOptions.timeout) && !isNaN(inputOptions.timeout)) {
outputOptions.timeout = parseInt(inputOptions.timeout, 10);
}

return outputOptions;
};

self.coalesce = function () {
return Array
.prototype
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.0.12",
"version": "1.0.13",
"contributors": [
{
"name": "Joshua Thomas",
Expand Down
72 changes: 72 additions & 0 deletions test/lib/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,78 @@ var
describe('validation', () => {
'use strict';

describe('#applyOptionalParameters', () => {
it('should properly return an empty object when input and output options are empty', () => {
Object.keys(validation.applyOptionalParameters()).length.should.equal(0);
});

it('should properly return the output object when input options are empty', () => {
validation.applyOptionalParameters(undefined, { test : true }).should.have.property('test');
validation.applyOptionalParameters(undefined, { test : true }).test.should.be.true;
});

it('should properly return a valid output object when output options are empty', () => {
var
inputOptions = {
agent : { proxy : true },
host : 'develop-test-api.apps.playnetwork.com',
maxRetries : 1,
port : 8080,
rejectUnauthorized : true,
secure : true,
timeout : 60000
},
outputOptions = validation.applyOptionalParameters(inputOptions);

outputOptions.should.have.property('agent');
outputOptions.agent.should.have.property('proxy');
outputOptions.should.have.property('maxRetries');
outputOptions.maxRetries.should.equal(1);
outputOptions.should.have.property('port');
outputOptions.port.should.equal(8080);
outputOptions.should.have.property('rejectUnauthorized');
outputOptions.rejectUnauthorized.should.equal(true);
outputOptions.should.have.property('timeout');
outputOptions.timeout.should.equal(60000);

should.not.exist(outputOptions.host);
should.not.exist(outputOptions.secure);
});

it('should properly augment an existing output object with input options', () => {
var
inputOptions = {
agent : { proxy : true },
host : 'develop-test-api.apps.playnetwork.com',
maxRetries : 1,
port : 8080,
rejectUnauthorized : true,
timeout : 60000
},
outputOptions = validation.applyOptionalParameters(
inputOptions,
{
host : 'develop-test-api.apps.playnetwork.com',
secure : true
});

outputOptions.should.have.property('agent');
outputOptions.agent.should.have.property('proxy');
outputOptions.should.have.property('host');
outputOptions.host.should.equal('develop-test-api.apps.playnetwork.com');
outputOptions.should.have.property('maxRetries');
outputOptions.maxRetries.should.equal(1);
outputOptions.should.have.property('port');
outputOptions.port.should.equal(8080);
outputOptions.should.have.property('rejectUnauthorized');
outputOptions.rejectUnauthorized.should.equal(true);
outputOptions.should.have.property('secure');
outputOptions.secure.should.equal(true);
outputOptions.should.have.property('timeout');
outputOptions.timeout.should.equal(60000);
});
});

describe('#coalesce', () => {
it('should properly return the first non-empty value', () => {
validation.coalesce(null, null, null, 'value').should.equal('value');
Expand Down

0 comments on commit 4c379d1

Please sign in to comment.