Skip to content
This repository has been archived by the owner on Jun 8, 2023. It is now read-only.

Commit

Permalink
Merge pull request #54 from disorderlyzen/master
Browse files Browse the repository at this point in the history
Adds URL shortener using bit.ly
  • Loading branch information
atmos committed Oct 30, 2011
2 parents 9a8c074 + 8289c35 commit fa1654c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/scripts/shorten.coffee
@@ -0,0 +1,16 @@
# Shorten URLs with bit.ly
#
# (bitly|shorten) me <url> - Shorten the URL using bit.ly

module.exports = (robot) ->
robot.respond /(bitly|shorten) me (.+)$/, (msg) ->
msg
.http("http://api.bitly.com/v3/shorten")
.query
login: process.env.HUBOT_BITLY_USERNAME
apiKey: process.env.HUBOT_BITLY_API_KEY
longUrl: msg.match[2]
format: "json"
.get() (err, res, body) ->
response = JSON.parse body
msg.send if response.status_code is 200 then response.data.url else response.status_txt

0 comments on commit fa1654c

Please sign in to comment.