Created
May 2, 2012 14:09
-
-
Save seanhess/2576781 to your computer and use it in GitHub Desktop.
trello campfire
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
request = require 'request' | |
# curl -u TOKEN:X -H 'Content-Type: application/json' -d '{"message":{"body":"Hello"}}' https://DOMAIN.campfirenow.com/room/ROOMID/speak.json | |
exports.room = room = (account, room, token) -> | |
send = (message, cb) -> | |
query = | |
url: "https://#{token}:X@#{account}.campfirenow.com/room/#{room}/speak.json" | |
json: | |
message: | |
body: message | |
#console.log "SENDING", query | |
request.post query, (err, rs, body) -> | |
if err? then return cb err | |
if rs.statusCode != 200 then return cb(new Error(rs.statusCode + " " + body)) | |
cb null, body | |
{send} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://trello.com/docs/api/index.html | |
# https://trello.com/1/appKey/generate | |
# https://trello.com/docs/gettingstarted/index.html#getting-a-token-from-a-user | |
request = require 'request' | |
{map, filter} = require 'underscore' | |
moment = require 'moment' | |
events = require 'events' | |
# https://api.trello.com/1/members/me/boards?key=KEY&token=TOKEN | |
# https://trello.com/1/connect?key=KEY&name=MyApp&response_type=token (gives you the oauth token you need to access stuffz) | |
exports.listen = listen = (endpoint, key, token, boardId, poll) -> | |
check = -> | |
# round! | |
start = lastPeriod poll | |
since = moment.utc(new Date(start)).format() | |
send "/boards/#{boardId}/actions", {filter: "commentCard", since}, (err, items) -> | |
if err? then return emitter.emit 'err', err | |
actions = map items, newAction | |
recent = filter actions, (action) -> withinPeriod start, poll, action | |
#console.log("RECENT COMMENTS!", recent) | |
emitter.emit 'comments', recent | |
send = (url, params, cb) -> | |
params.key = key | |
params.token = token | |
#console.log "SEND " + url, params, new Date() | |
request.get {url: endpoint + url, qs: params, json:true}, (err, rs, body) -> | |
if err? then return cb err | |
if rs.statusCode != 200 then return cb new Error(rs.statusCode + " " + body) | |
cb err, body | |
process.nextTick check | |
setInterval check, poll*1000 | |
emitter = new events.EventEmitter() | |
class Action | |
constructor: (item) -> | |
@text = item.data.text | |
@cardId = item.data.card.idShort | |
@cardName = item.data.card.name | |
@boardId = item.data.board.id | |
@user = item.memberCreator.fullName | |
@date = new Date(item.date) | |
cardUrl: -> "https://trello.com/card/x/#{@boardId}/#{@cardId}" | |
newAction = (item) -> new Action item | |
lastPeriod = (poll) -> | |
pollms = poll * 1000 | |
ago = Date.now() - pollms | |
rounded = ago - (ago % pollms) | |
withinPeriod = (start, poll, action) -> | |
start < action.date.getTime() < (start + poll*1000) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment