Skip to content

Instantly share code, notes, and snippets.

@loisaidasam
Last active May 25, 2016 15:45
Show Gist options
  • Select an option

  • Save loisaidasam/7f267105aba2eb191fbf66e0b16766af to your computer and use it in GitHub Desktop.

Select an option

Save loisaidasam/7f267105aba2eb191fbf66e0b16766af to your computer and use it in GitHub Desktop.
Hubot script to help you figure out what to eat for lunch (based on a foursquare list)
# Description:
# Figure out what to eat for lunch!
#
# Dependencies:
# None
#
# Configuration:
# FOURSQUARE_CLIENT_ID - a foursquare app's client id
# FOURSQUARE_CLIENT_SECRET - a foursquare app's client secret
# FOURSQUARE_LIST_ID - a foursquare list id
#
# Commands:
# hubot lunch
#
# References:
# https://developer.foursquare.com/docs/lists/lists
# https://developer.foursquare.com/docs/users/lists
# https://foursquare.com/loisaidasam/list/hifi-lunch-eats
# http://theprogrammingbutler.com/blog/archives/2011/10/28/hubot-scripts-explained/
#
# Author:
# @LoisaidaSam
CLIENT_ID = process.env.FOURSQUARE_CLIENT_ID
CLIENT_SECRET = process.env.FOURSQUARE_CLIENT_SECRET
LIST_ID = process.env.FOURSQUARE_LIST_ID
BASE_URL = "https://api.foursquare.com"
API_VERSION = "20140401"
https = require 'https'
module.exports = (robot) ->
robot.respond /lunch/, (msg) ->
search_for_venues (venues) ->
chosen_venue = msg.random venues
venue = chosen_venue['venue']
venue.url = "https://foursquare.com/v/#{venue.id}"
msg.send "How about #{venue.name}: #{venue.url}"
search_for_venues = (callback) ->
params =
host:'api.foursquare.com'
path: "/v2/lists/#{LIST_ID}?v=#{API_VERSION}&client_id=#{CLIENT_ID}&client_secret=#{CLIENT_SECRET}"
method: 'GET'
result = ""
request = https.get(params)
request.on 'response', (res) ->
res.on 'data', (data) ->
result += data
res.on 'end', ->
venues = JSON.parse(result)['response']['list']['listItems']['items']
callback(venues)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment