Skip to content
This repository was archived by the owner on Aug 7, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
.idea
*.swp
node_modules
coverage.html
38 changes: 20 additions & 18 deletions lib/node-trello.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ 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");
}

this.key = key;
this.token = token;
this.host = "https://api.trello.com";
this.requestOptions = requestOptions;
};

// Make a GET request to Trello.
Expand Down Expand Up @@ -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) {
Expand Down