Skip to content

Commit

Permalink
refactored verify to accept all verify attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
aydrian committed Aug 31, 2016
1 parent 94f26d0 commit acf4a19
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 27 deletions.
3 changes: 1 addition & 2 deletions docs/resources/sendingDomains.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ This library provides easy access to the [Sending Domains](https://developers.sp
* `callback` - see all function
* **verify(options[, callback]) &rarr; `{Promise}`**<br />
Validate the specified verification field types for a sending domain
* `options` - an object of [verify attributes](https://developers.sparkpost.com/api/sending-domains#header-verify-attributes)
* `options.domain` - the name of the domain you want to verify **required**
* `options.verifyDKIM` - initiates a check against the DKIM record default: `true`
* `options.verifySPF` - initiates a check against the SPF record default: `true`

*callback is optional because all methods return a Promise.

Expand Down
6 changes: 5 additions & 1 deletion examples/sendingDomains/verify_sendingDomain_default.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ var key = 'YOURAPIKEY'
, SparkPost = require('sparkpost')
, client = new SparkPost(key)
, options = {
domain: 'example1.com'
domain: 'example1.com',
dkim_verify: true,
spf_verify: true,
abuse_at_verify: true,
postmaster_at_verify: true
};

client.sendingDomains.verify(options)
Expand Down
4 changes: 2 additions & 2 deletions examples/sendingDomains/verify_sendingDomain_dkim_only.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ var key = 'YOURAPIKEY'
, SparkPost = require('sparkpost')
, client = new SparkPost(key)
, options = {
domain: 'example1.com'
, verifySPF: false
domain: 'example1.com',
dkim_verify: true
};

client.sendingDomains.verify(options)
Expand Down
4 changes: 2 additions & 2 deletions examples/sendingDomains/verify_sendingDomain_spf_only.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ var key = 'YOURAPIKEY'
, SparkPost = require('sparkpost')
, client = new SparkPost(key)
, options = {
domain: 'example1.com'
, verifyDKIM: false
domain: 'example1.com',
spf_verify: true
};

client.sendingDomains.verify(options)
Expand Down
10 changes: 4 additions & 6 deletions lib/sendingDomains.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,18 @@ module.exports = function(client) {
},
verify: function(options, callback) {
var reqOpts;
options = options || {};

if(!options.domain) {
if(!options || !options.domain) {
return Promise.reject(new Error('domain is required')).asCallback(callback);
}

reqOpts = {
uri: api + '/' + options.domain + '/verify',
json: {
dkim_verify: options.verifyDKIM !== false,
spf_verify: options.verifySPF !== false
}
json: options
};

delete options.domain;

return client.post(reqOpts).asCallback(callback);
}
};
Expand Down
14 changes: 0 additions & 14 deletions test/spec/sendingDomains.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,5 @@ describe('Sending Domains Library', function() {
expect(client.post.firstCall.args[0].json.spf_verify).to.be.true;
});
});

it('should allow a user to set verifyDKIM and verifySPF', function() {
var options = {
domain: 'test',
verifyDKIM: false,
verifySPF: false
};

sendingDomains.verify(options)
.then(function() {
expect(client.post.firstCall.args[0].json.dkim_verify).to.be.false;
expect(client.post.firstCall.args[0].json.spf_verify).to.be.false;
});
});
});
});

0 comments on commit acf4a19

Please sign in to comment.