This commit is contained in:
Andre Rodrigues 2013-04-12 17:50:06 +01:00
Родитель d1b0bc2765
Коммит a1e95061fb
6 изменённых файлов: 31 добавлений и 38 удалений

Просмотреть файл

@ -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 + '\'');

Просмотреть файл

@ -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 = {};

Просмотреть файл

@ -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) + '\'');

Просмотреть файл

@ -78,7 +78,7 @@ function _writeElementValue(parentElement, name, value) {
} else {
parentElement = parentElement.ele(propertyTagName);
if (!azureutil.stringIsEmpty(value)) {
if (azureutil.stringStartsWith(value.toString(), '<![CDATA[')) {
if (azureutil.stringStartsWith(value.toString().trim(), '<![CDATA[')) {
parentElement = parentElement.raw(value.toString());
} else {
parentElement = parentElement.txt(value.toString());

Просмотреть файл

@ -13,6 +13,7 @@
* limitations under the License.
*/
var _ = require('underscore');
var check = require('validator').check;
exports = module.exports;
@ -47,4 +48,16 @@ exports.isBase64Encoded = function (key) {
} else {
throw new Error('The provided account key ' + key + ' is not a valid base64 string.');
}
};
/**
* Validates a function.
*
* @param {object} function The function to validate.
* @return {function}
*/
exports.isValidFunction = function (functionObject, functionName) {
if (!functionObject || !_.isFunction(functionObject)) {
throw new Error(functionName + ' must be specified.');
}
};

Просмотреть файл

@ -26,6 +26,8 @@ var azure = testutil.libRequire('azure');
var HeaderConstants = azure.Constants.HeaderConstants;
var tokenId = '0f744707bebcf74f9b7c25d48e3358945f6aa01da5ddb387462c7eaf61bbad78';
var hubNames = [];
var hubNamePrefix = 'xplathubnxt';
@ -101,7 +103,7 @@ describe('APNS notifications registrations', function () {
});
it('should work', function (done) {
notificationHubService.apns.createNativeRegistration('0f744707bebcf74f9b7c25d48e3358945f6aa01da5ddb387462c7eaf61bbad78', function (error, registration) {
notificationHubService.apns.createNativeRegistration(tokenId, function (error, registration) {
should.not.exist(error);
registrationId = registration.RegistrationId;
@ -121,7 +123,7 @@ describe('APNS notifications registrations', function () {
it('should work', function (done) {
notificationHubService.apns.createTemplateRegistration(
'0f744707bebcf74f9b7c25d48e3358945f6aa01da5ddb387462c7eaf61bbad78',
tokenId,
{
alert: '${alertMessage1}'
},
@ -139,7 +141,7 @@ describe('APNS notifications registrations', function () {
beforeEach(function (done) {
notificationHubService.apns.createTemplateRegistration(
'0f744707bebcf74f9b7c25d48e3358945f6aa01da5ddb387462c7eaf61bbad78',
tokenId,
{
alert: '${alertMessage1}'
},
@ -158,7 +160,7 @@ describe('APNS notifications registrations', function () {
it('should work', function (done) {
notificationHubService.apns.updateTemplateRegistration(
registrationId,
'0f744707bebcf74f9b7c25d48e3358945f6aa01da5ddb387462c7eaf61bbad78',
tokenId,
{
alert: '${newAlertMessage1}'
},