diff --git a/.gitignore b/.gitignore index cba4ce3..b3c9cb1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .DS_Store +.idea *.swp node_modules coverage.html diff --git a/lib/node-trello.js b/lib/node-trello.js index b1b982d..7f8505e 100644 --- a/lib/node-trello.js +++ b/lib/node-trello.js @@ -4,7 +4,7 @@ var OAuth = require("./trello-oauth"); // Creates a new Trello request wrapper. // Syntax: new Trello(applicationApiKey, userToken) -var Trello = module.exports = function (key, token) { +var Trello = module.exports = function (key, token, requestOptions) { if (!key) { throw new Error("Application API key is required"); } @@ -12,6 +12,7 @@ var Trello = module.exports = function (key, token) { this.key = key; this.token = token; this.host = "https://api.trello.com"; + this.requestOptions = requestOptions; }; // Make a GET request to Trello. @@ -61,27 +62,28 @@ Trello.prototype.request = function (method, uri, argsOrCallback, callback) { url += "?" + querystring.stringify(this.addAuthArgs(this.parseQuery(uri, args))); } - var options = { + var options = Object.assign({}, this.requestOptions, { url: url, - method: method - }; - - if (args.attachment) { - options.formData = { - key: this.key, - token: this.token - }; + method: method, + json: true + }); - if (typeof args.attachment === "string" || args.attachment instanceof String) { - options.formData.url = args.attachment; - } - else { - options.formData.file = args.attachment; + if (method !== "GET") { + if (args.attachment) { + options.formData = { + key: this.key, + token: this.token + }; + + if (typeof args.attachment === "string" || args.attachment instanceof String) { + options.formData.url = args.attachment; + } else { + options.formData.file = args.attachment; + } + } else { + options.json = this.addAuthArgs(this.parseQuery(uri, args)); } } - else { - options.json = this.addAuthArgs(this.parseQuery(uri, args)); - } request[method === 'DELETE' ? 'del' : method.toLowerCase()](options, function (err, response, body) { if (!err && response.statusCode >= 400) {