sparkpost
Advanced tools
Comparing version 1.3.7 to 1.3.8
210
ajh_test.js
@@ -1,142 +0,75 @@ | ||
// NODE SDK Test Key | ||
// e2e1b620ff9cf2db919d3c40160c4851d445d454 | ||
'use strict'; | ||
var key = 'a09759fb7b8c81cb8878acb7b1aa8b91ff6a6e2d' | ||
, SparkPost = require('./lib/sparkpost') | ||
, sparky = new SparkPost() | ||
, recipients = [ | ||
var SparkPost = require('./lib/sparkpost') | ||
, client = new SparkPost(); | ||
/* | ||
client.transmissions.send({ transmissionBody: { | ||
'campaign_id': 'substitution_data_test', | ||
'content': { | ||
'template_id': 'substitution-test' | ||
}, | ||
'substitution_data': { | ||
'myVar': 'blue', | ||
'my_var': 'green', | ||
'MY_VAR': 'yellow' | ||
}, | ||
'recipients': [ | ||
{ | ||
email: 'test1@test.com' | ||
, transactional: false | ||
, non_transactional: true | ||
, description: 'Test description 1' | ||
}, | ||
{ | ||
email: 'test2@test.com' | ||
, transactional: true | ||
, non_transactional: true | ||
, description: 'Test description 2' | ||
}, | ||
{ | ||
email: 'test3@test.com' | ||
, transactional: true | ||
, non_transactional: false | ||
, description: 'Test description 3' | ||
'address': { | ||
'email': 'aydrian+nodejs@sparkpost.com' | ||
}, | ||
'substitution_data': { | ||
'yourVar': 'orange', | ||
'your_var': 'red', | ||
'YOUR_VAR': 'magenta' | ||
} | ||
} | ||
]; | ||
sparky.suppressionList.upsert(recipients, function(err, res) { | ||
if (err) { | ||
] | ||
}}) | ||
.then(data => { | ||
console.log(data); | ||
console.log('What up my glib globs! SparkPost!'); | ||
}) | ||
.catch(err => { | ||
console.log(err); | ||
} else { | ||
console.log(res.body); | ||
console.log('Congrats you can use our client library!'); | ||
} | ||
}); | ||
/*client.relayWebhooks.update(options, function(err, res) { | ||
if (err) { | ||
}); | ||
*/ | ||
/* | ||
client.templates.find({id:'substitution-test'}) | ||
.then(data => { | ||
console.log(data.name); | ||
}) | ||
.catch(err => { | ||
console.log(err); | ||
} else { | ||
console.log(res.request); | ||
console.log(res.body); | ||
} | ||
});*/ | ||
/*client.relayWebhooks.all(function(err, res) { | ||
if (err) { | ||
}); | ||
*/ | ||
/* | ||
client.templates.delete('delete-me') | ||
.then(data => { | ||
console.log(data); | ||
}) | ||
.catch(err => { | ||
console.log(err); | ||
} else { | ||
console.log(res.body); | ||
} | ||
}); | ||
client.templates.all(function(err, res) { | ||
}); | ||
*/ | ||
/* | ||
client.webhooks.all(function(err, res) { | ||
if (err) { | ||
console.log(err); | ||
} else { | ||
console.log(res.body); | ||
} | ||
});*/ | ||
/*var SparkPost = require('./lib/sparkpost'), | ||
client = new SparkPost('e2e1b620ff9cf2db919d3c40160c4851d445d454');*/ | ||
/*client.sendingDomains.all(function(err, res) { | ||
if (err) { | ||
console.log(err); | ||
} else { | ||
console.log(res); | ||
console.log(JSON.parse(res.body).results); | ||
console.log('Congrats you can use our SDK!'); | ||
} | ||
});*/ | ||
/** | ||
* Test Sending Domains | ||
*/ | ||
/* | ||
client.sendingDomains.all(function(err, res) { | ||
if (err) { | ||
throw err; | ||
} | ||
console.log(res.body); | ||
}); | ||
*/ | ||
/** | ||
* Test Transmissions | ||
*/ | ||
/*var trans = { | ||
campaign: 'test-campaign', | ||
substitutionData: { | ||
name: 'Test Name' | ||
}, | ||
description: 'test email', | ||
replyTo: 'hello@aydrian.me', | ||
trackOpens: true, | ||
trackClicks: true, | ||
from: 'Aydrian <hello@aydrian.me>', | ||
html: '<p>Hello World! Your name is: {{name}}</p>', | ||
text: 'Hello World!', | ||
subject: 'Example Email for All Fields', | ||
to: [ | ||
{ | ||
address: { | ||
email: 'aydrian@gmail.com' | ||
} | ||
} | ||
] | ||
};*/ | ||
/* | ||
var txBody = { | ||
"options": { | ||
"open_tracking": true, | ||
"click_tracking": true | ||
}, | ||
"substitution_data": { | ||
"signature": "Ayrat" | ||
}, | ||
"recipients": [ | ||
{ | ||
"address": { | ||
"email": "aydrian@gmail.com" | ||
} | ||
} | ||
], | ||
"content": { | ||
"template_id": "test-template", | ||
"from": "aydrian@gmail.com" | ||
} | ||
var webhook = { | ||
id: '8b8ce040-7e7f-11e5-a671-99aab5df8b48' | ||
, name: 'Syncano Test Updated' | ||
}; | ||
client.transmissions.send({transmissionBody: txBody }, function(err, res) { | ||
client.webhooks.update(webhook, function(err, res) { | ||
if (err) { | ||
console.log(err); | ||
return; | ||
} else { | ||
console.log(res.statusCode); | ||
console.log(res.body); | ||
@@ -146,34 +79,1 @@ console.log('Congrats you can use our SDK!'); | ||
}); | ||
/* | ||
var sinon = require('sinon'); | ||
var request = require('request'); | ||
// initializing sinon fakeServer | ||
var server = sinon.fakeServer.create(); | ||
console.log('running'); | ||
// fake server answers are queued and not returned automatically unless autoRespond set to true | ||
server.autoRespond = true; | ||
// setting some custom response | ||
server.respondWith("GET", "/some/path/to/data.json", | ||
[200, { "Content-Type": "application/json" }, | ||
'[{ "id": 12, "comment": "Hey there" }]']); | ||
// make an ajax call | ||
var reqOpts = { | ||
method: 'GET', | ||
uri: "/some/path/to/data.json" | ||
}; | ||
request(reqOpts, function(error, response, body) { | ||
if (error) { | ||
console.log(error + "!!!"); | ||
return; | ||
} | ||
console.log('Hurray! Our data has arrived:', body); | ||
}); | ||
// rollback default XHR object | ||
server.restore(); | ||
*/ | ||
@@ -7,2 +7,5 @@ # Change Log | ||
## [1.3.8] - 2016-08-26 | ||
- [#165](https://github.com/SparkPost/node-sparkpost/pull/165) Updated webhook update method to not send id in request (@aydrian) | ||
## [1.3.7] - 2016-07-28 | ||
@@ -111,3 +114,6 @@ - [#150](https://github.com/SparkPost/node-sparkpost/pull/150) Upgrade lodash version to 4 (@rnzo) | ||
[unreleased]: https://github.com/sparkpost/node-sparkpost/compare/1.3.5...HEAD | ||
[unreleased]: https://github.com/sparkpost/node-sparkpost/compare/1.3.8...HEAD | ||
[1.3.8]: https://github.com/sparkpost/node-sparkpost/compare/1.3.7...1.3.8 | ||
[1.3.7]: https://github.com/sparkpost/node-sparkpost/compare/1.3.6...1.3.7 | ||
[1.3.6]: https://github.com/sparkpost/node-sparkpost/compare/1.3.5...1.3.6 | ||
[1.3.5]: https://github.com/sparkpost/node-sparkpost/compare/1.3.4...1.3.5 | ||
@@ -114,0 +120,0 @@ [1.3.4]: https://github.com/sparkpost/node-sparkpost/compare/1.3.3...1.3.4 |
@@ -33,3 +33,3 @@ # Transmissions | ||
transmissionBody: { | ||
campaignId: 'first-mailing', | ||
campaign_id: 'first-mailing', | ||
content: { | ||
@@ -41,3 +41,3 @@ from: 'you@your-company.com', | ||
}, | ||
substitutionData: {name: 'YOUR FIRST NAME'}, | ||
substitution_data: {name: 'YOUR FIRST NAME'}, | ||
recipients: [{ address: { name: 'YOUR FULL NAME', email: 'YOUR EMAIL ADDRESS' } }] | ||
@@ -44,0 +44,0 @@ } |
@@ -8,3 +8,3 @@ 'use strict'; | ||
var webhooks = { | ||
all: function(options, callback) { | ||
all: function (options, callback) { | ||
var reqOpts = { | ||
@@ -26,6 +26,6 @@ uri: api | ||
}, | ||
describe: function(options, callback) { | ||
describe: function (options, callback) { | ||
options = options || {}; | ||
if(!options.id) { | ||
if (!options.id) { | ||
callback(new Error('id is required')); | ||
@@ -45,4 +45,4 @@ return; | ||
}, | ||
create: function(webhook, callback) { | ||
if(typeof webhook === 'function') { | ||
create: function (webhook, callback) { | ||
if (typeof webhook === 'function') { | ||
callback = webhook; | ||
@@ -52,3 +52,3 @@ webhook = null; | ||
if(!webhook) { | ||
if (!webhook) { | ||
callback(new Error('webhook object is required')); | ||
@@ -64,4 +64,6 @@ return; | ||
}, | ||
update: function(webhook, callback) { | ||
if(typeof webhook === 'function') { | ||
update: function (webhook, callback) { | ||
var object, options, id; | ||
if (typeof webhook === 'function') { | ||
callback = webhook; | ||
@@ -71,3 +73,3 @@ webhook = null; | ||
if(!webhook) { | ||
if (!webhook) { | ||
callback(new Error('webhook object is required')); | ||
@@ -77,10 +79,35 @@ return; | ||
var object = toApiFormat(webhook) | ||
, options = { | ||
uri: api + '/' + webhook.id | ||
, json: object | ||
}; | ||
if (!webhook.id) { | ||
callback(new Error('webhook.id is required')); | ||
return; | ||
} | ||
id = webhook.id; | ||
delete webhook.id; | ||
object = toApiFormat(webhook); | ||
options = { | ||
uri: api + '/' + id | ||
, json: object | ||
}; | ||
client.put(options, callback); | ||
}, | ||
delete: function (id, callback) { | ||
if (typeof id === 'function') { | ||
callback = id; | ||
id = null; | ||
} | ||
if (!id) { | ||
callback(new Error('id is required')); | ||
return; | ||
} | ||
var options = { | ||
uri: api + '/' + id | ||
}; | ||
client.delete(options, callback); | ||
}, | ||
validate: function(options, callback) { | ||
@@ -152,21 +179,3 @@ options = options || {}; | ||
webhooks['delete'] = function(id, callback) { | ||
if (typeof id === 'function') { | ||
callback = id; | ||
id = null; | ||
} | ||
if (!id) { | ||
callback(new Error('id is required')); | ||
return; | ||
} | ||
var options = { | ||
uri: api + '/' + id | ||
}; | ||
client['delete'](options, callback); | ||
}; | ||
return webhooks; | ||
}; |
{ | ||
"name": "sparkpost", | ||
"version": "1.3.7", | ||
"version": "1.3.8", | ||
"description": "A Node.js wrapper for interfacing with your favorite SparkPost APIs", | ||
@@ -19,3 +19,3 @@ "main": "./lib/sparkpost.js", | ||
"author": "Message Systems, Inc.", | ||
"license": "Apache 2.0", | ||
"license": "Apache-2.0", | ||
"bugs": { | ||
@@ -22,0 +22,0 @@ "url": "https://github.com/SparkPost/node-sparkpost/issues" |
@@ -16,3 +16,3 @@ var chai = require('chai') | ||
put: sinon.stub().yields(), | ||
'delete': sinon.stub().yields() | ||
delete: sinon.stub().yields() | ||
}; | ||
@@ -128,2 +128,10 @@ | ||
}); | ||
it('should throw an error if webhook.id is missing', function(done) { | ||
webhooks.update({}, function (err) { | ||
expect(err.message).to.equal('webhook.id is required'); | ||
expect(client.post).not.to.have.been.called; | ||
done(); | ||
}); | ||
}); | ||
}); | ||
@@ -133,4 +141,4 @@ | ||
it('should call client delete method with the appropriate uri', function(done) { | ||
webhooks['delete']('test', function(err, data) { | ||
expect(client['delete'].firstCall.args[0].uri).to.equal('webhooks/test'); | ||
webhooks.delete('test', function(err, data) { | ||
expect(client.delete.firstCall.args[0].uri).to.equal('webhooks/test'); | ||
done(); | ||
@@ -141,5 +149,5 @@ }); | ||
it('should throw an error if id is null', function(done) { | ||
webhooks['delete'](null, function(err) { | ||
webhooks.delete(null, function(err) { | ||
expect(err.message).to.equal('id is required'); | ||
expect(client['delete']).not.to.have.been.called; | ||
expect(client.delete).not.to.have.been.called; | ||
done(); | ||
@@ -150,5 +158,5 @@ }); | ||
it('should throw an error if id is missing', function(done) { | ||
webhooks['delete'](function(err) { | ||
webhooks.delete(function(err) { | ||
expect(err.message).to.equal('id is required'); | ||
expect(client['delete']).not.to.have.been.called; | ||
expect(client.delete).not.to.have.been.called; | ||
done(); | ||
@@ -155,0 +163,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
280182
128
4635