summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/sendgrid.js18
-rw-r--r--test/integration/sendgrid.test.js20
2 files changed, 31 insertions, 7 deletions
diff --git a/lib/sendgrid.js b/lib/sendgrid.js
index c7fc0b7..12c8b85 100644
--- a/lib/sendgrid.js
+++ b/lib/sendgrid.js
@@ -27,9 +27,11 @@ function SendGrid(api_user, api_key) {
* @param {Email|Object} email An email object or a hash that has
* the values for the email to be sent.
* @param {Function} callback A function to call when the processing is done.
+ * This parameter is optional.
*/
SendGrid.prototype.send = function(email, callback) {
- var self = this;
+ var self = this
+ , cb = callback || function() { };
var boundary = Math.random();
@@ -71,7 +73,7 @@ SendGrid.prototype.send = function(email, callback) {
});
res.on('end', function() {
var json = JSON.parse(content);
- callback(json.message == 'success', json.errors);
+ cb(json.message == 'success', json.errors);
});
});
@@ -93,7 +95,7 @@ SendGrid.prototype.send = function(email, callback) {
if (success) {
send_rest();
} else {
- callback(false, message);
+ cb(false, message);
}
});
} else {
@@ -108,10 +110,12 @@ SendGrid.prototype.send = function(email, callback) {
* @param {Email|Object} email An email object or a hash that has
* the values for the email to be sent.
* @param {Function} callback A function to call when the processing is done.
+ * This parameter is optional.
*/
SendGrid.prototype.smtp = function(email, callback) {
var self = this
- , smtpTransport;
+ , smtpTransport
+ , cb = callback || function() { };
// SMTP settings
smtpTransport = nodemailer.createTransport("SMTP", {
@@ -126,9 +130,9 @@ SendGrid.prototype.smtp = function(email, callback) {
smtpTransport.sendMail(email.toSmtpFormat(), function(error, response) {
smtpTransport.close();
if(error) {
- return callback(false, response);
+ return cb(false, response);
}
- return callback(true, response);
+ return cb(true, response);
});
}
@@ -141,7 +145,7 @@ SendGrid.prototype.smtp = function(email, callback) {
if (success) {
send_smtp();
} else {
- callback(false, message);
+ cb(false, message);
}
});
} else {
diff --git a/test/integration/sendgrid.test.js b/test/integration/sendgrid.test.js
index eda60b0..f775f40 100644
--- a/test/integration/sendgrid.test.js
+++ b/test/integration/sendgrid.test.js
@@ -136,6 +136,16 @@ describe('SendGrid', function () {
done();
});
});
+
+ it('has an optional callback', function(done) {
+ var mail = new Email(text_params)
+
+ expect(function() {
+ sendgrid.send(mail);
+ }).to.not.throw(Error);
+
+ done();
+ });
});
describe('Smtp Api', function() {
@@ -220,6 +230,16 @@ describe('SendGrid', function () {
done();
});
});
+
+ it('has an optional callback', function(done) {
+ var mail = new Email(text_params)
+
+ expect(function() {
+ sendgrid.smtp(mail);
+ }).to.not.throw(Error);
+
+ done();
+ });
});
describe('x-smtpapi', function(done) {