diff --git a/lib/services/serviceBus/apnsservice.js b/lib/services/serviceBus/apnsservice.js index 867b64460..b0b2ce9e0 100644 --- a/lib/services/serviceBus/apnsservice.js +++ b/lib/services/serviceBus/apnsservice.js @@ -17,6 +17,7 @@ var _ = require('underscore'); var azureutil = require('../../util/util'); var Constants = require('../../util/constants'); +var validate = require('../../util/validate'); var HttpConstants = Constants.HttpConstants; var HeaderConstants = Constants.HeaderConstants; @@ -35,18 +36,6 @@ function ApnsService(notificationHubService) { this.notificationHubService = notificationHubService; } -/** -* Validates a callback function. -* -* @param (function) callback The callback function. -* @return {undefined} -*/ -function validateCallback(callback) { - if (!callback) { - throw new Error('Callback must be specified.'); - } -} - /** * Sends an APNS notification. * @@ -105,7 +94,7 @@ ApnsService.prototype.createNativeRegistration = function (token, optionsOrCallb var options; azureutil.normalizeArgs(optionsOrCallback, callback, function (o, c) { options = o; callback = c; }); - validateCallback(callback); + validate.isValidFunction(callback); var registrationXml = registrationResult.serialize('AppleRegistrationDescription', { DeviceToken: token @@ -135,7 +124,7 @@ ApnsService.prototype.createTemplateRegistration = function (token, template, op var options; azureutil.normalizeArgs(optionsOrCallback, callback, function (o, c) { options = o; callback = c; }); - validateCallback(callback); + validate.isValidFunction(callback); if (!_.isString(template) && !_.isObject(template)) { throw new Error('The payload parameter must be the notification payload string or object.'); @@ -183,7 +172,7 @@ ApnsService.prototype.updateTemplateRegistration = function (registrationId, tok var options; azureutil.normalizeArgs(optionsOrCallback, callback, function (o, c) { options = o; callback = c; }); - validateCallback(callback); + validate.isValidFunction(callback); if (!_.isString(template) && !_.isObject(template)) { throw new Error('The payload parameter must be the notification payload string or object.'); @@ -232,7 +221,7 @@ ApnsService.prototype.getRegistrationsByToken = function (token, optionsOrCallba var options; azureutil.normalizeArgs(optionsOrCallback, callback, function (o, c) { options = o; callback = c; }); - validateCallback(callback); + validate.isValidFunction(callback); var webResource = WebResource.get(this.hubName + '/registrations/') .addOptionalQueryParam('$filter', 'deviceToken eq \'' + token + '\''); diff --git a/lib/services/serviceBus/notificationhubservice.js b/lib/services/serviceBus/notificationhubservice.js index 7bf762e5f..1a8797794 100644 --- a/lib/services/serviceBus/notificationhubservice.js +++ b/lib/services/serviceBus/notificationhubservice.js @@ -108,7 +108,7 @@ NotificationHubService.prototype.send = function (tags, payload, optionsOrCallba } if (!_.isFunction(callback)) { - throw new Error('The callback parameter must be the callback function.'); + throw new Error('The callback parameter must be a function.'); } var headers = {}; diff --git a/lib/services/serviceBus/wnsservice.js b/lib/services/serviceBus/wnsservice.js index 6fb5fbb3f..35a6de74b 100644 --- a/lib/services/serviceBus/wnsservice.js +++ b/lib/services/serviceBus/wnsservice.js @@ -20,6 +20,7 @@ var wns = require('wns'); var azureutil = require('../../util/util'); var Constants = require('../../util/constants'); +var validate = require('../../util/validate'); var HttpConstants = Constants.HttpConstants; var HeaderConstants = Constants.HeaderConstants; @@ -258,18 +259,6 @@ function WnsService(notificationHubService) { }); } -/** -* Validates a callback function. -* -* @param (function) callback The callback function. -* @return {undefined} -*/ -function validateCallback(callback) { - if (!callback) { - throw new Error('Callback must be specified.'); - } -} - /** * Sends a wns/badge WNS notification. * @@ -393,7 +382,7 @@ WnsService.prototype.createNativeRegistration = function (channel, optionsOrCall var options; azureutil.normalizeArgs(optionsOrCallback, callback, function (o, c) { options = o; callback = c; }); - validateCallback(callback); + validate.isValidFunction(callback); var registrationXml = registrationResult.serialize('WindowsRegistrationDescription', { ChannelUri: channel @@ -422,7 +411,7 @@ WnsService.prototype.createRawTemplateRegistration = function (channel, template var options; azureutil.normalizeArgs(optionsOrCallback, callback, function (o, c) { options = o; callback = c; }); - validateCallback(callback); + validate.isValidFunction(callback); var registrationXml = this._createRawTemplateBody(channel, template, options); @@ -450,7 +439,7 @@ WnsService.prototype.updatesRawTemplateRegistration = function (channel, templat var options; azureutil.normalizeArgs(optionsOrCallback, callback, function (o, c) { options = o; callback = c; }); - validateCallback(callback); + validate.isValidFunction(callback); var registrationXml = this._createRawTemplateBody(channel, template, options); @@ -482,7 +471,7 @@ WnsService.prototype.getRegistrationsByChannel = function (channel, optionsOrCal var options; azureutil.normalizeArgs(optionsOrCallback, callback, function (o, c) { options = o; callback = c; }); - validateCallback(callback); + validate.isValidFunction(callback); var webResource = WebResource.get(this.hubName + '/registrations/') .addOptionalQueryParam('$filter', 'ChannelUri eq \'' + encodeURIComponent(channel) + '\''); diff --git a/lib/util/js2xml.js b/lib/util/js2xml.js index 507993694..364a8f4d7 100644 --- a/lib/util/js2xml.js +++ b/lib/util/js2xml.js @@ -78,7 +78,7 @@ function _writeElementValue(parentElement, name, value) { } else { parentElement = parentElement.ele(propertyTagName); if (!azureutil.stringIsEmpty(value)) { - if (azureutil.stringStartsWith(value.toString(), '