Permalink
Browse files

Made sure to grab only open boards. Added 'since' handling. Needs uni…

…t tests.
  • Loading branch information...
dogeared committed Jan 2, 2013
1 parent d307b68 commit b17a2d4566736e741955f68289ecdc4c3ffc3ee0
Showing with 20 additions and 13 deletions.
  1. +1 −1 features/step_definitions/background_steps.js
  2. +19 −12 lib/trello_events.js
@@ -8,7 +8,7 @@ Given(/^I have connected to the Trello API$/, function(step) {
self.trello = new Trello(settings.key, settings.token)
self.trello.get(
'/1/members/me/boards',
- { fields: 'name' },
+ { fields: 'name', filter: 'open' },
function(err, boards) {
expect(err).to.be(null)
self.boards = boards
View
@@ -1,5 +1,4 @@
var emitter = require('events').EventEmitter
-var util = require('util')
var _ = require('underscore')
var async = require('async')
var Trello = require('node-trello')
@@ -13,16 +12,22 @@ var TrelloEventsClass = function(_key, _token) {
boards = {}
var eventLoop = function(board, callback) {
- //trelloEvents.emit('createList', { a: 'b' })
var processActions = function(err, actions) {
+ if (err) return callback(err)
+ // FIXME: assuming latest action is first
+ if (actions[0]) boards[board].since = actions[0].date
async.forEach(actions, function(action) {
trelloEvents.emit(action.type, action)
- }, function(err) {
- callback()
- })
+ }, callback)
}
- trello.get('/1/boards/' + boards[board] + '/actions', processActions)
+ var since = (boards[board].since) ? {since: boards[board].since} : {}
+ // FIXME: could be bad if unmonitor was called just before we got here
+ trello.get(
+ '/1/boards/' + boards[board].id + '/actions',
+ since,
+ processActions
+ )
}
var startEventLoop = function(board) {
@@ -32,7 +37,7 @@ var TrelloEventsClass = function(_key, _token) {
setTimeout(function() { eventLoop(board, callback) }, 1000)
},
function(err) {
- // event loop done
+ if (err) throw err
}
)
}
@@ -45,18 +50,20 @@ var TrelloEventsClass = function(_key, _token) {
credentials: function() {
return { key: key, token: token }
},
- monitor: function(board) {
+ monitor: function(board, since) {
+ // FIXME: maybe should grab boards at instantiation time?
trello.get(
'/1/members/me/boards',
- {fields: 'name'},
+ {fields: 'name', filter: 'open'},
function(err, _boards) {
- // FIXME
if (err) throw err
var boardInfo = _.find(
_boards,
function(_board) { return _board.name === board }
)
- boards[board] = boardInfo.id
+ boards[board] = {}
+ boards[board].id = boardInfo.id
+ if (since) boards[board].since = since
startEventLoop(board)
}
)
@@ -65,7 +72,7 @@ var TrelloEventsClass = function(_key, _token) {
stopEventLoop(board)
},
monitoring: function(board) {
- return (boards[board])?true:false
+ return boards[board]
}
}
trelloEvents.__proto__ = new emitter()

0 comments on commit b17a2d4

Please sign in to comment.