Skip to content

Commit

Permalink
Create giphy.coffee
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreytierney committed Jun 6, 2013
1 parent ac7c4e9 commit 29ac70b
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions giphy.coffee
@@ -0,0 +1,27 @@
# Commands:
# giphy <term> - Returns a randomly selected gif from a search of the giphy api for <term>

giphy =
api_key: process.env.HUBOT_GIPHY_API_KEY
api_url: 'http://api.giphy.com/v1'


search: (msg, q, callback) ->
endpoint = '/gifs/search'
url = "#{giphy.api_url}#{endpoint}"
msg.http(url)
.query
api_key: giphy.api_key
q: q
.get() (err, res, body) ->
res = JSON.parse(body)
data = res?.data || []
if data.length
img_obj = msg.random data
msg.send(img_obj.images.original.url)
else
msg.send "No results found for #{q}"

module.exports = (robot) ->
robot.hear /^giphy (.*)$/i, (msg) ->
giphy.search msg, msg.match[1]

0 comments on commit 29ac70b

Please sign in to comment.