Skip to content
This repository has been archived by the owner on Mar 17, 2020. It is now read-only.

Commit

Permalink
They see me callin'
Browse files Browse the repository at this point in the history
  • Loading branch information
dpritchett committed Jan 21, 2012
0 parents commit d92ad78
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source 'http://rubygems.org'
gem 'sinatra'
gem 'twilio-ruby'
27 changes: 27 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
GEM
remote: http://rubygems.org/
specs:
builder (3.0.0)
json (1.6.5)
jwt (0.1.4)
json (>= 1.2.4)
multi_json (1.0.4)
rack (1.4.0)
rack-protection (1.2.0)
rack
sinatra (1.3.2)
rack (~> 1.3, >= 1.3.6)
rack-protection (~> 1.2)
tilt (~> 1.3, >= 1.3.3)
tilt (1.3.3)
twilio-ruby (3.5.0)
builder (>= 2.1.2)
jwt (>= 0.1.2)
multi_json (>= 1.0.3)

PLATFORMS
ruby

DEPENDENCIES
sinatra
twilio-ruby
8 changes: 8 additions & 0 deletions app.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
load 'twilio-say.rb'
require 'sinatra'

get '/call/:number' do
"""Calls a phone number, plays some sad Vader."""
Caller.new("http://#{request.host}:#{request.port.to_s}").dial(params[:number])
"Now dialing #{params[:number]}..."
end
8 changes: 8 additions & 0 deletions app.rb~
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
load 'twilio-say.rb'
require 'sinatra'

get '/call/:number' do
"""Calls a phone number, plays some sad Vader."""
Caller.new("http://#{request.host}:#{request.port.to_s}").dial(params[:number])
"Now dialing #{params[:number]}..."
end
2 changes: 2 additions & 0 deletions config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require './app.rb'
run Sinatra::Application
3 changes: 3 additions & 0 deletions public/twiml/call.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Response>
<Play>http://m.friendfeed-media.com/57d6847c57fc04e8d640cea86741c147461cfa38</Play>
</Response>
Empty file added tmp/restart.txt
Empty file.
35 changes: 35 additions & 0 deletions twilio-say.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'twilio-ruby'

class Caller
"""
Twilio API phone caller / SMS dialer.
Darth Vader is gonna call and let me know when I hit the wrong key in vim.
"""
def initialize(hostname)
"""
For this to work you'll need to host a valid TwiML call script at hostname/public/twiml/call.xml.
"""
@client = Twilio::REST::Client.new ENV['TWILIO_ACCOUNT_SID'],
ENV['TWILIO_AUTH_TOKEN']

@from = @client.account.incoming_phone_numbers.list.first.phone_number
@url = hostname
end

def sms(to_number, message)
@client.account.sms.messages.create(
:from => @from,
:to => "+1" + to_number.to_s,
:body => message.to_s)
end

def dial(to_number)
@client.account.calls.create(
:from => @from,
:to => "+1" + to_number.to_s,
:url => @url + "/twiml/call.xml",
:method => 'GET'
)
end
end
35 changes: 35 additions & 0 deletions twilio-say.rb~
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'twilio-ruby'

class Caller
"""
Twilio API phone caller / SMS dialer.

Darth Vader is gonna call and let me know when I hit the wrong key in vim.
"""
def initialize(hostname)
"""
For this to work you'll need to host a valid TwiML call script at hostname/public/twiml/call.xml.
"""
@client = Twilio::REST::Client.new ENV['TWILIO_ACCOUNT_SID'],
ENV['TWILIO_AUTH_TOKEN']

@from = @client.account.incoming_phone_numbers.list.first.phone_number
@url = hostname
end

def sms(to_number, message)
@client.account.sms.messages.create(
:from => @from,
:to => "+1" + to_number.to_s,
:body => message.to_s)
end

def call(to_number)
@client.account.calls.create(
:from => @from,
:to => "+1" + to_number.to_s,
:url => @url + "/twiml/call.xml",
:method => 'GET'
)
end
end

1 comment on commit d92ad78

@dpritchett
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit is for @jetpackjarrett

Please sign in to comment.