Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 31 lines (26 sloc) 0.74 kb
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
# Description:
# Grab a Punchform recipe - http://punchfork.com/api
#
# Dependencies:
# None
#
# Configuration:
# HUBOT_PUNCHFORK_APIKEY
#
# Commands:
# hubot cook <ingredent> - Suggest recipe based on ingredent
#
# Author:
# adamstrawson

module.exports = (robot) ->
  robot.respond /cook (.*)$/i, (msg) ->
 
    keyword = "#{msg.match[1]}/"
      
    api_key = process.env.HUBOT_PUNCHFORK_APIKEY

    msg.http("http://api.punchfork.com/recipes?key=#{api_key}&q=#{keyword}&count=1")
      .get() (err, res, body) ->
        if res.statusCode == 404
          msg.send 'No recipe not found.'
        else
          object = JSON.parse(body)
          msg.send object.recipes[0].title
          msg.send object.recipes[0].pf_url
Something went wrong with that request. Please try again.