An alternative to Trello's client.js for interfacing with Trello from the browser, using CORS.
All calls return promises (with lie).
Install with
npm install trello-browser
Trello = require 'trello-browser'trello = TRELLO_API_KEY # doing auth Promiseresolvethen-> # perhaps you have some token stored at localStorage return localStoragegetItem'token'then if existingToken # no need to call auth trellosetTokenexistingToken return trelloauth name: 'My Trello App' scope: read: true write: true account: true expiration: '1hour' # this will open a friendly Trello popup then-> # trello.token will contain the token you got from the user trelloget"/1/tokens//member"fields: 'username,id,email'catch consolelog'something bad happened, or the user took too long to authorize.'
Besides these calls, you can do .get
, .put
, .post
and .del
, for example:
trelloget'/1/boards'thenconsolelogbind consoletrellodel'/1/cards/782346238742'then-> consolelog 'deleted card'trellopost'/1/cards/21838932983/actions/comments'text: 'hello'then-> consolelog 'created comment'trelloput'/1/cards/2342632532532/desc'value: 'hello world!'then-> consolelog 'updated description'
When uploading attachments to /1/cards/:id/attachments
, you can pass a File object or a string to be turned into a file:
file = 'eat tomatoes.'// or file = fileInputfiles0 trellopost'/1/cards/32478324/attachments' name: 'tomato.txt' mimeType: 'text/plain' file: filethenconsolelogbind console