diff options
author | scottmotte <scott@scottmotte.com> | 2014-05-28 15:10:23 -0700 |
---|---|---|
committer | scottmotte <scott@scottmotte.com> | 2014-05-28 15:10:23 -0700 |
commit | 882ca106f508a2f09af9f772c438686966bbe79d (patch) | |
tree | b6d9fedc8dba3010bddf43b021bdaf94b7896197 | |
parent | b39924fc1fee9fc2e8754c4cb6259d7521a0b38a (diff) | |
download | sendgrid-nodejs-882ca106f508a2f09af9f772c438686966bbe79d.zip sendgrid-nodejs-882ca106f508a2f09af9f772c438686966bbe79d.tar.gz sendgrid-nodejs-882ca106f508a2f09af9f772c438686966bbe79d.tar.bz2 |
Update to latest smtpapi nodejs lib
-rw-r--r-- | lib/email.js | 34 | ||||
-rw-r--r-- | lib/sendgrid.js | 12 | ||||
-rw-r--r-- | package.json | 2 | ||||
-rw-r--r-- | test/lib/email.test.js | 3 |
4 files changed, 6 insertions, 45 deletions
diff --git a/lib/email.js b/lib/email.js index 902dd46..9fb57e3 100644 --- a/lib/email.js +++ b/lib/email.js @@ -1,34 +1,17 @@ "use strict"; var FileHandler = require('./file_handler'); -var smtpapi = require('smtpapi'); +var smtpapi_lib = require('smtpapi'); var _ = require('lodash'); var request = require('request'); var fs = require('fs'); -/** - * Class to handle storing the properties relative to an email. - * - * @param {Object} params - * @param {string|array} params.to The to address(es) of the email - * @param {string|array} params.toname The display name of the email recipients - * @param {string} params.from The from address of the email - * @param {string} params.fromname The display name of the email sender - * @param {SmtpapiHeaders} params.smtpapi The SendGrid x-smtpapi headers object - * @param {string} params.subject The subject of the email - * @param {string} params.text The text/plain content of an email - * @param {string} params.html The text/html content of an email - * @param {string|array} params.bcc The bcc address(es) of the email - * @param {Date} params.date The date of the email - * @param {object} params.headers The custom headers on an email - */ function Email(params) { - params = params || {}; this.to = params.to || []; this.from = params.from || ''; - this.smtpapi = params.smtpapi || new smtpapi.Header(); + this.smtpapi = params.smtpapi || new smtpapi_lib(); this.subject = params.subject || ''; this.text = params.text || ''; this.html = params.html || ''; @@ -209,23 +192,12 @@ Email.prototype._formatFileForNodeMailer = function(file) { } }; -/** - * There needs to be at least 1 to address, or else the mail won't send. - * This method modifies the data that will be sent via either Rest - * - * @param {object} data The data parameter to send via Rest - */ Email.prototype.updateMissingTo = function(data) { - if (this.smtpapi.to && this.smtpapi.to.length > 0) { + if (this.smtpapi.jsonObject().to && this.smtpapi.jsonObject().to.length > 0) { data.to = this.from; } }; -/** - * This method is used to show if there are files on this email object - * - * @return boolean - */ Email.prototype.hasFiles = function() { return this.files.length > 0; }; diff --git a/lib/sendgrid.js b/lib/sendgrid.js index 085085d..559ba23 100644 --- a/lib/sendgrid.js +++ b/lib/sendgrid.js @@ -13,15 +13,6 @@ var Sendgrid = function(api_user, api_key, options) { var _this = this; this.options = options || {}; - /* - * Sends an email and returns true if the - * message was sent successfully. - * - * @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. - */ var send = function(email, callback) { var callback = callback || function() { }; if (email.constructor !== Email) { @@ -31,9 +22,6 @@ var Sendgrid = function(api_user, api_key, options) { _send.bind(this)(email, callback); }; - /* - * Psuedo-private methods - */ var _send = function(email, callback) { var postOptions = { method : 'POST', diff --git a/package.json b/package.json index cf80826..4f9a7b3 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "mime": "1.2.9", "request": "2.22.0", "lodash": "2.0.0", - "smtpapi": "0.0.2" + "smtpapi": "1.0.1" }, "devDependencies": { "dotenv": "0.0.2", diff --git a/test/lib/email.test.js b/test/lib/email.test.js index fda747c..65e66bc 100644 --- a/test/lib/email.test.js +++ b/test/lib/email.test.js @@ -45,7 +45,7 @@ describe('Email', function () { expect(format.to).to.equal(payload.to); }); - it('should have not have multiple TOs if as an array but also set on smtp-api via addTo', function() { + it('should not have multiple TOs if as an array but also set on smtpapi via addTo', function() { var payload = Object.create(default_payload); payload.to = ['david.tomberlin@sendgrid.com', 'otherguy@sendgrid.com']; var email = new Email(payload); @@ -54,6 +54,7 @@ describe('Email', function () { var format = email.toWebFormat(); + console.log(format); expect(format.to).to.equal(payload.from); }); |