Add first attempt at Alexa support.

This commit is contained in:
Darren VanBuren 2017-02-06 01:08:07 -08:00
parent be0b0b49c2
commit dde0224208

View file

@ -1,5 +1,6 @@
require 'camping' require 'camping'
require 'newrelic_rpm' require 'newrelic_rpm'
require 'json'
# Camping is a great small framework. # Camping is a great small framework.
Camping.goes :StargateRando Camping.goes :StargateRando
@ -52,6 +53,61 @@ module StargateRando::Controllers
render :results render :results
end end
end end
class Alexa < R '/alexa'
def get
post()
end
def post
series_selector = 1 + rand(17)
case series_selector
when 1..10
chosen_series_id = 'SG-1'
when 11..15
chosen_series_id = 'SGA'
else
chosen_series_id = 'SGU'
end
@series = Data::SERIES_NAMES[chosen_series_id]
num_seasons = Data::SEASONS_PER_SERIES[chosen_series_id]
chosen_season = 1 + rand(num_seasons)
# SG-1 has a couple of seasons of length 22 and one of length 21 so we need to handle that.
case chosen_series_id
when 'SG-1'
case chosen_season
when 1
num_episodes = 21
when 2..7
num_episodes = 22
else
num_episodes = 20
end
else
num_episodes = 20
end
chosen_episode = 1 + rand(num_episodes)
@headers['Content-Type'] = "application/json"
@episode_and_season = "Season #{chosen_season} Episode #{chosen_episode}"
@episode_name = Data::EPISODES["#{chosen_series_id}|#{chosen_season}x#{chosen_episode}"]
result_hash = {:version => "1.0", :response => {
:outputSpeech => {
:type => "PlainText",
:text => "You should watch: #{@series}: #{@episode_and_season}: #{@episode_name}"
},
:shouldEndSession => true
}
}
JSON.generate(result_hash)
end
end
end end
# This holds our views. Markaby is pretty swagtacular. # This holds our views. Markaby is pretty swagtacular.
@ -77,7 +133,7 @@ module StargateRando::Views
end end
p do p do
span do span do
"Perhaps you might want to check out " "Perhaps you might want to check out "
end end
a :href => "stargateorder.html" do a :href => "stargateorder.html" do