├── .gitignore ├── README.md ├── example_backup.js ├── main.js ├── package.json └── tests.js /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.swp 3 | test/ 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Node wrapper for Trello’s HTTP API. 2 | [This project is now maintained by adunkman.](https://github.com/adunkman/node-trello) 3 | 4 | All pull requests and issues should be directed at that repository. -------------------------------------------------------------------------------- /example_backup.js: -------------------------------------------------------------------------------- 1 | var app_key = ''; 2 | var oauth_access_token = ''; 3 | var organization = ''; 4 | 5 | var fs = require('fs'); 6 | var Trello = require("./main.js"); 7 | var t = new Trello(app_key, oauth_access_token); 8 | 9 | t.get("/1/organization/" + organization + "/boards/all", function(err, data) { 10 | if(err) throw err; 11 | for(board in data) { 12 | var board_id = data[board].id; 13 | var board_name = data[board].name; 14 | t.api('/1/board/' + board_id + '/cards/all', function(err, data) { 15 | if(err) throw err; 16 | var filename = board_name + " - " + new Date().toString() + ".json"; 17 | console.log('Backing up ' + data.length + ' cards for board "' + board_name); 18 | 19 | fs.writeFile(filename, JSON.stringify(data), function(err) { 20 | if(err) { 21 | console.log(err); 22 | } else { 23 | console.log("Saved to " + filename); 24 | } 25 | }); 26 | }); 27 | } 28 | }); 29 | -------------------------------------------------------------------------------- /main.js: -------------------------------------------------------------------------------- 1 | var https = require('https'); 2 | var querystring = require('querystring'); 3 | 4 | var trello = function(key, token) { 5 | this.key = key; 6 | this.token = token; 7 | this.host = "api.trello.com"; 8 | }; 9 | 10 | trello.prototype.invokeGeneric = function(method, apiCall, args, callback) { 11 | if (!callback) { 12 | // allow args to be optional and callback passed in its position. 13 | callback = args; 14 | args = {}; 15 | } else { 16 | args = args || {}; 17 | } 18 | 19 | var options = { 20 | host: this.host, 21 | port: 443, 22 | path: apiCall, 23 | method: method 24 | }; 25 | 26 | if(this.key) { 27 | args["key"] = this.key; 28 | } 29 | if(this.token) { 30 | args["token"] = this.token; 31 | } 32 | if (method == 'GET') { 33 | options.path += "?" + querystring.stringify(args); 34 | } else { 35 | post_data = querystring.stringify(args); 36 | options.headers = { 'Content-Type': 'application/x-www-form-urlencoded', 37 | 'Content-Length': post_data.length }; 38 | } 39 | var req = https.request(options, function(res) { 40 | res.setEncoding('utf8'); 41 | var data = ""; 42 | res.on('data', function(d) { 43 | data += d; 44 | }); 45 | res.on("end", function() { 46 | if(res.statusCode !== 200) { 47 | callback(data); 48 | } else { 49 | var j = JSON.parse(data); 50 | callback(false, j); 51 | } 52 | }); 53 | }); 54 | if (method != 'GET') { 55 | req.write(post_data); 56 | } 57 | req.end(); 58 | 59 | req.on('error', function(e) { 60 | throw e; 61 | }); 62 | }; 63 | 64 | trello.prototype.get = trello.prototype.api = function(apiCall, args, callback) { 65 | return this.invokeGeneric('GET', apiCall, args, callback); 66 | }; 67 | 68 | trello.prototype.post = function(apiCall, args, callback) { 69 | return this.invokeGeneric('POST', apiCall, args, callback); 70 | }; 71 | 72 | trello.prototype.put = function(apiCall, args, callback) { 73 | return this.invokeGeneric('PUT', apiCall, args, callback); 74 | }; 75 | 76 | exports = module.exports = trello; 77 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "node-trello" 3 | , "description" : "Node wrapper for Trello's HTTP API." 4 | , "tags" : ["http", "trello", "api", "web-service"] 5 | , "version" : "0.0.1" 6 | , "author" : "Luca Matteis " 7 | , "repository" : 8 | { "type" : "git" 9 | , "url" : "http://github.com/lmatteis/node-trello.git" 10 | } 11 | , "bugs" : 12 | { "url" : "http://github.com/lmatteis/node-trello/issues" } 13 | , "engines" : ["node >= 0.4.7"] 14 | , "main" : "./main" 15 | ,"scripts": { "test": "node tests.js" } 16 | } 17 | -------------------------------------------------------------------------------- /tests.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'), 2 | Trello = require('./main.js'); 3 | 4 | var key = process.argv[2]; 5 | var token = process.argv[3]; 6 | var org = process.argv[4]; 7 | var t = new Trello(key, token); 8 | 9 | // https://trello.com/docs/api/index.html 10 | var tests = { 11 | testParams: function(){ 12 | var args = { foo: "bar", "french":"noob"}; 13 | var query = t.params(args); 14 | var expected = "foo=bar&french=noob"; 15 | assert.equal(query, expected, query + " should be " + expected); 16 | }, 17 | getBoards: function() { 18 | t.get("/1/organization/"+org+"/boards/all", function(err, data) { 19 | if(err) throw err; 20 | assert.ok(data.length > 0); 21 | }); 22 | }, 23 | getBoardsWithArgs: function() { 24 | var args = { fields: "name,desc" }; 25 | t.get("/1/organization/"+org+"/boards/all", args, function(err, data) { 26 | if(err) throw err; 27 | assert.ok(data.length > 0); 28 | // we asked for two fields, but id is always returned, so we look for 3 29 | assert.equal(3, Object.keys(data[0]).length) 30 | }); 31 | } 32 | }; 33 | 34 | 35 | for(var i in tests) { 36 | tests[i](); 37 | } 38 | --------------------------------------------------------------------------------