Created
July 29, 2012 10:50
-
-
Save kevinprince/3197535 to your computer and use it in GitHub Desktop.
Source for dotbox
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 'sinatra' | |
require 'httparty' | |
require 'json' | |
require 'twilio-ruby' | |
get '/' do | |
"This is an action server for iftxttt" | |
end | |
post '/olympics' do | |
puts params.inspect | |
response = HTTParty.get('http://hosted.stats.com/olympics/medals_widget/data.asp') | |
result = JSON.parse(response.body) | |
request.body.rewind | |
data = JSON.parse request.body.read | |
country = data['content'].upcase | |
team = result['medals'][country].first | |
"Current result for Team #{country} - Gold: #{team['gold']} Silver: #{team['silver']} Bronze: #{team['bronze']}" | |
end | |
post '/help' do | |
call_now '' | |
end | |
post '/script' do | |
response = Twilio::TwiML::Response.new do |r| | |
r.Pause '5' | |
r.Say '9 1 1 Operator', :voice => 'man' | |
r.Pause '1' | |
r.Say 'What is your emergency?', :voice => 'man' | |
end | |
# print the result | |
response.text | |
end | |
post '/panic' do | |
phones = [] | |
phones.each do |phone| | |
call_now phone | |
end | |
end | |
post '/prank' do | |
3.times do | |
send_text_message('') | |
end | |
end | |
def call_now(number = '') | |
account_sid = '' | |
auth_token = '' | |
# set up a client to talk to the Twilio REST API | |
@client = Twilio::REST::Client.new account_sid, auth_token | |
call = @client.account.calls.create( | |
:from => '', | |
:to => number, | |
:url => 'http://dottxt.herokuapp.com/script' | |
) | |
end | |
def send_text_message(number = '') | |
account_sid = '' | |
auth_token = '' | |
@twilio_client = Twilio::REST::Client.new account_sid, auth_token | |
@twilio_client.account.sms.messages.create( | |
:from => "", | |
:to => number, | |
:body => "Bacon, Bacon, Bacon, Bacon, Bacon, Bacon, Bacon, Bacon, Bacon, Bacon, Bacon, Bacon, Bacon, Bacon, Bacon, Bacon, Bacon, Bacon, Bacon, Bacon." | |
) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment