Skip to content

Commit

Permalink
Swapped in new verbs, added jsdoc, updated tests (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
aydrian committed Sep 7, 2016
1 parent 4d3890d commit b5ad424
Show file tree
Hide file tree
Showing 11 changed files with 201 additions and 191 deletions.
40 changes: 10 additions & 30 deletions docs/resources/inboundDomains.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,22 @@
# Inbound Domains

This library provides easy access to the [Inbound Domains](https://developers.sparkpost.com/api#/reference/inbound-domains/) Resource.
This library provides easy access to the [Inbound Domains](https://developers.sparkpost.com/api/inbound-domains) Resource.

*Note: All methods return promises and accept an optional last argument callback. [Read about how we handle callbacks and promises](/docs/async.md).*

## Methods
* **all(callback)**
* **list()**<br />
List an overview of all inbound domains in the account.
* `callback` - executed after task is completed. **required**
* standard `callback(err, data)`
* `err` - any error that occurred
* `data` - full response from request client
* **find(domain, callback)**
Retrieve a inbound domain by its domain name
* **get(domain)**<br />
Get an inbound domain by its domain name
* `domain` - the name of the domain you want to look up **required**
* `callback` - see all function
* **create(domain, callback)**
* **create(createOpts)**<br />
Create a new inbound domain
* `domain` - the name of the domain you want to create **required**
* `callback` - see all function
* **delete(domain, callback)**
* `createOpts` - a hash of [inbound domain attributes](https://developers.sparkpost.com/api/inbound-domains#header-inbound-domains-attributes) **required**
* **delete(domain)**<br />
Delete an existing inbound domain
* `domain` - the name of the domain you want to delete **required**
* `callback` - see all function

## Examples

```js
var SparkPost = require('sparkpost');
var client = new SparkPost('YOUR_API_KEY');

client.inboundDomains.all(function(err, data) {
if(err) {
console.log(err);
return;
}

console.log(data);
});

```

Check out all the examples provided [here](/examples/inboundDomains).
Visit our examples section to see all of [our inbound domains resource examples](/examples/inboundDomains).
28 changes: 28 additions & 0 deletions examples/inboundDomains/create.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

var key = 'YOURAPIKEY'
, SparkPost = require('sparkpost')
, client = new SparkPost(key)
, createOpts = {domain: 'example1.com'};

// Promise
client.inboundDomains.create(createOpts)
.then(data => {
console.log('Congrats you can use our client library!');
console.log(data);
})
.catch(err => {
console.log('Whoops! Something went wrong');
console.log(err);
});

// Callback
client.inboundDomains.create(createOpts, function(err, data) {
if (err) {
console.log('Whoops! Something went wrong');
console.log(err);
} else {
console.log('Congrats you can use our client library!');
console.log(data);
}
});
14 changes: 0 additions & 14 deletions examples/inboundDomains/create_inboundDomain.js

This file was deleted.

27 changes: 27 additions & 0 deletions examples/inboundDomains/delete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

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

// Promise
client.inboundDomains.delete('example1.com')
.then(data => {
console.log('Congrats you can use our client library!');
console.log(data);
})
.catch(err => {
console.log('Whoops! Something went wrong');
console.log(err);
});

// Callback
client.inboundDomains.delete('example1.com', function(err, data) {
if (err) {
console.log('Whoops! Something went wrong');
console.log(err);
} else {
console.log('Congrats you can use our client library!');
console.log(data);
}
});
14 changes: 0 additions & 14 deletions examples/inboundDomains/delete_inboundDomain.js

This file was deleted.

14 changes: 0 additions & 14 deletions examples/inboundDomains/find_inboundDomain.js

This file was deleted.

27 changes: 27 additions & 0 deletions examples/inboundDomains/get.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

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

// Promise
client.inboundDomains.get('example1.com')
.then(data => {
console.log('Congrats you can use our client library!');
console.log(data);
})
.catch(err => {
console.log('Whoops! Something went wrong');
console.log(err);
});

// Callback
client.inboundDomains.get('example1.com', function(err, data) {
if (err) {
console.log('Whoops! Something went wrong');
console.log(err);
} else {
console.log('Congrats you can use our client library!');
console.log(data);
}
});
14 changes: 0 additions & 14 deletions examples/inboundDomains/get_all_inboundDomains.js

This file was deleted.

27 changes: 27 additions & 0 deletions examples/inboundDomains/list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

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

// Promise
client.inboundDomains.list()
.then(data => {
console.log('Congrats you can use our client library!');
console.log(data);
})
.catch(err => {
console.log('Whoops! Something went wrong');
console.log(err);
});

// Callback
client.inboundDomains.list(function(err, data) {
if (err) {
console.log('Whoops! Something went wrong');
console.log(err);
} else {
console.log('Congrats you can use our client library!');
console.log(data);
}
});
74 changes: 41 additions & 33 deletions lib/inboundDomains.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
'use strict';

var api = 'inbound-domains'
, Promise = require('./Promise');
const api = 'inbound-domains';
const Promise = require('./Promise');

module.exports = function(client) {
var inboundDomains = {
all: function(callback) {
return {
/**
* List an overview of all inbound domains in the account.
*
* @param {RequestCb} [callback]
* @returns {Promise}
*/
list: function(callback) {
var options = {
uri: api
};
return client.get(options).asCallback(callback);
},
find: function(domain, callback) {
var options;
/**
* Get an inbound domain by its domain name
*
* @param {string} domain
* @param {RequestCb} [callback]
* @returns {Promise}
*/
get: function(domain, callback) {
let options;

if(typeof domain === 'function') {
callback = domain;
domain = null;
}

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

Expand All @@ -28,35 +36,37 @@ module.exports = function(client) {
};
return client.get(options).asCallback(callback);
},
create: function(domain, callback) {
var options;

if(typeof domain === 'function') {
callback = domain;
domain = null;
}
/**
* Create a new inbound domain
*
* @param {Object} createOpts
* @param {RequestCb} [callback]
* @returns {Promise}
*/
create: function(createOpts, callback) {
let options;

if(!domain) {
return Promise.reject(new Error('domain is required')).asCallback(callback);
if(!createOpts || typeof createOpts !== 'object') {
return Promise.reject(new Error('create options are required')).asCallback(callback);
}

options = {
uri: api
, json: {
domain: domain
}
, json: createOpts
};
return client.post(options, callback).asCallback(callback);
},
/**
* Delete an existing inbound domain
*
* @param {string} domain
* @param {RequestCb} [callback]
* @returns {Promise}
*/
delete: function(domain, callback) {
var options;

if (typeof domain === 'function') {
callback = domain;
domain = null;
}
let options;

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

Expand All @@ -66,6 +76,4 @@ module.exports = function(client) {
return client.delete(options).asCallback(callback);
}
};

return inboundDomains;
};
Loading

0 comments on commit b5ad424

Please sign in to comment.