File tree Expand file tree Collapse file tree 1 file changed +27
-8
lines changed Expand file tree Collapse file tree 1 file changed +27
-8
lines changed Original file line number Diff line number Diff line change 11# Description:
22# A way to search images on giphy.com
33#
4+ # Configuration:
5+ # HUBOT_GIPHY_API_KEY
6+ #
47# Commands:
58# hubot gif me <query> - Returns an animated gif matching the requested search term.
69
10+ giphy =
11+ api_key : process .env .HUBOT_GIPHY_API_KEY
12+ base_url : ' http://api.giphy.com/v1'
13+
714module .exports = (robot ) ->
815 robot .respond / (gif| giphy)( me)? (. * )/ i , (msg ) ->
916 giphyMe msg, msg .match [3 ], (url ) ->
1017 msg .send url
1118
1219giphyMe = (msg , query , cb ) ->
13- q = q : query
14- msg .http (' http://giphy.com/api/gifs/search' )
15- .query (q)
20+ endpoint = ' /gifs/search'
21+ url = " #{ giphy .base_url }#{ endpoint} "
22+
23+ msg .http (url)
24+ .query
25+ q : query
26+ api_key : giphy .api_key
1627 .get () (err , res , body ) ->
17- response = JSON .parse (body)
18- images = response .data .gifs
19- if images .length > 0
20- image = msg .random images
21- cb image .original_url
28+ response = undefined
29+ try
30+ response = JSON .parse (body)
31+ images = response .data
32+ if images .length > 0
33+ image = msg .random images
34+ cb image .images .original .url
35+
36+ catch e
37+ response = undefined
38+ cb ' Error'
39+
40+ return if response is undefined
You can’t perform that action at this time.
0 commit comments