This repository has been archived by the owner on Sep 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
66 lines (48 loc) · 1.69 KB
/
app.rb
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require 'rubygems'
require 'sinatra'
require 'tropo-webapi-ruby'
require 'httparty'
require 'logger'
require 'net/http'
require 'uri'
use Rack::Session::Pool
get '/' do
"Hello World"
end
post '/start.json' do
tropo_session = Tropo::Generator.parse request.env["rack.input"].read
session[:callid] = tropo_session[:session][:id]
session[:truck_name] = 'not found'
tropo = Tropo::Generator.new do
ask( :name => 'truck', :bargein => true, :timeout => 60, :attempts => 2,
:say => [{:event => "timeout", :value => "Sorry, I did not hear anything."},
{:event => "nomatch:1 nomatch:2", :value => "Oops, I don't recognize that food truck'."},
{:value => "Which food truck do you want?"}],
:choices => { :value => "ken-jeez, calvins, gordmelt"})
on :event=>'continue', :next => "/process_truck.json"
end
tropo.response
end
post '/hangup.json' do
say "Thanks for nomming."
end
post '/the_answer.json' do
say "Test Answer"
end
post '/process_truck.json' do
tropo_session = Tropo::Generator.parse request.env["rack.input"].read
truck = tropo_session[:result][:actions][:truck][:value]
puts "Chosen truck: " + truck
tropo = Tropo::Generator.new do
say "You chose " + truck
if truck == "ken-jeez" then
foodtruckId = "4e4b3ef6aeb72792c3381b27"
puts "KENJI Routing..."
urlToGo = "http://api.foursquare.com/v2/venues/" +foodtruckId + "?client_id=" + ENV['FOURSQUARE_CLIENT_ID'] + "&client_secret=" + ENV['FOURSQUARE_CLIENT_SECRET']
puts "URLTOGO: " + urlToGo
foursquareInfo = JSON.parse(open(urlToGo).read)
puts "FOURSQUAREINFO: " + foursquareInfo
end
end
tropo.response
end