sns-q.js
function messageBuilder(msg, args) {
    var message = msg,
        supported = [],
        badge = 0,
        builders = {};

    //** currently only APNS is supported
    builders[platforms.APNS] = builders[platforms.APNSSandbox] = function() {
        return {
            aps: { 
                //** adds the custom arguments onto the "alert" object
                alert: _.extend({}, { body: msg }, args||{}),
                badge: badge
            }
        };
    }

    //** sets the supported platforms
    this.platforms = function(list) {
        if(!Array.isArray(list)) return;
        supported = list;
        return this;
    }

    //** shows/clears badges for the app icon
    this.showBadge = function(count) {
        badge = count;
        return this;
    }
    this.clearBadge = function() {
        badge = 0;
        return this;
    }

    this.toJSON = function() {
        //** create the composite message object based on the supported platforms
        return _.reduce(supported, function(m, platform) {
            if(!!builders[platform])
                m[platform] = JSON.stringify(builders[platform]());

            return m;
        }, 

        //** support the default message inherently; this is required for publishing to topics
        { default: msg });
    }

    this.stringify = function() { return JSON.stringify(this.toJSON()); }

    return this;
}
function messageBuilder(msg, args) {
    var message = msg,
        supported = [],
        badge = 0,
        builders = {};

    //** currently only APNS is supported
    builders[platforms.APNS] = builders[platforms.APNSSandbox] = function() {
        return {
            aps: { 
                //** adds the custom arguments onto the "alert" object
                alert: _.extend({}, { body: msg }, args||{}),
                badge: badge
            }
        };
    }

    //** sets the supported platforms
    this.platforms = function(list) {
        if(!Array.isArray(list)) return;
        supported = list;
        return this;
    }

    //** shows/clears badges for the app icon
    this.showBadge = function(count) {
        badge = count;
        return this;
    }
    this.clearBadge = function() {
        badge = 0;
        return this;
    }

    this.toJSON = function() {
        //** create the composite message object based on the supported platforms
        return _.reduce(supported, function(m, platform) {
            if(!!builders[platform])
                m[platform] = JSON.stringify(builders[platform]());

            return m;
        }, 

        //** support the default message inherently; this is required for publishing to topics
        { default: msg });
    }

    this.stringify = function() { return JSON.stringify(this.toJSON()); }

    return this;
}
function messageBuilder ( msg , args ) { var message = msg , supported = [ ] , badge = 0 , builders = { } ; //** currently only APNS is supported builders [ platforms . APNS ] = builders [ platforms . APNSSandbox ] = function ( ) { return { aps : { //** adds the custom arguments onto the "alert" object alert : _ . extend ( { } , { body : msg } , args || { } ) , badge : badge } } ; } //** sets the supported platforms this . platforms = function ( list ) { if ( ! Array . isArray ( list ) ) return ; supported = list ; return this ; } //** shows/clears badges for the app icon this . showBadge = function ( count ) { badge = count ; return this ; } this . clearBadge = function ( ) { badge = 0 ; return this ; } this . toJSON = function ( ) { //** create the composite message object based on the supported platforms return _ . reduce ( supported , function ( m , platform ) { if ( ! ! builders [ platform ] ) m [ platform ] = JSON . stringify ( builders [ platform ] ( ) ) ; return m ; } , //** support the default message inherently; this is required for publishing to topics { default : msg } ) ; } this . stringify = function ( ) { return JSON . stringify ( this . toJSON ( ) ) ; } return this ; }
a message builder to abstract the individual format for each platform; supports a message, badges, and custom payloads

@param {String} msg the message we are building platform specific representations of
@param {Object} args individual platform specific payload arguments (optional)
a message builder to abstract the individual format for each platform ; supports a message badges and custom payloads