Skip to content

Instantly share code, notes, and snippets.

@cobyism
Created May 13, 2014 12:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cobyism/becdea9e9f9cb6a7d433 to your computer and use it in GitHub Desktop.
Save cobyism/becdea9e9f9cb6a7d433 to your computer and use it in GitHub Desktop.
hubot remote me example.
# make this URL an endpoint that returns something like the users.json file in this gist.
baseUrl = "…"
robot.respond /remote me/i, (msg) ->
if Math.random() < 0.01
msg.send "https://f.cloud.github.com/assets/1476/552951/f1a15572-c370-11e2-8ddd-db568c36d27a.jpg"
return
msg.finish()
msg.http(baseUrl)
.headers(headers)
.get() (err, res, body) ->
if err
console.log(err)
else
try
users = JSON.parse(body).users
catch e
console.log(body)
# This box defines a rectangle considered to be "local".
# In our case it’s roughly SF + Oakland or thereabouts.
theBox =
lats: [ 37.237, 38.050 ],
longs: [ -122.657, -121.671 ]
@remote_people = []
for user in users
if user.last_known_location
local = theBox.lats[0] <= user.last_known_location.lat <= theBox.lats[1] &&
theBox.longs[0] <= user.last_known_location.long <= theBox.longs[1]
@remote_people.push(user.login.toLowerCase()) unless local
names = @remote_people.sort()
names = names.join(', ')
msg.send "Whoa, " + @remote_people.length + "/" + users.length + " meatbags are remote (#{Math.floor(@remote_people.length / users.length * 1000)/10}%)"
msg.send "Remote meatbags: #{names}"
// Have your endpoint return something like this structure.
{
"users": [
{
"login": "…",
"last_known_location": {
"lat": …,
"long": …
}
},
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment