Skip to content

Commit

Permalink
Made polling interval configurable. Expanded README.
Browse files Browse the repository at this point in the history
  • Loading branch information
dogeared committed Jan 3, 2013
1 parent 06a4473 commit 5552bfb
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 15 deletions.
53 changes: 51 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,55 @@ trelloEvents.monitor('MyBoard')

A complete list of all the actions exposed via the Trello API can be found [here][apidocs]

## TrelloEvents API

### constructor

TrelloEvents uses the module pattern and as such the ```new``` opertor is not needed.

```
var TrelloEventsClass = require('trello_events')
var trelloEvents = TrelloEventsClass(<key>, <token>)
```

### credentials

```
trelloEvents.credentials()
```

returns: { key: <key>, token: <token> }

### monitor

```
trelloEvents.monitor(<board name>, { since: <date>, interval: <millis> })```

This starts an event loop which retrieves Trello actions via the Trello API. Any actions that are retrieved will be emitted as events keyed on the type of action.

The second parameter is optional. If provided, either or both ```since``` and ```interval``` can be provided.

```since``` is a fully qualified date string in the form:
'2013-01-02T19:53:24.930Z'. Trello actions will be retrieved from the time after ```since```, if provided. If not provided, all Trello actions will be retrieved (see Issues below).

```interval``` is the number of milliseconds between the event loop runs. NOTE: If the event loop (which make Trello API calls) runs longer than the interval you specify, the event loop will simply run again immediately. The default value for interval is: 1000

### unmonitor

```
trelloEvents.unmonitor(<board name>)
```

Turns off Trello action monitoring for that specified board.

### monitoring

```
trelloEvents.monitoring(<board name>)
```

returns: true || false

## Setup for running the tests

You'll need to create a ```config/environments/test/settings.js``` based on the example file found there.
Expand All @@ -79,5 +128,5 @@ make

## ToDo/Issues

* The timing of the event loop to check on actions should be configurable
* While TrelloEvents supports monitoring more than one board, emitted events are not board specific
* There is no support for paging and limits right now. If you are looking at a board with tons of actions, some might be missed.
* While TrelloEvents supports monitoring more than one board, emitted events are not board specifici.
5 changes: 1 addition & 4 deletions features/step_definitions/event_steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Given(/^I setup the trello event listener$/, function(step) {

When(/^I check the event information$/, function(step) {
var self = this
self.trelloEvents.monitor(settings.board)
self.trelloEvents.monitor(settings.board, { interval: 1000 })

var checkUnmonitored = function() {
if (!self.trelloEvents.monitoring(settings.board)) {
Expand All @@ -35,9 +35,6 @@ When(/^I check the event information$/, function(step) {
var interval = setInterval(checkMonitored, 200)
});

Then(/^I should see that the lanes were created$/, function(step, table) {
});

Then(/^I should see the event for "([^"]*?)"$/, function(step, lane) {
var self = this
expect(self.action.data.list.name).to.be(lane)
Expand Down
14 changes: 8 additions & 6 deletions lib/trello_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ var async = require('async')
var Trello = require('node-trello')

var TrelloEventsClass = function(_key, _token, testing) {
var key, token, trello, boards, timeout
var key, token, trello, boards, interval

key = _key
token = _token
trello = new Trello(key, token)
boards = {}
timeout = 1000
interval = 10000

var eventLoop = function(board, callback) {
var processActions = function(err, actions) {
Expand All @@ -35,7 +35,7 @@ var TrelloEventsClass = function(_key, _token, testing) {
async.whilst(
function() { return boards[board] },
function(callback) {
setTimeout(function() { eventLoop(board, callback) }, timeout)
setTimeout(function() { eventLoop(board, callback) }, interval)
},
function(err) {
if (err) throw err
Expand All @@ -51,7 +51,7 @@ var TrelloEventsClass = function(_key, _token, testing) {
credentials: function() {
return { key: key, token: token }
},
monitor: function(board, since) {
monitor: function(board, config) {
// FIXME: maybe should grab boards at instantiation time?
trello.get(
'/1/members/me/boards',
Expand All @@ -64,7 +64,10 @@ var TrelloEventsClass = function(_key, _token, testing) {
)
boards[board] = {}
boards[board].id = boardInfo.id
if (since) boards[board].since = since
if (config) {
if (config.since) boards[board].since = config.since
if (config.interval) interval = config.interval
}
startEventLoop(board)
}
)
Expand All @@ -78,7 +81,6 @@ var TrelloEventsClass = function(_key, _token, testing) {
}
if (testing) {
trelloEvents.trello = function() { return trello }
timeout = 10
}
trelloEvents.__proto__ = new emitter()
emitter.call(trelloEvents)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "trello_tools",
"version": "0.0.2",
"version": "0.0.3",
"dependencies": {
"async": "0.1.22",
"node-trello": "0.1.3",
Expand Down
5 changes: 3 additions & 2 deletions test/unit/trello_events.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('When working with Trello events', function() {

it('properly handles all events ', function(done) {
var self = this
self.trelloEvents.monitor('MyBoard')
self.trelloEvents.monitor('MyBoard', { interval: 10 })
setTimeout(function() {
self.trelloEvents.unmonitor('MyBoard')
expect(self.eventCounters).to.eql(self.expectedEventCounters)
Expand All @@ -81,7 +81,8 @@ describe('When working with Trello events', function() {
self.expectedEventCounters.createBoard = 0
self.expectedEventCounters.createList = 1
self.trelloEvents.monitor(
'MyBoard', '2013-01-02T19:53:24.930Z'
'MyBoard',
{ since: '2013-01-02T19:53:24.930Z', interval: 10 }
)
setTimeout(function() {
self.trelloEvents.unmonitor('MyBoard')
Expand Down

0 comments on commit 5552bfb

Please sign in to comment.