Notification hubs updates
This commit is contained in:
Родитель
c1a49bde56
Коммит
aa05b3346f
|
@ -20,9 +20,14 @@ test-result.xml
|
|||
# Windows #
|
||||
Thumbs.db
|
||||
|
||||
# Credentials #
|
||||
*.cer
|
||||
*.pfx
|
||||
*.pem
|
||||
|
||||
# WebStorm #
|
||||
.idea/
|
||||
|
||||
# docs #
|
||||
docs/
|
||||
jsdoc/
|
||||
jsdoc/
|
|
@ -200,6 +200,7 @@ ServiceClient.prototype._performRequest = function (webResource, body, options,
|
|||
self.logger.log(Logger.LogLevels.DEBUG, 'REQUEST OPTIONS:\n' + util.inspect(requestOptions));
|
||||
|
||||
var operation = function (finalRequestOptions, next) {
|
||||
console.log(finalRequestOptions);
|
||||
self.logger.log(Logger.LogLevels.DEBUG, 'FINAL REQUEST OPTIONS:\n' + util.inspect(finalRequestOptions));
|
||||
|
||||
var processResponseCallback = function (error, response, body, cb) {
|
||||
|
@ -337,14 +338,16 @@ ServiceClient.prototype._performRequest = function (webResource, body, options,
|
|||
ServiceClient.prototype._buildRequestOptions = function (webResource, body, options, callback) {
|
||||
var self = this;
|
||||
|
||||
if (!webResource.headers || !webResource.headers[HeaderConstants.CONTENT_TYPE]) {
|
||||
if (!webResource.headers || webResource.headers[HeaderConstants.CONTENT_TYPE] === undefined) {
|
||||
webResource.withHeader(HeaderConstants.CONTENT_TYPE, '');
|
||||
} else if (webResource.headers && webResource.headers[HeaderConstants.CONTENT_TYPE] === null) {
|
||||
delete webResource.headers[HeaderConstants.CONTENT_TYPE];
|
||||
}
|
||||
|
||||
if (!webResource.headers || webResource.headers[HeaderConstants.CONTENT_LENGTH] === undefined) {
|
||||
if (body && body.outputData) {
|
||||
webResource.withHeader(HeaderConstants.CONTENT_LENGTH, Buffer.byteLength(body.outputData, 'UTF8'));
|
||||
} else {
|
||||
} else if (webResource.headers[HeaderConstants.CONTENT_LENGTH] === undefined) {
|
||||
webResource.withHeader(HeaderConstants.CONTENT_LENGTH, 0);
|
||||
}
|
||||
} else if (webResource.headers && webResource.headers[HeaderConstants.CONTENT_LENGTH] === null) {
|
||||
|
|
|
@ -370,7 +370,7 @@ ScmService.prototype.getLogStream = function (path, optionsOrCallback, chunkCall
|
|||
}
|
||||
|
||||
if (options.filter) {
|
||||
webResource.withOption('filter', options.filter);
|
||||
webResource.withQueryOption('filter', options.filter);
|
||||
}
|
||||
|
||||
this.performChunkedRequest(webResource, null, null, function (responseObject, next) {
|
||||
|
|
|
@ -80,7 +80,7 @@ ApnsService.prototype.send = function (tags, payload, callback) {
|
|||
headers[HeaderConstants.SERVICE_BUS_NOTIFICATION_FORMAT] = 'apple';
|
||||
if (tags) {
|
||||
if (_.isArray(tags)) {
|
||||
tags = tags.join(',');
|
||||
tags = this.notificationHubService._joinTags(tags);
|
||||
}
|
||||
|
||||
headers[HeaderConstants.SERVICE_BUS_NOTIFICATION_TAGS] = tags;
|
||||
|
@ -260,7 +260,7 @@ ApnsService.prototype._createBody = function (elementName, token, tags, template
|
|||
|
||||
if (tags) {
|
||||
if (_.isArray(tags)) {
|
||||
tags = tags.join(',');
|
||||
tags = this.notificationHubService._joinTags(tags);
|
||||
}
|
||||
|
||||
registration.Tags = tags;
|
||||
|
|
|
@ -63,7 +63,7 @@ GcmService.prototype.send = function (tags, payload, callback) {
|
|||
headers[HeaderConstants.SERVICE_BUS_NOTIFICATION_FORMAT] = 'gcm';
|
||||
if (tags) {
|
||||
if (_.isArray(tags)) {
|
||||
tags = tags.join(',');
|
||||
tags = this.notificationHubService._joinTags(tags);
|
||||
}
|
||||
|
||||
headers[HeaderConstants.SERVICE_BUS_NOTIFICATION_TAGS] = tags;
|
||||
|
@ -222,7 +222,7 @@ GcmService.prototype._createBody = function (elementName, gcmRegistrationId, tag
|
|||
|
||||
if (tags) {
|
||||
if (_.isArray(tags)) {
|
||||
tags = tags.join(',');
|
||||
tags = this.notificationHubService._joinTags(tags);
|
||||
}
|
||||
|
||||
registration.Tags = tags;
|
||||
|
|
|
@ -151,6 +151,29 @@ function MpnsService(notificationHubService) {
|
|||
|
||||
self.notificationHubService._executeRequest(webResource, registrationXml, registrationResult, null, callback);
|
||||
};
|
||||
|
||||
var createOrUpdateRegistrationName = util.format('createOrUpdate%sRegistration', templateName);
|
||||
self[createOrUpdateRegistrationName] = function () {
|
||||
var registrationId = Array.prototype.shift.apply(arguments);
|
||||
var callback = arguments[arguments.length - 1];
|
||||
|
||||
if (!_.isFunction(callback)) {
|
||||
throw new Error('The callback parameter must be the callback function.');
|
||||
}
|
||||
|
||||
var options = {};
|
||||
if (arguments.length >= 3 && _.isObject(arguments[arguments.length - 2])) {
|
||||
options = arguments[arguments.length - 2];
|
||||
}
|
||||
|
||||
var registrationXml = createRegistrationXml(arguments);
|
||||
|
||||
var webResource = WebResource.put(self.notificationHubService.hubName + '/registrations/' + registrationId)
|
||||
.withHeader(HeaderConstants.CONTENT_TYPE, 'application/atom+xml;type=entry;charset=utf-8')
|
||||
.withHeader(HeaderConstants.CONTENT_LENGTH, Buffer.byteLength(registrationXml, 'utf8'));
|
||||
|
||||
self.notificationHubService._executeRequest(webResource, registrationXml, registrationResult, null, callback);
|
||||
};
|
||||
};
|
||||
|
||||
templateSpecs.forEach(function (templateName) {
|
||||
|
@ -316,7 +339,7 @@ MpnsService.prototype.send = function (tags, payload, targetName, notificationCl
|
|||
|
||||
if (tags) {
|
||||
if (_.isArray(tags)) {
|
||||
tags = tags.join(',');
|
||||
tags = this.notificationHubService._joinTags(tags);
|
||||
}
|
||||
|
||||
headers[HeaderConstants.SERVICE_BUS_NOTIFICATION_TAGS] = tags;
|
||||
|
@ -357,7 +380,7 @@ MpnsService.prototype._createBody = function (elementName, channel, tags, templa
|
|||
|
||||
if (tags) {
|
||||
if (_.isArray(tags)) {
|
||||
tags = tags.join(',');
|
||||
tags = this.notificationHubService._joinTags(tags);
|
||||
}
|
||||
|
||||
registration.Tags = tags;
|
||||
|
|
|
@ -148,7 +148,7 @@ NotificationHubService.prototype.send = function (tags, payload, optionsOrCallba
|
|||
|
||||
if (tags) {
|
||||
if (_.isArray(tags)) {
|
||||
tags = tags.join(',');
|
||||
tags = this.notificationHubService._joinTags(tags);
|
||||
}
|
||||
|
||||
headers[HeaderConstants.SERVICE_BUS_NOTIFICATION_TAGS] = tags;
|
||||
|
@ -169,6 +169,26 @@ NotificationHubService.prototype.send = function (tags, payload, optionsOrCallba
|
|||
this._sendNotification(payload, headers, callback);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a registration identifier.
|
||||
*
|
||||
* @param {Function(error, response)} callback `error` will contain information
|
||||
* if an error occurs; otherwise, `response`
|
||||
* will contain information related to this operation.
|
||||
*/
|
||||
NotificationHubService.prototype.createRegistrationId = function (callback) {
|
||||
validateCallback(callback);
|
||||
|
||||
var webResource = WebResource.post(this.hubName + '/registrationids');
|
||||
webResource.headers = {
|
||||
'content-length': null,
|
||||
'content-type': null
|
||||
};
|
||||
|
||||
this._executeRequest(webResource, null, null, null, callback);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves a registration.
|
||||
*
|
||||
|
@ -256,6 +276,39 @@ NotificationHubService.prototype.updateRegistration = function (registration, op
|
|||
this._executeRequest(webResource, registrationXml, registrationResult, null, callback);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates or updates a registration.
|
||||
*
|
||||
* @param {string} registration The registration to update.
|
||||
* @param {object} [options] The request options or callback function. Additional properties will be passed as headers.
|
||||
* @param {object} [options.etag] The etag.
|
||||
* @param {Function(error, response)} callback `error` will contain information
|
||||
* if an error occurs; otherwise, `response`
|
||||
* will contain information related to this operation.
|
||||
*/
|
||||
NotificationHubService.prototype.createOrUpdateRegistration = function (registration, optionsOrCallback, callback) {
|
||||
var options;
|
||||
azureutil.normalizeArgs(optionsOrCallback, callback, function (o, c) { options = o; callback = c; });
|
||||
|
||||
validateCallback(callback);
|
||||
|
||||
if (!registration || !registration.RegistrationId) {
|
||||
throw new Error('Invalid registration');
|
||||
}
|
||||
|
||||
var webResource = WebResource.put(this.hubName + '/registrations/' + registration.RegistrationId);
|
||||
|
||||
registration = _.clone(registration);
|
||||
var registrationType = registration[Constants.ATOM_METADATA_MARKER]['ContentRootElement'];
|
||||
delete registration[Constants.ATOM_METADATA_MARKER];
|
||||
delete registration.ExpirationTime;
|
||||
delete registration.Expiry;
|
||||
delete registration.TemplateName;
|
||||
|
||||
var registrationXml = registrationResult.serialize(registrationType, registration);
|
||||
this._executeRequest(webResource, registrationXml, registrationResult, null, callback);
|
||||
};
|
||||
|
||||
/**
|
||||
* List registrations.
|
||||
*
|
||||
|
@ -351,4 +404,8 @@ NotificationHubService.prototype._sendNotification = function (payload, optionsO
|
|||
this._executeRequest(webResource, payload, null, null, callback);
|
||||
};
|
||||
|
||||
NotificationHubService.prototype._joinTags = function (tags) {
|
||||
return tags.join(' && ');
|
||||
};
|
||||
|
||||
module.exports = NotificationHubService;
|
|
@ -206,6 +206,29 @@ function WnsService(notificationHubService) {
|
|||
|
||||
self.notificationHubService._executeRequest(webResource, registrationXml, registrationResult, null, callback);
|
||||
};
|
||||
|
||||
var createOrUpdateRegistrationName = util.format('createOrUpdate%sRegistration', templateName);
|
||||
self[createOrUpdateRegistrationName] = function () {
|
||||
var registrationId = Array.prototype.shift.apply(arguments);
|
||||
var callback = arguments[arguments.length - 1];
|
||||
|
||||
if (!_.isFunction(callback)) {
|
||||
throw new Error('The callback parameter must be the callback function.');
|
||||
}
|
||||
|
||||
var options = {};
|
||||
if (arguments.length >= 3 && _.isObject(arguments[arguments.length - 2])) {
|
||||
options = arguments[arguments.length - 2];
|
||||
}
|
||||
|
||||
var registrationXml = createRegistrationXml(arguments);
|
||||
|
||||
var webResource = WebResource.put(self.notificationHubService.hubName + '/registrations/' + registrationId)
|
||||
.withHeader(HeaderConstants.CONTENT_TYPE, 'application/atom+xml;type=entry;charset=utf-8')
|
||||
.withHeader(HeaderConstants.CONTENT_LENGTH, Buffer.byteLength(registrationXml, 'utf8'));
|
||||
|
||||
self.notificationHubService._executeRequest(webResource, registrationXml, registrationResult, null, callback);
|
||||
};
|
||||
};
|
||||
|
||||
Object.keys(templateSpecs).forEach(function (templateName) {
|
||||
|
@ -314,7 +337,7 @@ WnsService.prototype.send = function (tags, payload, type, optionsOrCallback, ca
|
|||
|
||||
if (tags) {
|
||||
if (_.isArray(tags)) {
|
||||
tags = tags.join(',');
|
||||
tags = this.notificationHubService._joinTags(tags);
|
||||
}
|
||||
|
||||
headers[HeaderConstants.SERVICE_BUS_NOTIFICATION_TAGS] = tags;
|
||||
|
@ -485,7 +508,7 @@ WnsService.prototype._createBody = function (elementName, channel, tags, templat
|
|||
|
||||
if (tags) {
|
||||
if (_.isArray(tags)) {
|
||||
tags = tags.join(',');
|
||||
tags = this.notificationHubService._joinTags(tags);
|
||||
}
|
||||
|
||||
registration.Tags = tags;
|
||||
|
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -315,6 +315,36 @@ describe('Notification hubs', function () {
|
|||
});
|
||||
});
|
||||
|
||||
describe('create registration identifier', function () {
|
||||
var hubName;
|
||||
var notificationHubService;
|
||||
|
||||
beforeEach(function (done) {
|
||||
hubName = testutil.generateId(hubNamePrefix, hubNames, suiteUtil.isMocked);
|
||||
|
||||
notificationHubService = azure.createNotificationHubService(hubName);
|
||||
|
||||
suiteUtil.setupService(notificationHubService);
|
||||
service.createNotificationHub(hubName, function () {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should work', function (done) {
|
||||
service.getNotificationHub(hubName, function (err, hub) {
|
||||
console.log(err);
|
||||
console.log(hub);
|
||||
|
||||
notificationHubService.createRegistrationId(function (err, rsp) {
|
||||
should.not.exist(err);
|
||||
console.log(rsp);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('update registration', function () {
|
||||
var hubName;
|
||||
var notificationHubService;
|
||||
|
|
|
@ -1,67 +1,67 @@
|
|||
common/credentials/token-tests.js
|
||||
common/filters/exponentialretrypolicyfilter-tests.js
|
||||
common/filters/linearretrypolicyfilter-tests.js
|
||||
common/filters/proxyfilter-tests.js
|
||||
common/connectionstringparser-tests.js
|
||||
common/serviceclient-tests.js
|
||||
common/hmacsha256sign-tests.js
|
||||
common/servicesettings-tests.js
|
||||
common/servicebussettings-tests.js
|
||||
common/servicemanagementsettings-tests.js
|
||||
common/storageservicesettings-tests.js
|
||||
serviceruntime/roleenvironment-tests.js
|
||||
serviceruntime/runtimeversionmanager-tests.js
|
||||
serviceruntime/runtimeversionprotocolclient-tests.js
|
||||
services/blob/internal/sharedaccesssignature-tests.js
|
||||
services/blob/internal/sharedkey-tests.js
|
||||
services/blob/internal/sharedkeylite-tests.js
|
||||
services/blob/blobservice-tests.js
|
||||
services/blob/blobservice-stream-tests.js
|
||||
services/blob/blobservice-gb-tests.js
|
||||
services/blob/blobservice-uploaddownload-tests.js
|
||||
services/blob/models/blobpagerangestream-test.js
|
||||
services/blob/filters-tests.js
|
||||
services/queue/queueservice-tests.js
|
||||
services/scm/scmservice-tests.js
|
||||
services/serviceBus/internal/wraptokenmanager-tests.js
|
||||
services/serviceBus/apnsservice-tests.js
|
||||
services/serviceBus/apnsservice-registrations-tests.js
|
||||
services/serviceBus/gcmservice-tests.js
|
||||
services/serviceBus/gcmservice-registrations-tests.js
|
||||
services/serviceBus/servicebusservice-tests.js
|
||||
services/serviceBus/mpnsservice-tests.js
|
||||
services/serviceBus/mpnsservice-registrations-tests.js
|
||||
# common/credentials/token-tests.js
|
||||
# common/filters/exponentialretrypolicyfilter-tests.js
|
||||
# common/filters/linearretrypolicyfilter-tests.js
|
||||
# common/filters/proxyfilter-tests.js
|
||||
# common/connectionstringparser-tests.js
|
||||
# common/serviceclient-tests.js
|
||||
# common/hmacsha256sign-tests.js
|
||||
# common/servicesettings-tests.js
|
||||
# common/servicebussettings-tests.js
|
||||
# common/servicemanagementsettings-tests.js
|
||||
# common/storageservicesettings-tests.js
|
||||
# serviceruntime/roleenvironment-tests.js
|
||||
# serviceruntime/runtimeversionmanager-tests.js
|
||||
# serviceruntime/runtimeversionprotocolclient-tests.js
|
||||
# services/blob/internal/sharedaccesssignature-tests.js
|
||||
# services/blob/internal/sharedkey-tests.js
|
||||
# services/blob/internal/sharedkeylite-tests.js
|
||||
# services/blob/blobservice-tests.js
|
||||
# services/blob/blobservice-stream-tests.js
|
||||
# services/blob/blobservice-gb-tests.js
|
||||
# services/blob/blobservice-uploaddownload-tests.js
|
||||
# services/blob/models/blobpagerangestream-test.js
|
||||
# services/blob/filters-tests.js
|
||||
# services/queue/queueservice-tests.js
|
||||
# services/scm/scmservice-tests.js
|
||||
# services/serviceBus/internal/wraptokenmanager-tests.js
|
||||
# services/serviceBus/apnsservice-tests.js
|
||||
# services/serviceBus/apnsservice-registrations-tests.js
|
||||
# services/serviceBus/gcmservice-tests.js
|
||||
# services/serviceBus/gcmservice-registrations-tests.js
|
||||
# services/serviceBus/servicebusservice-tests.js
|
||||
# services/serviceBus/mpnsservice-tests.js
|
||||
# services/serviceBus/mpnsservice-registrations-tests.js
|
||||
services/serviceBus/notificationhubs-tests.js
|
||||
services/serviceBus/wnsservice-tests.js
|
||||
services/serviceBus/wnsservice-registrations-tests.js
|
||||
services/serviceBus/wrapservice-tests.js
|
||||
services/management/affinitygroup-tests.js
|
||||
services/management/servicemanagementservice-tests.js
|
||||
services/serviceBus/servicebusmanagementservice-tests.js
|
||||
services/sql/sqlmanagementservice-tests.js
|
||||
services/sql/sqlservice-tests.js
|
||||
services/table/internal/sharedkeytable-tests.js
|
||||
services/table/internal/sharedkeylitetable-tests.js
|
||||
services/table/batchserviceclient-tests.js
|
||||
services/table/tabledatatype-tests.js
|
||||
services/table/tablequery-tests.js
|
||||
services/table/tableservice-batch-tests.js
|
||||
services/table/tableservice-tablequery-tests.js
|
||||
services/table/tableservice-tests.js
|
||||
# TODO: find out why it's broken
|
||||
# services/table/tableservice-gb-tests.js
|
||||
services/webSite/websitemanagementservice-tests.js
|
||||
util/date-tests.js
|
||||
util/edmtype-tests.js
|
||||
util/iso8061date-tests.js
|
||||
util/js2xml-tests.js
|
||||
util/odatahandler-tests.js
|
||||
util/util-tests.js
|
||||
util/validate-tests.js
|
||||
azure-tests.js
|
||||
services/HDInsight/hdinsight-listClusters-unit-tests.js
|
||||
services/HDInsight/hdinsight-createCluster-unit-tests.js
|
||||
services/HDInsight/hdinsight-deleteCluster-unit-tests.js
|
||||
services/HDInsight/namespace-tests.js
|
||||
# services/serviceBus/wnsservice-tests.js
|
||||
# services/serviceBus/wnsservice-registrations-tests.js
|
||||
# services/serviceBus/wrapservice-tests.js
|
||||
# services/management/affinitygroup-tests.js
|
||||
# services/management/servicemanagementservice-tests.js
|
||||
# services/serviceBus/servicebusmanagementservice-tests.js
|
||||
# services/sql/sqlmanagementservice-tests.js
|
||||
# services/sql/sqlservice-tests.js
|
||||
# services/table/internal/sharedkeytable-tests.js
|
||||
# services/table/internal/sharedkeylitetable-tests.js
|
||||
# services/table/batchserviceclient-tests.js
|
||||
# services/table/tabledatatype-tests.js
|
||||
# services/table/tablequery-tests.js
|
||||
# services/table/tableservice-batch-tests.js
|
||||
# services/table/tableservice-tablequery-tests.js
|
||||
# services/table/tableservice-tests.js
|
||||
# # TODO: find out why it's broken
|
||||
# # services/table/tableservice-gb-tests.js
|
||||
# services/webSite/websitemanagementservice-tests.js
|
||||
# util/date-tests.js
|
||||
# util/edmtype-tests.js
|
||||
# util/iso8061date-tests.js
|
||||
# util/js2xml-tests.js
|
||||
# util/odatahandler-tests.js
|
||||
# util/util-tests.js
|
||||
# util/validate-tests.js
|
||||
# azure-tests.js
|
||||
# services/HDInsight/hdinsight-listClusters-unit-tests.js
|
||||
# services/HDInsight/hdinsight-createCluster-unit-tests.js
|
||||
# services/HDInsight/hdinsight-deleteCluster-unit-tests.js
|
||||
# services/HDInsight/namespace-tests.js
|
||||
# These tests are waiting for the CI system to get the proper setup.
|
||||
# services/HDInsight/hdinsight-tests.js
|
||||
|
|
Загрузка…
Ссылка в новой задаче