Skip to content

Instantly share code, notes, and snippets.

@nhocki
Created October 22, 2016 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nhocki/86105e7bf41357c3408dd92a5a6bda1b to your computer and use it in GitHub Desktop.
Save nhocki/86105e7bf41357c3408dd92a5a6bda1b to your computer and use it in GitHub Desktop.
Bitly library for Hubot
# Bit.ly shortener
#
# Configuration:
# HUBOT_BITLY_ACCESS_TOKEN
module.exports = (robot) ->
shorten: (url, callback) ->
robot.http("https://api-ssl.bitly.com/v3/shorten")
.query
access_token: process.env.HUBOT_BITLY_ACCESS_TOKEN
format: "json"
longUrl: url
.get() (err, res, body) ->
if err
callback(err, null)
return
response = JSON.parse body
if response.status_code is 200
callback(null, response.data.url)
else
callback({error: response.status_txt}, null)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment