Skip to content

Commit

Permalink
Merge 4a7271e into 8a5d142
Browse files Browse the repository at this point in the history
  • Loading branch information
avigoldman committed Jan 19, 2017
2 parents 8a5d142 + 4a7271e commit fdfa7b9
Show file tree
Hide file tree
Showing 21 changed files with 578 additions and 120 deletions.
15 changes: 7 additions & 8 deletions lib/inboundDomains.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

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

module.exports = function(client) {
Expand All @@ -15,7 +14,7 @@ module.exports = function(client) {
const options = {
uri: api
};
return withCallback(client.get(options), callback);
return client.get(options, callback);
},
/**
* Get an inbound domain by its domain name
Expand All @@ -26,13 +25,13 @@ module.exports = function(client) {
*/
get: function(domain, callback) {
if (!domain || typeof domain !== 'string') {
return withCallback(Promise.reject(new Error('domain is required')), callback);
return client.reject(new Error('domain is required'), callback);
}

const options = {
uri: `${api}/${domain}`
};
return withCallback(client.get(options), callback);
return client.get(options, callback);
},
/**
* Create a new inbound domain
Expand All @@ -43,14 +42,14 @@ module.exports = function(client) {
*/
create: function(createOpts, callback) {
if (!createOpts || typeof createOpts !== 'object') {
return withCallback(Promise.reject(new Error('create options are required')), callback);
return client.reject(new Error('create options are required'), callback);
}

const options = {
uri: api
, json: createOpts
};
return withCallback(client.post(options, callback), callback);
return client.post(options, callback);
},
/**
* Delete an existing inbound domain
Expand All @@ -61,13 +60,13 @@ module.exports = function(client) {
*/
delete: function(domain, callback) {
if (!domain || typeof domain !== 'string') {
return withCallback(Promise.reject(new Error('domain is required')), callback);
return client.reject(new Error('domain is required'), callback);
}

const options = {
uri: `${api}/${domain}`
};
return withCallback(client.delete(options), callback);
return client.delete(options, callback);
}
};
};
3 changes: 1 addition & 2 deletions lib/messageEvents.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const withCallback = require('./Promise');
const api = 'message-events';

/*
Expand Down Expand Up @@ -29,7 +28,7 @@ module.exports = function(client) {
options.qs[paramname] = parameters[paramname];
}
});
return withCallback(client.get(options), callback);
return client.get(options, callback);
}
};
};
21 changes: 10 additions & 11 deletions lib/recipientLists.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const withCallback = require('./Promise');
const api = 'recipient-lists';

module.exports = function(client) {
Expand All @@ -16,7 +15,7 @@ module.exports = function(client) {
const reqOpts = {
uri: api
};
return withCallback(client.get(reqOpts), callback);
return client.get(reqOpts, callback);
},

/**
Expand All @@ -38,15 +37,15 @@ module.exports = function(client) {
}

if (!id) {
return withCallback(Promise.reject(new Error('id is required')), callback);
return client.reject(new Error('id is required'), callback);
}

const reqOpts = {
uri: `${api}/${id}`,
qs: options
};

return withCallback(client.get(reqOpts), callback);
return client.get(reqOpts, callback);
},


Expand All @@ -61,7 +60,7 @@ module.exports = function(client) {
*/
create: function(recipientList, callback) {
if (!recipientList || typeof recipientList !== 'object' || !recipientList.recipients) {
return withCallback(Promise.reject(new Error('recipient list is required')), callback);
return client.reject(new Error('recipient list is required'), callback);
}

const reqOpts = {
Expand All @@ -72,7 +71,7 @@ module.exports = function(client) {
}
};

return withCallback(client.post(reqOpts), callback);
return client.post(reqOpts, callback);
},

/**
Expand All @@ -88,11 +87,11 @@ module.exports = function(client) {
*/
update: function(id, recipientList, callback) {
if (!id) {
return withCallback(Promise.reject(new Error('recipient list id is required')), callback);
return client.reject(new Error('recipient list id is required'), callback);
}

if (!recipientList || typeof recipientList === 'function') {
return withCallback(Promise.reject(new Error('recipient list is required')), callback);
return client.reject(new Error('recipient list is required'), callback);
}

const reqOpts = {
Expand All @@ -103,7 +102,7 @@ module.exports = function(client) {
}
};

return withCallback(client.put(reqOpts), callback);
return client.put(reqOpts, callback);
},

/**
Expand All @@ -117,14 +116,14 @@ module.exports = function(client) {
*/
delete: function(id, callback) {
if (!id || typeof id !== 'string') {
return withCallback(Promise.reject(new Error('id is required')), callback);
return client.reject(new Error('id is required'), callback);
}

const reqOpts = {
uri: `${api}/${id}`
};

return withCallback(client.delete(reqOpts), callback);
return client.delete(reqOpts, callback);
}
};

Expand Down
21 changes: 10 additions & 11 deletions lib/relayWebhooks.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const withCallback = require('./Promise');
const api = 'relay-webhooks';

