Skip to content

Commit

Permalink
add create* methods for constructing WNS payload from parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
tjanczuk committed Feb 16, 2013
1 parent 84882e5 commit c8ca5f8
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions lib/wns.js
Expand Up @@ -548,14 +548,9 @@ for (var item in templateSpecs) {
var imageCount = templateSpec[0];
var textCount = templateSpec[1];
var template = createTemplate(type, templateName, imageCount, textCount);

exports['send' + templateName] = function () {
// signature is (channel, [payload, ]*, [options], [callback])

var channel = Array.prototype.shift.apply(arguments);

if (typeof channel !== 'string')
throw new Error('The channel parameter must be the channel URI string.');
exports['create' + templateName] = function () {
// signature is ([payload, ]+, [options])

// determine notification template parameters

Expand Down Expand Up @@ -601,8 +596,7 @@ for (var item in templateSpecs) {
params.push(Array.prototype.shift.apply(arguments));
}

var options = typeof arguments[0] === 'object' ? Array.prototype.shift.apply(arguments) : {};
var callback = arguments[0];
var options = typeof arguments[0] === 'object' ? arguments[0] : {};

// validate required number of parameters was specified

Expand All @@ -627,9 +621,30 @@ for (var item in templateSpecs) {

xmlEscapedParams[1] = createToastAttributes(type, options);

var payload = util.format.apply(this, xmlEscapedParams);
return util.format.apply(this, xmlEscapedParams);
};

exports['send' + templateName] = function () {
// signature is (channel, [payload, ]+, [options], [callback])

// send notification
var channel = Array.prototype.shift.apply(arguments);

if (typeof channel !== 'string')
throw new Error('The channel parameter must be the channel URI string.');

var payload = exports['create' + templateName].apply(this, arguments);
var argNum = 0;
if (typeof arguments[0] === 'object') {
argNum++;
}
else {
while (typeof arguments[argNum] === 'string') {
argNum++;
}
}

var options = arguments[argNum];
var callback = arguments[argNum + 1];

return exports.send(channel, payload, 'wns/' + type, options, callback);
};
Expand Down

0 comments on commit c8ca5f8

Please sign in to comment.