Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for deleting a sending domain #118

Merged
merged 3 commits into from
Mar 28, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/resources/sendingDomains.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ This library provides easy access to the [Sending Domains](https://www.sparkpost
Update an existing sending domain
* `domainBody` - a sending domain object **required**
* `callback` - see all function
* **delete(domain, callback)**
Delete an existing sending domain
* `domain` - the name of the domain you want to delete **required**
* `callback` - see all function
* **verify(options, callback)**
Validate the specified verification field types for a sending domain
* `options.domain` - the name of the domain you want to verify **required**
Expand Down
14 changes: 14 additions & 0 deletions examples/sendingDomains/delete_sendingDomain.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

var key = 'YOURAPIKEY'
, SparkPost = require('sparkpost')
, client = new SparkPost(key);

client.sendingDomains['delete']('example1.com', function(err, data) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to quote delete in Node. If this is failing linting, we should update the jshint to es3:false

I see this in a few places in this PR, I'll just comment this once.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is everywhere. I'll fix it in this PR. I'll create an issue to clean that up as part of v2.0.0

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

if (err) {
console.log(err);
} else {
console.log(data);
console.log('Congrats you can use our client library!');
}
});
22 changes: 21 additions & 1 deletion lib/sendingDomains.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ var api = 'sending-domains'
* "Class" declaration, Sending Domains API exposes five functions:
* - create: creates a new sending domain
* - update: updates an existing sending domain
* - delete: deletes an existing sending domain
* - verify: validates specified verification field types on a sending domain
* - all: retreives a list of sending domains
* - find: retreives info about a specific sending domain
*/
module.exports = function (client) {

return {
var sendingDomains = {
all: function (callback) { //list
var options = {
uri: api
Expand Down Expand Up @@ -100,4 +101,23 @@ module.exports = function (client) {
client.post(reqOpts, callback);
}
};

sendingDomains['delete'] = function(domain, callback) {
if (typeof domain === 'function') {
callback = domain;
domain = null;
}

if (!domain) {
callback(new Error('domain is required'));
return;
}

var options = {
uri: api + '/' + domain
};
client['delete'](options, callback);
};

return sendingDomains;
};
28 changes: 27 additions & 1 deletion test/spec/sendingDomains.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ describe('Sending Domains Library', function() {
client = {
get: sinon.stub().yields(),
post: sinon.stub().yields(),
put: sinon.stub().yields()
put: sinon.stub().yields(),
'delete': sinon.stub().yields()
};

sendingDomains = require('../../lib/sendingDomains')(client);
Expand Down Expand Up @@ -126,6 +127,31 @@ describe('Sending Domains Library', function() {
});
});

describe('delete Method', function() {
it('should call client delete method with the appropriate uri', function(done) {
sendingDomains['delete']('test', function(err, data) {
expect(client['delete'].firstCall.args[0].uri).to.equal('sending-domains/test');
done();
});
});

it('should throw an error if domain is null', function(done) {
sendingDomains['delete'](null, function(err) {
expect(err.message).to.equal('domain is required');
expect(client['delete']).not.to.have.been.called;
done();
});
});

it('should throw an error if domain is missing', function(done) {
sendingDomains['delete'](function(err) {
expect(err.message).to.equal('domain is required');
expect(client['delete']).not.to.have.been.called;
done();
});
});
});

describe('verify Method', function() {
it('should call client post method with the appropriate uri', function(done) {
var options = {
Expand Down