Skip to content

Instantly share code, notes, and snippets.

@commadelimited
Created November 5, 2013 15:51
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save commadelimited/7321142 to your computer and use it in GitHub Desktop.
Save commadelimited/7321142 to your computer and use it in GitHub Desktop.
Athletable Hubot plugin Add your Athletable API key (https://athletable.com/pages/api) on line 20 Upload to your instance of Hubot Paste in a link in the following format: https://athletable.com/sports/9859cd755e/results/1126656
# Description:
# Front end to Athletable API
#
# Dependencies:
# "underscore": "1.5.1"
#
# Configuration:
# HUBOT_ATHLETABLE_API_KEY
#
# Commands:
# None
#
# Author:
# Andy Matthews, @commadelimited
_ = require 'underscore'
module.exports = (robot) ->
# api_key = process.env.HUBOT_ATHLETABLE_API_KEY
api_key = '<your API key>'
robot.hear /https:\/\/athletable\.com\/sports\/[0-9a-z]+\/results\/\d+/i, (msg) ->
# The URLs needed to retrieve the data
raw_url = msg.message.text
final_url = raw_url + '.json?api_key=' + api_key
# Go get the data
msg.http(final_url)
.get() (error, response, body) ->
results = JSON.parse body
winner = _.max results.scores, (player) -> player.score
loser = _.min results.scores, (player) -> player.score
results = winner.player.name + ' defeated ' + loser.player.name + ' ' + winner.score + ' to ' + loser.score
msg.send results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment