Created
April 15, 2011 08:12
-
-
Save johndbritton/921366 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
post '/' do | |
builder :welcome | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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