module.exports = function(client) {
Expand All @@ -15,7 +14,7 @@ module.exports = function(client) {
const reqOpts = {
uri: api
};
return withCallback(client.get(reqOpts), callback);
return client.get(reqOpts, callback);
},
/**
* Get details about a specified relay webhook by its id
Expand All @@ -26,14 +25,14 @@ module.exports = function(client) {
*/
get: function(id, callback) {
if (!id || typeof id !== 'string') {
return withCallback(Promise.reject(new Error('id is required')), callback);
return client.reject(new Error('id is required'), callback);
}

const options = {
uri: `${api}/${id}`
};

return withCallback(client.get(options), callback);
return client.get(options, callback);
},
/**
* Create a new relay webhook
Expand All @@ -44,15 +43,15 @@ module.exports = function(client) {
*/
create: function(webhook, callback) {
if (!webhook || typeof webhook !== 'object') {
return withCallback(Promise.reject(new Error('webhook object is required')), callback);
return client.reject(new Error('webhook object is required'), callback);
}

const reqOpts = {
uri: api
, json: webhook
};

return withCallback(client.post(reqOpts), callback);
return client.post(reqOpts, callback);
},
/**
* Update an existing relay webhook
Expand All @@ -64,19 +63,19 @@ module.exports = function(client) {
*/
update: function(id, webhook, callback) {
if (!id || typeof id !== 'string') {
return withCallback(Promise.reject(new Error('id is required')), callback);
return client.reject(new Error('id is required'), callback);
}

if (!webhook || typeof webhook !== 'object') {
return withCallback(Promise.reject(new Error('webhook object is required')), callback);
return client.reject(new Error('webhook object is required'), callback);
}

const reqOpts = {
uri: `${api}/${id}`
, json: webhook
};

return withCallback(client.put(reqOpts), callback);
return client.put(reqOpts, callback);
},
/**
* Delete an existing relay webhook
Expand All @@ -87,14 +86,14 @@ module.exports = function(client) {
*/
delete: function(id, callback) {
if (!id || typeof id !== 'string') {
return withCallback(Promise.reject(new Error('id is required')), callback);
return client.reject(new Error('id is required'), callback);
}

const options = {
uri: `${api}/${id}`
};

return withCallback(client.delete(options, callback), callback);
return client.delete(options, callback);
}
};
};
28 changes: 13 additions & 15 deletions lib/sendingDomains.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
'use strict';

const withCallback = require('./Promise');
const api = 'sending-domains';

module.exports = function(client) {

return {
/**
* Lists all sending domains
Expand All @@ -17,7 +15,7 @@ module.exports = function(client) {
uri: api
};

return withCallback(client.get(options), callback);
return client.get(options, callback);
},

/**
Expand All @@ -29,14 +27,14 @@ module.exports = function(client) {
*/
get: function(domain, callback) {
if (!domain || typeof domain === 'function') {
return withCallback(Promise.reject(new Error('domain is required')), callback);
return client.reject(new Error('domain is required'), callback);
}

const options = {
uri: `${api}/${domain}`
};

return withCallback(client.get(options), callback);
return client.get(options, callback);
},

/**
Expand All @@ -48,15 +46,15 @@ module.exports = function(client) {
*/
create: function(createOpts, callback) {
if (!createOpts || typeof createOpts !== 'object') {
return withCallback(Promise.reject(new Error('create options are required')), callback);
return client.reject(new Error('create options are required'), callback);
}

const options = {
uri: api,
json: createOpts
};

return withCallback(client.post(options), callback);
return client.post(options, callback);
},

/**
Expand All @@ -69,19 +67,19 @@ module.exports = function(client) {
*/
update: function(domain, updateOpts, callback) {
if (typeof domain !== 'string') {
return withCallback(Promise.reject(new Error('domain is required')), callback);
return client.reject(new Error('domain is required'), callback);
}

if (!updateOpts || typeof updateOpts !== 'object') {
return withCallback(Promise.reject(new Error('update options are required')), callback);
return client.reject(new Error('update options are required'), callback);
}

const options = {
uri: `${api}/${domain}`,
json: updateOpts
};

return withCallback(client.put(options), callback);
return client.put(options, callback);
},

/**
Expand All @@ -93,14 +91,14 @@ module.exports = function(client) {
*/
delete: function(domain, callback) {
if (typeof domain !== 'string') {
return withCallback(Promise.reject(new Error('domain is required')), callback);
return client.reject(new Error('domain is required'), callback);
}

const options = {
uri: `${api}/${domain}`
};

return withCallback(client.delete(options), callback);
return client.delete(options, callback);
},

/**
Expand All @@ -113,19 +111,19 @@ module.exports = function(client) {
*/
verify: function(domain, options, callback) {
if (typeof domain !== 'string') {
return withCallback(Promise.reject(new Error('domain is required')), callback);
return client.reject(new Error('domain is required'), callback);
}

if (!options || typeof options !== 'object') {
return withCallback(Promise.reject(new Error('verification options are required')), callback);
return client.reject(new Error('verification options are required'), callback);
}

const reqOpts = {
uri: `${api}/${domain}/verify`,
json: options
};

return withCallback(client.post(reqOpts), callback);
return client.post(reqOpts, callback);
}
};

Expand Down
Loading

0 comments on commit fdfa7b9

Please sign in to comment.