14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/lita/handlers/animate.rb', line 14
def fetch(response)
query = response.matches[0][0]
http_response = http.get(
URL,
v: "1.0",
q: query,
safe: safe_value,
rsz: 8,
as_filetype: "gif"
)
data = MultiJson.load(http_response.body)
if data["responseStatus"] == 200
choice = data["responseData"]["results"].sample
response.reply "#{choice["unescapedUrl"]}#.gif"
else
reason = data["responseDetails"] || "unknown error"
Lita.logger.warn(
"Couldn't get image from Google: #{reason}"
)
end
end
|