Permalink
Browse files

Merge pull request #3 from sleekslush/master

Shorten URLs using bit.ly
  • Loading branch information...
2 parents b046e2a + c238326 commit c163ae1bfe81d9e318f354e3e93c262b0d50a50b Zakaria Zajac committed Oct 30, 2011
Showing with 16 additions and 0 deletions.
  1. +16 −0 src/scripts/shorten.coffee
View
@@ -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 c163ae1

Please sign in to comment.