Permalink
Browse files

Fixed imgur script to use new imgur api

I was getting weird redirects using the current script.  This one utilizes the
v3 api published by imgur.  It now requires you create an application and
generaate a Client-ID oath2 token.
  • Loading branch information...
1 parent e703a81 commit 19d2a21fb26dd7f5b3e4cc8669253bde425e8b55 @mattikus mattikus committed Dec 19, 2012
Showing with 10 additions and 5 deletions.
  1. +10 −5 src/scripts/imgur-info.coffee
@@ -5,23 +5,28 @@
# None
#
# Configuration:
-# None
+# HUBOT_IMGUR_CLIENTID - your client id from imgur
#
# Commands:
# None
#
# Notes:
# For text-based adapters like IRC.
+# You'll need to generate a Client-ID at:
+# https://api.imgur.com/oauth2/addclient
#
# Author:
# mmb
+token = "Client-ID #{process.env.HUBOT_IMGUR_CLIENTID}"
+
module.exports = (robot) ->
- robot.hear /http:\/\/(?:i\.)?imgur\.com\/(?:gallery\/)?([a-z\d]+)(?:\.(?:gif|jpe?g|png))?/i, (msg) ->
- api_url = "http://imgur.com/gallery/#{msg.match[1]}.json"
- msg.http(api_url).get() (err, res, body) ->
+ robot.hear /(?:http:\/\/)?(?:i\.)?imgur\.com\/(a\/)?(\w+)(?:\.(?:gif|jpe?g|png))?/i, (msg) ->
+ type = if msg.match[1]? then 'gallery' else 'image'
+ api_url = "https://api.imgur.com/3/#{type}/#{msg.match[2]}/"
+ msg.http(api_url).headers('Authorization': token).get() (err, res, body) ->
if res.statusCode is 200
data = JSON.parse(body)
- msg.send "imgur: #{data.data.image.title}"
+ msg.send "imgur: #{data.data.title}"
else
console.error "imgur-info script error: #{api_url} returned #{res.statusCode}: #{body}"

0 comments on commit 19d2a21

Please sign in to comment.