summaryrefslogtreecommitdiffstats
path: root/lib/sendgrid.js
diff options
context:
space:
mode:
authorSwift <theycallmeswift@gmail.com>2012-10-13 13:20:46 -0400
committerSwift <theycallmeswift@gmail.com>2012-10-13 13:20:46 -0400
commit66cdb6d85e1d168ca9e77e37cc8cbf4b7c7ed61d (patch)
tree132fb5872c943a5d60a32dd9bcad3b590edfb2c1 /lib/sendgrid.js
parentbf5558f500170996daa1eb524b54133e8512a3bb (diff)
downloadsendgrid-nodejs-66cdb6d85e1d168ca9e77e37cc8cbf4b7c7ed61d.zip
sendgrid-nodejs-66cdb6d85e1d168ca9e77e37cc8cbf4b7c7ed61d.tar.gz
sendgrid-nodejs-66cdb6d85e1d168ca9e77e37cc8cbf4b7c7ed61d.tar.bz2
Web and SMTP api have optional callbacks.
In case you don't care about the callback for `send` or `smtp`, it is now optional to supply a callback function.
Diffstat (limited to 'lib/sendgrid.js')
-rw-r--r--lib/sendgrid.js18
1 files changed, 11 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 {