Comparing version 0.10.1 to 0.10.2
@@ -437,2 +437,138 @@ // | ||
/** | ||
* Creates or updates a installation. | ||
* | ||
* @param {string} installation The installation to create/update. | ||
* @param {object} [options] The request options or callback function. Additional properties will be passed as headers. | ||
* @param {Function(error, response)} callback `error` will contain information | ||
* if an error occurs; otherwise, `response` | ||
* will contain information related to this operation. | ||
*/ | ||
NotificationHubService.prototype.createOrUpdateInstallation = function (installation, optionsOrCallback, callback) { | ||
var options; | ||
azureutil.normalizeArgs(optionsOrCallback, callback, function (o, c) { options = o; callback = c; }); | ||
validateCallback(callback); | ||
if (!installation || !installation.installationId) { | ||
throw new Error('Invalid installation'); | ||
} | ||
var webResource = WebResource.put(this.hubName + '/installations/' + installation.installationId); | ||
var requestContent = JSON.stringify(installation); | ||
this.performRequest(webResource, requestContent, options, function (responseObject, next) { | ||
var finalCallback = function (returnObject) { | ||
callback(returnObject.error, returnObject.response); | ||
}; | ||
next(responseObject, finalCallback); | ||
}); | ||
}; | ||
/** | ||
* Patches an existing installation. | ||
* | ||
* @param {string} installationId Installation Id | ||
* @param {array} partialUpdateOperations List of partial operations to patch an existing installation | ||
* @param {object} [options] The request options or callback function. Additional properties will be passed as headers. | ||
* @param {Function(error, response)} callback `error` will contain information | ||
* if an error occurs; otherwise, `response` | ||
* will contain information related to this operation. | ||
*/ | ||
NotificationHubService.prototype.patchInstallation = function (installationId, partialUpdateOperations, optionsOrCallback, callback) { | ||
var options; | ||
azureutil.normalizeArgs(optionsOrCallback, callback, function (o, c) { options = o; callback = c; }); | ||
validateCallback(callback); | ||
if (!installationId) { | ||
throw new Error('Invalid installationId'); | ||
} | ||
if (!_.isArray(partialUpdateOperations)) { | ||
throw new Error('Invalid partialUpdateOperations'); | ||
} | ||
var webResource = WebResource.patch(this.hubName + '/installations/' + installationId); | ||
var requestContent = JSON.stringify(partialUpdateOperations); | ||
this.performRequest(webResource, requestContent, options, function (responseObject, next) { | ||
var finalCallback = function (returnObject) { | ||
callback(returnObject.error, returnObject.response); | ||
}; | ||
next(responseObject, finalCallback); | ||
}); | ||
}; | ||
/** | ||
* Deletes an existing installation. | ||
* | ||
* @param {string} installationId Installation Id | ||
* @param {object} [options] The request options or callback function. Additional properties will be passed as headers. | ||
* @param {Function(error, response)} callback `error` will contain information | ||
* if an error occurs; otherwise, `response` | ||
* will contain information related to this operation. | ||
*/ | ||
NotificationHubService.prototype.deleteInstallation = function (installationId, optionsOrCallback, callback) { | ||
var options; | ||
azureutil.normalizeArgs(optionsOrCallback, callback, function (o, c) { options = o; callback = c; }); | ||
validateCallback(callback); | ||
if (!installationId) { | ||
throw new Error('Invalid installationId'); | ||
} | ||
var webResource = WebResource.del(this.hubName + '/installations/' + installationId); | ||
this.performRequest(webResource, null, options, function (responseObject, next) { | ||
var finalCallback = function (returnObject) { | ||
callback(returnObject.error, returnObject.response); | ||
}; | ||
next(responseObject, finalCallback); | ||
}); | ||
}; | ||
/** | ||
* Gets an installation by its Id | ||
* | ||
* @param {string} installationId Installation Id | ||
* @param {object} [options] The request options or callback function. Additional properties will be passed as headers. | ||
* @param {Function(error, response)} callback `error` will contain information | ||
* if an error occurs; otherwise, `response` | ||
* will contain information related to this operation. | ||
*/ | ||
NotificationHubService.prototype.getInstallation = function (installationId, optionsOrCallback, callback) { | ||
var options; | ||
azureutil.normalizeArgs(optionsOrCallback, callback, function (o, c) { options = o; callback = c; }); | ||
validateCallback(callback); | ||
if (!installationId) { | ||
throw new Error('Invalid installationId'); | ||
} | ||
var webResource = WebResource.get(this.hubName + '/installations/' + installationId); | ||
webResource.rawResponse = true; | ||
this.performRequest(webResource, null, options, function (responseObject, next) { | ||
responseObject.installationResult = null; | ||
if (!responseObject.error && responseObject.response.body) { | ||
responseObject.installationResult = JSON.parse(responseObject.response.body); | ||
} | ||
// function to be called after all filters | ||
var finalCallback = function (returnObject) { | ||
callback(returnObject.error, returnObject.installationResult, returnObject.response); | ||
}; | ||
// call the first filter | ||
next(responseObject, finalCallback); | ||
}); | ||
}; | ||
NotificationHubService.prototype._joinTags = function (tags) { | ||
@@ -439,0 +575,0 @@ return tags.join(','); |
@@ -11,5 +11,6 @@ { | ||
"Rodrigues, Andre <andrerod@microsoft.com>", | ||
"Tavares, Chris <ctavares@microsoft.com>" | ||
"Tavares, Chris <ctavares@microsoft.com>", | ||
"Kulshrestha, Ankur <ankurkul@microsoft.com>" | ||
], | ||
"version": "0.10.1", | ||
"version": "0.10.2", | ||
"description": "Microsoft Azure Service Bus Service Library for node", | ||
@@ -35,3 +36,3 @@ "tags": [ | ||
"dependencies": { | ||
"azure-common": "^0.9.13", | ||
"azure-common": "^0.9.14", | ||
"underscore": "1.4.x", | ||
@@ -38,0 +39,0 @@ "wns": "~0.5.3", |
@@ -6,5 +6,3 @@ # Microsoft Azure SDK for Node.js - Gallery | ||
## Features | ||
## How to Install | ||
@@ -18,8 +16,65 @@ | ||
### Authentication | ||
```node | ||
var azure = require('azure'); | ||
### Create the ServiceBus service | ||
function checkForMessages(sbService, queueName, callback) { | ||
sbService.receiveQueueMessage(queueName, { isPeekLock: true }, function (err, lockedMessage) { | ||
if (err) { | ||
if (err == 'No messages to receive') { | ||
console.log('No messages'); | ||
} else { | ||
callback(err); | ||
} | ||
} else { | ||
callback(null, lockedMessage); | ||
} | ||
}); | ||
} | ||
function processMessage(sbService, err, lockedMsg) { | ||
if (err) { | ||
console.log('Error on Rx: ', err); | ||
} else { | ||
console.log('Rx: ', lockedMsg); | ||
sbService.deleteMessage(lockedMsg, function(err2) { | ||
if (err2) { | ||
console.log('Failed to delete message: ', err2); | ||
} else { | ||
console.log('Deleted message.'); | ||
} | ||
}) | ||
} | ||
} | ||
var idx = 0; | ||
function sendMessages(sbService, queueName) { | ||
var msg = 'Message # ' + (++idx); | ||
sbService.sendQueueMessage(queueName, msg, function (err) { | ||
if (err) { | ||
console.log('Failed Tx: ', err); | ||
} else { | ||
console.log('Sent ' + msg); | ||
} | ||
}); | ||
} | ||
var connStr = process.argv[2] || process.env.CONNECTION_STRING; | ||
if (!connStr) throw new Error('Must provide connection string'); | ||
var queueName = 'sbqtest'; | ||
console.log('Connecting to ' + connStr + ' queue ' + queueName); | ||
var sbService = azure.createServiceBusService(connStr); | ||
sbService.createQueueIfNotExists(queueName, function (err) { | ||
if (err) { | ||
console.log('Failed to create queue: ', err); | ||
} else { | ||
setInterval(checkForMessages.bind(null, sbService, queueName, processMessage.bind(null, sbService)), 5000); | ||
setInterval(sendMessages.bind(null, sbService, queueName), 15000); | ||
} | ||
}); | ||
``` | ||
Thanks to [@noodlefrenzy](https://github.com/noodlefrenzy) for the great example. The original is [here](https://github.com/noodlefrenzy/node-cerulean/blob/master/lib/index.js). | ||
## Related projects | ||
- [Microsoft Azure SDK for Node.js](https://github.com/WindowsAzure/azure-sdk-for-node) |
263100
4460
79
Updatedazure-common@^0.9.14