summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSorin Baba <sorin.baba@sendgrid.com>2014-12-10 10:32:07 +0200
committerSorin Baba <sorin.baba@sendgrid.com>2014-12-10 10:43:38 +0200
commit81a9be438f99da2146e386052cb6f3135527013d (patch)
treedc73a59a722c16bfffe176b85600779b6de671fb
parentc61fa29ad2fbffcbecd73e7492037c316ca5c2bb (diff)
downloadsendgrid-nodejs-81a9be438f99da2146e386052cb6f3135527013d.zip
sendgrid-nodejs-81a9be438f99da2146e386052cb6f3135527013d.tar.gz
sendgrid-nodejs-81a9be438f99da2146e386052cb6f3135527013d.tar.bz2
Added the ability to schedule the send
-rw-r--r--README.md25
-rw-r--r--lib/email.js12
-rw-r--r--package.json4
-rw-r--r--test/integration/sendgrid.test.js28
-rw-r--r--test/lib/email.test.js38
-rw-r--r--test/lib/sendgrid.test.js2
6 files changed, 106 insertions, 3 deletions
diff --git a/README.md b/README.md
index 80fbebc..dde97e3 100644
--- a/README.md
+++ b/README.md
@@ -221,6 +221,31 @@ email.setHtml('<h1>Some html</h1>');
sendgrid.send(email, function(err, json) { });
```
+#### setSendAt
+
+```javascript
+var email = new sendgrid.Email();
+email.setSendAt(1409348513');
+sendgrid.send(email, function(err, json) { });
+```
+
+#### setSendEachAt
+
+```javascript
+var email = new sendgrid.Email();
+email.setSendEachAt([1409348513, 1409348514]);
+sendgrid.send(email, function(err, json) { });
+```
+
+#### addSendEachAt
+
+```javascript
+var email = new sendgrid.Email();
+email.addSendEachAt(1409348513);
+email.addSendEachAt(1409348514);
+sendgrid.send(email, function(err, json) { });
+```
+
#### addHeader
You can add custom headers. This will ADD rather than SET headers.
diff --git a/lib/email.js b/lib/email.js
index 701da9d..4b1c933 100644
--- a/lib/email.js
+++ b/lib/email.js
@@ -133,6 +133,18 @@ Email.prototype.addFile = function(file_object) {
this.files.push(new FileHandler(file_object));
};
+Email.prototype.setSendAt = function(send_at) {
+ this.smtpapi.setSendAt(send_at);
+};
+
+Email.prototype.setSendEachAt = function(send_each_at) {
+ this.smtpapi.setSendEachAt(send_each_at);
+};
+
+Email.prototype.addSendEachAt = function(send_each_at) {
+ this.smtpapi.addSendEachAt(send_each_at);
+};
+
Email.prototype.toWebFormat = function() {
var web = {
to : this.to,
diff --git a/package.json b/package.json
index d51ecab..3c5053a 100644
--- a/package.json
+++ b/package.json
@@ -9,7 +9,7 @@
],
"name": "sendgrid",
"description": "Official SendGrid NodeJS library.",
- "version": "1.3.0",
+ "version": "1.4.0",
"homepage": "http://sendgrid.com",
"repository": {
"type": "git",
@@ -22,7 +22,7 @@
"mime": "^1.2.9",
"request": "^2.40.0",
"lodash": "^2.0.0",
- "smtpapi": "^1.0.4"
+ "smtpapi": "^1.0.5"
},
"devDependencies": {
"dotenv": "0.0.2",
diff --git a/test/integration/sendgrid.test.js b/test/integration/sendgrid.test.js
index 18b8ad7..53c7a90 100644
--- a/test/integration/sendgrid.test.js
+++ b/test/integration/sendgrid.test.js
@@ -357,6 +357,34 @@ describe('SendGrid #skip', function () {
});
});
+ it('handles the send_at scheduling param', function(done) {
+ payload.subject += "handles the send_at scheduling param";
+
+ var email = new Email(payload);
+ email.setSendAt(Math.floor(new Date() / 1000) + 60);
+ sendgrid.send(email, function(err, json) {
+ expect(err).to.be.null;
+ expect(json.message).to.equal('success');
+ done();
+ });
+ });
+
+ it('handles the send_each_at scheduling param', function(done) {
+ payload.subject += "handles the send_each_at scheduling param";
+ payload.to = [process.env.TO, 'sendgrid-nodejs@mailinator.com']
+ var email = new Email(payload);
+ email.addTo(payload.to[0]);
+ email.addTo(payload.to[1]);
+ email.addSendEachAt(Math.floor(new Date() / 1000) + 60);
+ email.addSendEachAt(Math.floor(new Date() / 1000) + 300);
+
+ sendgrid.send(email, function(err, json) {
+ expect(err).to.be.null;
+ expect(json.message).to.equal('success');
+ done();
+ });
+ });
+
it('handles filters', function(done) {
payload.subject += "handles filters";
diff --git a/test/lib/email.test.js b/test/lib/email.test.js
index e5aab66..20f99ca 100644
--- a/test/lib/email.test.js
+++ b/test/lib/email.test.js
@@ -189,6 +189,44 @@ describe('Email', function () {
expect(email.smtpapi.header.unique_args).to.eql({unique_arg1: 'value', unique_arg2: 'value'});
});
+ it('should be possible to setSendAt', function() {
+ var email = new Email();
+ expect(email.smtpapi.header.send_at).to.be.empty;
+ expect(email.smtpapi.header.send_each_at).to.eql([]);
+ email.setSendAt(1409348513);
+ expect(email.smtpapi.header.send_at).to.eql(1409348513);
+ expect(email.smtpapi.header.send_each_at).to.eql([]);
+ });
+
+ it('should be possible to setSendEachAt', function() {
+ var email = new Email();
+ expect(email.smtpapi.header.send_at).to.be.empty;
+ expect(email.smtpapi.header.send_each_at).to.eql([]);
+ email.setSendEachAt([1409348513, 1409348514]);
+ expect(email.smtpapi.header.send_at).to.be.empty;
+ expect(email.smtpapi.header.send_each_at).to.eql([1409348513, 1409348514]);
+ });
+
+ it('should be possible to addSendEachAt', function() {
+ var email = new Email();
+ expect(email.smtpapi.header.send_at).to.be.empty;
+ expect(email.smtpapi.header.send_each_at).to.eql([]);
+ email.addSendEachAt(1409348513);
+ email.addSendEachAt(1409348514);
+ expect(email.smtpapi.header.send_at).to.be.empty;
+ expect(email.smtpapi.header.send_each_at).to.eql([1409348513, 1409348514]);
+ });
+
+ it('should be possible to setSendEachAt and addSendEachAt', function() {
+ var email = new Email();
+ expect(email.smtpapi.header.send_at).to.be.empty;
+ expect(email.smtpapi.header.send_each_at).to.eql([]);
+ email.setSendEachAt([1409348513]);
+ email.addSendEachAt(1409348514);
+ expect(email.smtpapi.header.send_at).to.be.empty;
+ expect(email.smtpapi.header.send_each_at).to.eql([1409348513, 1409348514]);
+ });
+
it('should be possible to setUniqueArgs', function() {
var email = new Email();
expect(email.smtpapi.header.unique_args).to.eql({});
diff --git a/test/lib/sendgrid.test.js b/test/lib/sendgrid.test.js
index 335c13c..218660f 100644
--- a/test/lib/sendgrid.test.js
+++ b/test/lib/sendgrid.test.js
@@ -15,7 +15,7 @@ describe('SendGrid', function () {
});
it('version should be set', function() {
- expect(sendgrid.version).to.equal("1.3.0");
+ expect(sendgrid.version).to.equal("1.4.0");
});
it('should attach a options object to self', function() {