Created
July 25, 2012 09:05
-
-
Save leggetter/3175204 to your computer and use it in GitHub Desktop.
This file contains 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
;( function( $ ) { | |
var pusher; | |
function init() { | |
pusher = new Pusher(PUSHER_CONFIG.APP_KEY); | |
} | |
$(init); | |
} )( jQuery ); |
This file contains 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/base' | |
require 'yaml' | |
require 'pusher' | |
class App < Sinatra::Base | |
set :public_folder, Proc.new { File.join(root, "public") } | |
config = YAML.load_file('./config.yml') | |
get '/' do | |
@app_key = config['pusher']['app_key'] | |
erb :index | |
end | |
run! if app_file == $0 | |
end |
This file contains 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
var pusher, | |
smsChannel, | |
activeCallChannel; | |
function init() { | |
pusher = new Pusher(PUSHER_CONFIG.APP_KEY); | |
smsChannel = pusher.subscribe('sms'); | |
smsChannel.bind('sms_received', function( data ) { | |
var li = $('<li>').text( 'From: ' + data.from_number + | |
' Text: ' + data.text + | |
' Time: ' + data.timestamp ); | |
$('#sms_messages').prepend( li ); | |
} ); | |
activeCallChannel = pusher.subscribe('calls'); | |
activeCallChannel.bind('call_incoming', function( data ) { | |
var li = $('<li>').text( 'From: ' + data.from_number + | |
' Time: ' + data.timestamp ); | |
$('#incoming_calls').prepend( li ); | |
} ); | |
} |
This file contains 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 '/call' do | |
if( params['AccountSid'] != config['twilio']['account_sid'] ) | |
status 401 | |
else | |
# allow | |
end | |
end | |
post '/sms' do | |
if( params['AccountSid'] != config['twilio']['account_sid'] ) | |
status 401 | |
else | |
# allow | |
end | |
end |
This file contains 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
Pusher.app_id = config['pusher']['app_id'] | |
Pusher.key = config['pusher']['app_key'] | |
Pusher.secret = config['pusher']['app_secret'] |
This file contains 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 '/call' do | |
if( params['AccountSid'] != config['twilio']['account_sid'] ) | |
status 401 | |
else | |
Pusher['calls'].trigger('call_incoming', { | |
:from_number => '...' + params['From'][-4, 4], | |
:timestamp => Time.now.strftime("%Y-%m-%dT%H:%M:%S") | |
}) | |
end | |
end | |
post '/sms' do | |
if( params['AccountSid'] != config['twilio']['account_sid'] ) | |
status 401 | |
else | |
Pusher['sms'].trigger('sms_received', { | |
:from_number => '...' + params['From'][-4, 4], | |
:timestamp => Time.now.strftime("%Y-%m-%dT%H:%M:%S"), | |
:text => params['Body'] | |
}) | |
end | |
end |
This file contains 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
pusher: | |
app_id: <YOUR_APP_ID> | |
app_key: <YOUR_APP_KEY> | |
app_secret: <YOUR_APP_SECRET> | |
twilio: | |
account_sid: <YOUR_TWILIO_ACCOUNT_SID> |
This file contains 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
source 'http://rubygems.org' | |
gem 'sinatra' | |
gem 'sinatra-contrib' | |
gem 'pusher' |
This file contains 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<title>Pusher & Twilio Example</title> | |
</head> | |
<body> | |
Hello, Pusher & Twilio | |
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script> | |
<script src="http://js.pusher.com/1.12/pusher.min.js"></script> | |
<script> | |
var PUSHER_CONFIG = { | |
APP_KEY: '<%= @app_key %>' | |
}; | |
</script> | |
<script src="js/app.js"></script> | |
</body> | |
</html> |
This file contains 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
<div> | |
<h3>SMS</h3> | |
<ul id="sms_messages"></ul> | |
</div> | |
<div> | |
<h3>Incoming Calls</h3> | |
<ul id="incoming_calls"></ul> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment