aerogear-sender-client
Advanced tools
Comparing version 0.0.3 to 0.1.0
@@ -106,38 +106,5 @@ /* AeroGear JavaScript Library | ||
/** | ||
The broadcast Method | ||
@param {Object} message={} - the message to be passed | ||
@param {String} [message.alert] | ||
@param {String} [message.sound] | ||
@param {String} [message.badge] | ||
@param {String} [message.simple-push] | ||
@param {Object} settings={} - the settings to be passed to the adapter | ||
@param {String} settings.applicationID - The Application ID | ||
@param {String} settings.masterSecret - The Master Secret | ||
@returns {Object} itself | ||
*/ | ||
AeroGear.Sender.prototype.broadcast = function( message, settings ) { | ||
settings = settings || {}; | ||
var url, | ||
serverOptions; | ||
url = urlParser.parse( this.getUrl() + "broadcast" ); | ||
serverOptions = createServerSettings( url, settings ); | ||
send.call( this, serverOptions, message ); | ||
return this; | ||
}; | ||
/** | ||
The sendTo Method | ||
@param {Object} [criteria={}] - the criteria to select | ||
@param {Array} [criteria.alias] - a list of email or name strings | ||
@param {Array} [criteria.deviceType] - a list of device types as strings | ||
@param {Array} [criteria.category] - a list of categories as strings | ||
@param {Array} [criteria.variants] - a list of variantID's as strings | ||
@param {Object} [criteria.simple-push] - an object containing simple-push criteria | ||
The send Method | ||
@param {Object} message={} - the message to be passed | ||
@@ -150,15 +117,23 @@ @param {String} [message.alert] | ||
@param {String} settings.masterSecret - The Master Secret | ||
@param {Object} [settings.criteria={}] - the criteria to select | ||
@param {Array} [settings.criteria.alias] - a list of email or name strings | ||
@param {Array} [settings.criteria.deviceType] - a list of device types as strings | ||
@param {Array} [settings.criteria.category] - a list of categories as strings | ||
@param {Array} [settings.criteria.variants] - a list of variantID's as strings | ||
@param {Object} [settings.criteria.simple-push] - an object containing simple-push criteria | ||
@returns {Object} itself | ||
*/ | ||
AeroGear.Sender.prototype.sendTo = function( criteria, message, settings ) { | ||
AeroGear.Sender.prototype.send = function( message, settings ) { | ||
settings = settings || {}; | ||
var url, | ||
serverSettings, | ||
var serverSettings, | ||
url = urlParser.parse( this.getUrl() ), | ||
newMessage = {}; | ||
for( var crit in criteria ) { | ||
newMessage[ crit ] = criteria[ crit ]; | ||
if( settings.criteria ) { | ||
for( var crit in settings.criteria ) { | ||
newMessage[ crit ] = settings.criteria[ crit ]; | ||
} | ||
} | ||
@@ -168,3 +143,2 @@ | ||
url = urlParser.parse( this.getUrl() + "selected" ); | ||
serverSettings = createServerSettings( url, settings ); | ||
@@ -171,0 +145,0 @@ |
{ | ||
"name": "aerogear-sender-client", | ||
"version": "0.0.3", | ||
"version": "0.1.0", | ||
"description": "Sender api for the AeroGear Unified Push server", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/aerogear/aerogear-unifiedpush-nodejs-client", |
@@ -48,14 +48,8 @@ # aerogear-sender-client [![Build Status](https://secure.travis-ci.org/aerogear/aerogear-unifiedpush-nodejs-client.png?branch=master)](https://travis-ci.org/aerogear/aerogear-unifiedpush-nodejs-client) | ||
Send a Broadcast Message | ||
agSender.Sender( url ).broadcast( message, settings ).on( "success", function( response ) { | ||
console.log( "success called", response ); | ||
}); | ||
Send a Selective Message | ||
agSender.Sender( url ).sendTo( criteria, message, settings ).on( "success", function( response ) { | ||
agSender.Sender( url ).send( message, settings ).on( "success", function( response ) { | ||
console.log( "success called", response ); | ||
}); | ||
@@ -22,12 +22,7 @@ var chai = require( "chai" ), | ||
it( "Sender should have a broadcast method", function() { | ||
it( "Sender should have a send method", function() { | ||
var sender = AeroGear.Sender(); | ||
expect( sender.broadcast ).to.exist; | ||
expect( sender.send ).to.exist; | ||
}); | ||
it( "Sender should have a sendTo method", function() { | ||
var sender = AeroGear.Sender(); | ||
expect( sender.sendTo ).to.exist; | ||
}); | ||
it( "Sender should have a URL constructed", function() { | ||
@@ -40,3 +35,3 @@ var sender = AeroGear.Sender( "http://localhost:8080/ag-push" ); | ||
describe( "Sender Broadcast", function() { | ||
describe( "Sender - send", function() { | ||
var sender = AeroGear.Sender( "http://localhost:8080/ag-push" ), | ||
@@ -54,4 +49,4 @@ applicationID = "12345", | ||
describe( "Broadcast Method", function() { | ||
it( "broadcast should be called with success", function( done ) { | ||
describe( "send Method", function() { | ||
it( "send should be called with success", function( done ) { | ||
@@ -61,3 +56,3 @@ nock( "http://localhost:8080" ) | ||
.matchHeader('Content-type', 'application/json') | ||
.post( "/ag-push/rest/sender/broadcast" ) | ||
.post( "/ag-push/rest/sender/" ) | ||
.reply( 200,{} ); | ||
@@ -68,3 +63,3 @@ | ||
sender.broadcast( message, settings ).on( "success", function( response ) { | ||
sender.send( message, settings ).on( "success", function( response ) { | ||
expect( response ).to.be.ok; | ||
@@ -75,7 +70,7 @@ done(); | ||
it( "broadcast should be called with error", function( done ) { | ||
it( "send should be called with error", function( done ) { | ||
nock( "http://localhost:8080" ) | ||
.matchHeader('Accept', 'application/json') | ||
.matchHeader('Content-type', 'application/json') | ||
.post( "/ag-push/rest/sender/broadcast" ).reply( 400,{} ); | ||
.post( "/ag-push/rest/sender/" ).reply( 400,{} ); | ||
@@ -85,3 +80,3 @@ settings.applicationID = applicationID; | ||
sender.broadcast( message, settings ).on( "error", function( error ) { | ||
sender.send( message, settings ).on( "error", function( error ) { | ||
expect( error ).to.be.ok; | ||
@@ -94,50 +89,2 @@ done(); | ||
describe( "Sender - sendTo", function() { | ||
var sender = AeroGear.Sender( "http://localhost:8080/ag-push" ), | ||
applicationID = "12345", | ||
masterSecret = "54321", | ||
settings = {}, | ||
message = {}; | ||
beforeEach( function() { | ||
settings = {}; | ||
message = {}; | ||
}); | ||
describe( "sendTo Method", function() { | ||
it( "broadcast should be called with success", function( done ) { | ||
nock( "http://localhost:8080" ) | ||
.matchHeader('Accept', 'application/json') | ||
.matchHeader('Content-type', 'application/json') | ||
.post( "/ag-push/rest/sender/selected" ) | ||
.reply( 200,{} ); | ||
settings.applicationID = applicationID; | ||
settings.masterSecret = masterSecret; | ||
sender.sendTo( message, settings ).on( "success", function( response ) { | ||
expect( response ).to.be.ok; | ||
done(); | ||
}); | ||
}); | ||
it( "broadcast should be called with error", function( done ) { | ||
nock( "http://localhost:8080" ) | ||
.matchHeader('Accept', 'application/json') | ||
.matchHeader('Content-type', 'application/json') | ||
.post( "/ag-push/rest/sender/selected" ).reply( 400,{} ); | ||
settings.applicationID = applicationID; | ||
settings.masterSecret = masterSecret; | ||
sender.sendTo( message, settings ).on( "error", function( error ) { | ||
expect( error ).to.be.ok; | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe( "Sender - Handle Moved Status Codes", function() { | ||
@@ -155,5 +102,4 @@ var sender = AeroGear.Sender( "http://localhost:8080/ag-push" ), | ||
describe( "Endpoint returns moved", function() { | ||
it( "broadcast should be called with success", function( done ) { | ||
it( "send should be called with success", function( done ) { | ||
@@ -163,3 +109,3 @@ nock( "http://localhost:8080" ) | ||
.matchHeader('Content-type', 'application/json') | ||
.post( "/ag-push/rest/sender/broadcast" ) | ||
.post( "/ag-push/rest/sender/" ) | ||
.reply( 302,{},{'location': "http://localhost:8080/rest/new/sender"} ) | ||
@@ -172,3 +118,3 @@ .post( "/rest/new/sender" ) | ||
sender.broadcast( message, settings ).on( "success", function( response ) { | ||
sender.send( message, settings ).on( "success", function( response ) { | ||
expect( response ).to.be.ok; | ||
@@ -181,3 +127,3 @@ done(); | ||
describe( "Endpoint returns moved, with no new location", function() { | ||
it( "broadcast should be called with error", function( done ) { | ||
it( "send should be called with error", function( done ) { | ||
@@ -187,3 +133,3 @@ nock( "http://localhost:8080" ) | ||
.matchHeader('Content-type', 'application/json') | ||
.post( "/ag-push/rest/sender/broadcast" ) | ||
.post( "/ag-push/rest/sender/" ) | ||
.reply( 302,{},{} ); | ||
@@ -194,3 +140,3 @@ | ||
sender.broadcast( message, settings ).on( "error", function( error ) { | ||
sender.send( message, settings ).on( "error", function( error ) { | ||
expect( error ).to.be.ok; | ||
@@ -202,43 +148,2 @@ expect( error ).to.equal( "redirect url is not available" ); | ||
}); | ||
// describe( "Endpoint returns moved", function() { | ||
// it( "sendTo should be called with success", function( done ) { | ||
// nock( "http://localhost:8080" ) | ||
// .matchHeader('Accept', 'application/json') | ||
// .matchHeader('Content-type', 'application/json') | ||
// .post( "/ag-push/rest/sender/selected" ) | ||
// .reply( 302,{},{'location': "http://localhost:8080/rest/new/sender"} ) | ||
// .post( "/rest/new/sender" ) | ||
// .reply( 200, {} ); | ||
// settings.applicationID = applicationID; | ||
// settings.masterSecret = masterSecret; | ||
// sender.sendTo( message, settings ).on( "success", function( response ) { | ||
// expect( response ).to.be.ok; | ||
// done(); | ||
// }); | ||
// }); | ||
// }); | ||
// describe( "Endpoint returns moved, with no new location", function() { | ||
// it( "sendTo should be called with error", function( done ) { | ||
// nock( "http://localhost:8080" ) | ||
// .matchHeader('Accept', 'application/json') | ||
// .matchHeader('Content-type', 'application/json') | ||
// .post( "/ag-push/rest/sender/selected" ) | ||
// .reply( 302,{},{} ); | ||
// settings.applicationID = applicationID; | ||
// settings.masterSecret = masterSecret; | ||
// sender.sendTo( message, settings ).on( "error", function( error ) { | ||
// expect( error ).to.be.ok; | ||
// expect( error ).to.equal( "redirect url is not available" ); | ||
// done(); | ||
// }); | ||
// }); | ||
// }); | ||
}); | ||
@@ -259,3 +164,3 @@ | ||
describe( "Endpoint returns moved", function() { | ||
it( "sendTo should be called with success", function( done ) { | ||
it( "send should be called with success", function( done ) { | ||
@@ -265,3 +170,3 @@ nock( "http://localhost:8080" ) | ||
.matchHeader('Content-type', 'application/json') | ||
.post( "/ag-push/rest/sender/selected" ) | ||
.post( "/ag-push/rest/sender/" ) | ||
.reply( 302,{},{'location': "http://localhost:8080/rest/new/sender"} ) | ||
@@ -274,3 +179,3 @@ .post( "/rest/new/sender" ) | ||
sender.sendTo( message, settings ).on( "success", function( response ) { | ||
sender.send( message, settings ).on( "success", function( response ) { | ||
expect( response ).to.be.ok; | ||
@@ -283,3 +188,3 @@ done(); | ||
describe( "Endpoint returns moved, with no new location", function() { | ||
it( "sendTo should be called with error", function( done ) { | ||
it( "send should be called with error", function( done ) { | ||
@@ -289,3 +194,3 @@ nock( "http://localhost:8080" ) | ||
.matchHeader('Content-type', 'application/json') | ||
.post( "/ag-push/rest/sender/selected" ) | ||
.post( "/ag-push/rest/sender/" ) | ||
.reply( 302,{},{} ); | ||
@@ -296,3 +201,3 @@ | ||
sender.sendTo( message, settings ).on( "error", function( error ) { | ||
sender.send( message, settings ).on( "error", function( error ) { | ||
expect( error ).to.be.ok; | ||
@@ -299,0 +204,0 @@ expect( error ).to.equal( "redirect url is not available" ); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
126845
4742
55