-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrewerydb.coffee
44 lines (42 loc) · 1.16 KB
/
brewerydb.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Description:
# BreweryDB API
#
# Dependencies:
# None
#
# Configuration:
# BREWERYDB_API_KEY
#
# Commands:
# hubot beer me <beer name> - Information about a beer
#
# Author:
# greggroth
module.exports = (robot) ->
robot.respond /beer me (.*)/i, (msg) ->
unless process.env.BREWERYDB_API_KEY?
msg.send "Please sepcify your BreweyDB API key in BREWERYDB_API_KEY"
return
msg.http("http://api.brewerydb.com/v2/search")
.query
type: "beer"
withBreweries: "Y"
key: process.env.BREWERYDB_API_KEY
q: msg.match[1].replace(" ", "+")
.get() (err, res, body) ->
data = JSON.parse(body)['data']
if data
beer = data[0]
else
msg.send "No beer found"
return
response = beer['name']
if beer['breweries']?
response += " (#{beer['breweries'][0]['name']})"
if beer['style']?
response += "\n#{beer['style']['name']}"
if beer['abv']?
response += "\nABV: #{beer['abv']}%"
if beer['ibu']?
response += "\nIBU: #{beer['ibu']}"
msg.send response