Skip to content

Instantly share code, notes, and snippets.

@johndbritton
Created April 15, 2011 08:12
Show Gist options
  • Save johndbritton/921366 to your computer and use it in GitHub Desktop.
Save johndbritton/921366 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'sinatra'
require 'builder'
require 'sunlight'
set :sunlight_key, ENV['sunlight_key']
post '/' do
builder :welcome
end
post '/people' do
if params[:FromZip] then
Sunlight::Base.api_key = settings.sunlight_key
@members_of_congress = Sunlight::Legislator.all_in_zipcode(params[:FromZip])
builder :people
else
redirect '/nozip'
end
end
post '/nozip' do
builder :nozip
end
post '/dial' do
if params[:FromZip] then
Sunlight::Base.api_key = settings.sunlight_key
members_of_congress = Sunlight::Legislator.all_in_zipcode(params[:FromZip])
@member = members_of_congress[params[:Digits].to_i-1]
builder :dial
else
redirect '/nozip'
end
end
post '/' do
builder :welcome
end
xml.instruct!
xml.Response do
xml.Say("Thanks for using Call Congress.")
xml.Say("We make it easy to contact Senators and Representatives from your part of the country.")
xml.Redirect("/people")
end
post '/people' do
if params[:FromZip] then
Sunlight::Base.api_key = settings.sunlight_key
@members_of_congress = Sunlight::Legislator.all_in_zipcode(params[:FromZip])
builder :people
else
redirect '/nozip'
end
end
xml.instruct!
xml.Response do
xml.Say("Here's a list of your Senators and Representatives, select who you'd like to connect to.")
xml.Gather(:action => "/dial", :numDigits => "1") do
@members_of_congress.each_with_index do |member, index|
xml.Say("Press #{index+1} for " + member.firstname + " " + member.lastname)
end
end
xml.Redirect("/people")
end
post '/dial' do
if params[:FromZip] then
Sunlight::Base.api_key = settings.sunlight_key
members_of_congress = Sunlight::Legislator.all_in_zipcode(params[:FromZip])
@member = members_of_congress[params[:Digits].to_i-1]
builder :dial
else
redirect '/nozip'
end
end
xml.instruct!
xml.Response do
xml.Say("Please wait while we connect you to " + @member.firstname + " " + @member.lastname)
xml.Dial(@member.phone)
xml.Hangup
end
xml.instruct!
xml.Response do
xml.Say("We couldn't detect your zipcode, so we're connecting you to the main Congress switchboard in Washington, DC.")
xml.Dial("2022253121")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment