Created
October 22, 2016 18:10
-
-
Save nhocki/86105e7bf41357c3408dd92a5a6bda1b to your computer and use it in GitHub Desktop.
Bitly library for Hubot
This file contains 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
# 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