Commit 65fb40b2 by Ben Drucker

Provide a helper fn that strips falsy query params and returns undefined if the object is empty

parent 0f55f7de
......@@ -36,6 +36,11 @@ ClearbitClient.prototype.url = function (options) {
return this.base(options) + options.path;
};
function generateQuery (objects) {
var query = _.pick(_.extend.apply(_, [{}].concat([].slice.apply(arguments))), _.identity);
return _.isEmpty(query) ? undefined : query;
}
ClearbitClient.prototype.request = function (options) {
options = _.defaults(options || {}, {
method: 'get',
......@@ -44,7 +49,7 @@ ClearbitClient.prototype.request = function (options) {
return needle.requestAsync(
options.method,
this.url(options),
_.isEmpty(options.query) ? void 0 : _.extend({
generateQuery({
webhook_id: options.webhook_id
}, options.query),
{
......@@ -57,4 +62,4 @@ ClearbitClient.prototype.request = function (options) {
});
};
module.exports = ClearbitClient;
\ No newline at end of file
module.exports = ClearbitClient;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment