forked from twilio/twilio-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kyle Conroy
committed
Sep 15, 2009
0 parents
commit 8a74a70
Showing
24 changed files
with
1,951 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Changelog for Twilio Ruby Gem | ||
================================================= | ||
0.1.2 - Renamed gem |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Copyright (c) 2008 Twilio, Inc. | ||
|
||
Permission is hereby granted, free of charge, to any person | ||
obtaining a copy of this software and associated documentation | ||
files (the "Software"), to deal in the Software without | ||
restriction, including without limitation the rights to use, | ||
copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following | ||
conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
## Ruby Twilio Helper Library | ||
|
||
### DESCRIPTION | ||
The Twilio REST SDK simplifies the process of makes calls to the Twilio REST. | ||
The Twilio REST API lets to you initiate outgoing calls, list previous call, | ||
and much more. See http://www.twilio.com/docs for more information. | ||
|
||
### USAGE | ||
To use the twiliorest.rb library with Rails just copy the twiliorest.rb file | ||
into the lib directory of your Rails application. Then just require | ||
"twiliorest.rb" in the controller or code file you wish to use the Twilio REST | ||
API from. As shown in example.rb, you will need to specify the ACCOUNT_ID and | ||
ACCOUNT_TOKEN given to you by Twilio before you can make REST requests. In | ||
addition, you will need to choose a 'Caller' and 'Called' before making | ||
outgoing calls. See http://www.twilio.com/docs for more information. | ||
|
||
### GEM | ||
|
||
### FILES | ||
lib/twilio.rb -- include this library in your code | ||
example-rest.rb -- example usage of REST | ||
example-twiml.rb -- example usage of the TwiML generator | ||
example-utils.rb -- example usage of utilities | ||
|
||
### LICENSE | ||
The Twilio Ruby Helper Library is distributed under the MIT License | ||
|
||
### THANKS | ||
Jay Philips (@adhearsion) for some great advice | ||
Michael Ansel (@michaelansel) for a great starting point <http://github.com/michaelansel/twilio-rails/tree/master> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require 'rubygems' | ||
require 'rake/gempackagetask' | ||
|
||
spec = Gem::Specification.new do |s| | ||
s.name = "twilio" | ||
s.version = "2.0.0" | ||
s.author = "Kyle Conroy" | ||
s.email = "[email protected]" | ||
s.homepage = "http://www.twilio.com/docs" | ||
s.description = "A Ruby gem for communicating with the Twilio API and generating TwiML" | ||
s.platform = Gem::Platform::RUBY | ||
s.summary = "Some description" | ||
s.files = FileList["{lib}/*"].to_a | ||
s.require_path = "lib" | ||
s.test_files = FileList["{test}/response_spec.rb"].to_a | ||
s.has_rdoc = true | ||
s.extra_rdoc_files = ["README.markdown"] | ||
s.add_dependency("builder", ">= 2.1.2") | ||
end | ||
|
||
Rake::GemPackageTask.new(spec) do |pkg| | ||
pkg.need_tar = true | ||
end | ||
|
||
task :default => "pkg/#{spec.name}-#{spec.version}.gem" do | ||
puts "generated latest version" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require "lib/twilio.rb" | ||
|
||
# Twilio REST API version | ||
API_VERSION = '2008-08-01' | ||
|
||
# Twilio AccountSid and AuthToken | ||
ACCOUNT_SID = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' | ||
ACCOUNT_TOKEN = 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY' | ||
|
||
# Outgoing Caller ID previously validated with Twilio | ||
CALLER_ID = 'NNNNNNNNNN'; | ||
|
||
# Create a Twilio REST account object using your Twilio account ID and token | ||
account = TwilioRest::Account.new(ACCOUNT_SID, ACCOUNT_TOKEN) | ||
|
||
# =========================================================================== | ||
# 1. Initiate a new outbound call to 415-555-1212 | ||
# uses a HTTP POST | ||
d = { | ||
'Caller' => CALLER_ID, | ||
'Called' => '415-555-1212', | ||
'Url' => 'http://demo.twilio.com/welcome', | ||
} | ||
resp = account.request("/#{API_VERSION}/Accounts/#{ACCOUNT_SID}/Calls", | ||
'POST', d) | ||
resp.error! unless resp.kind_of? Net::HTTPSuccess | ||
puts "code: %s\nbody: %s" % [resp.code, resp.body] | ||
|
||
# =========================================================================== | ||
# 2. Get a list of recent completed calls (i.e. Status = 2) | ||
# uses a HTTP GET | ||
d = { 'Status' => 2 } | ||
resp = account.request("/#{API_VERSION}/Accounts/#{ACCOUNT_SID}/Calls", | ||
'GET', d) | ||
resp.error! unless resp.kind_of? Net::HTTPSuccess | ||
puts "code: %s\nbody: %s" % [resp.code, resp.body] | ||
|
||
# =========================================================================== | ||
# 3. Get a list of recent notification log entries | ||
# uses a HTTP GET | ||
resp = account.request("/#{API_VERSION}/Accounts/#{ACCOUNT_SID}/\ | ||
Notifications", 'GET') | ||
resp.error! unless resp.kind_of? Net::HTTPSuccess | ||
puts "code: %s\nbody: %s" % [resp.code, resp.body] | ||
|
||
# =========================================================================== | ||
# 4. Get a list of audio recordings for a certain call | ||
# uses a HTTP GET | ||
d = { 'CallSid' => 'CA5d44cc11756367a4c54e517511484900' } | ||
resp = account.request("/#{API_VERSION}/Accounts/#{ACCOUNT_SID}/Recordings", | ||
'GET', d) | ||
resp.error! unless resp.kind_of? Net::HTTPSuccess | ||
puts "code: %s\nbody: %s" % [resp.code, resp.body] | ||
|
||
# =========================================================================== | ||
# 5. Delete a specific recording | ||
# uses a HTTP DELETE, no response is returned when using DLETE | ||
resp = account.request( \ | ||
"/#{API_VERSION}/Accounts/#{ACCOUNT_SID}/Recordings/\ | ||
RE7b22d733d3e730d234e94242b9697cae", 'DELETE') | ||
puts "code: %s" % [resp.code] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
require "lib/twilio.rb" | ||
|
||
# =========================================================================== | ||
# 1. Say, Dial, and Play | ||
@r = Twilio::Response.new | ||
@r.append(Twilio::Say.new "Hello World", :voice => "man", :loop => "10") | ||
@r.append(Twilio::Dial.new("4155551212", :timeLimit => "45")) | ||
@r.append(Twilio::Play.new("http://www.mp3.com")) | ||
puts @r.respond | ||
|
||
#<Response> | ||
# <Say voice="man" loop="10">Hello World</Say> | ||
# <Play>http://www.mp3.com</Play> | ||
# <Dial timeLimit="45">4155551212</Dial> | ||
#</Response> | ||
|
||
|
||
# =========================================================================== | ||
# 2. Gather, Redirect | ||
@r = Twilio::Response.new; | ||
@g = @r.append(Twilio::Gather.new(:numDigits => "10")) | ||
@g.append(Twilio::Say.new("Press 1")) | ||
@r.append(Twilio::Redirect.new()) | ||
puts @r.respond | ||
|
||
|
||
#<Response> | ||
# <Gather numDigits="1"> | ||
# <Say>Press 1</Say> | ||
# </Gather> | ||
# <Redirect/> | ||
#</Response> | ||
|
||
|
||
# =========================================================================== | ||
# 3. Add a Say verb multiple times | ||
@r = Twilio::Response.new | ||
@say = Twilio::Say.new("Press 1") | ||
@r.append(@say); | ||
@r.append(@say); | ||
puts @r.respond | ||
|
||
#<Response> | ||
# <Say>Press 1</Say> | ||
# <Say>Press 1</Say> | ||
#</Response> | ||
|
||
# =========================================================================== | ||
# 4. Set any attribute / value pair | ||
|
||
@r = Twilio::Response.new | ||
@r.append(Twilio::Redirect.new(:__crazy => "delicious")) | ||
puts @r.respond | ||
|
||
|
||
#<Response> | ||
# <Redirect crazy="delicious"/> | ||
#<Response> | ||
|
||
# =========================================================================== | ||
# 5. Convenience methods | ||
@r = Twilio::Response.new | ||
@r.addSay "Hello World", :voice => "man", :language => "fr", :loop => "10" | ||
@r.addDial "4155551212", :timeLimit => "45" | ||
@r.addPlay "http://www.mp3.com" | ||
puts @r.respond | ||
|
||
#<Response> | ||
# <Say voice="man" language="fr" loop="10">Hello World</Say> | ||
# <Play>http://www.mp3.com</Play> | ||
# <Dial timeLimit="45">4155551212</Dial> | ||
#</Response> | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require "lib/twilio.rb" | ||
|
||
# new Utils Object | ||
utils = Twilio::Utils.new( | ||
|
||
# This is the signature we expect for the key, url, and params below | ||
expected_sig = 'Ma7fvTryuU51vDGO2IT5/KhivpI=' | ||
|
||
# Twilio AccountSid and AuthToken | ||
ACCOUNT_SID = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' | ||
ACCOUNT_TOKEN = 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY' | ||
|
||
# =========================================================================== | ||
# 1. Validate a Twilio request | ||
|
||
# the URL and POST parameters would typically be provided by the web | ||
# framework that is recieving the request from Twilio (e.g. Django) | ||
url = "http://UUUUUUUUUUUUUUUUUU" | ||
postvars = {} | ||
|
||
# the request from Twilio also includes the HTTP header: X-Twilio-Signature | ||
# containing the expected signature | ||
signature = "SSSSSSSSSSSSSSSSSSSSSSSSSSSS" | ||
|
||
# Create a new Utils Object | ||
utils = Twilio::Utils.new(ACCOUNT_SID, ACCOUNT_TOKEN); | ||
|
||
# Check if the signature matches the expected signature | ||
result = utils.validateRequest(signature, url, postvars); | ||
|
||
if result | ||
puts "The signature is valid!" | ||
else | ||
puts "The signature was NOT VALID. It might have been spoofed!" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
K 25 | ||
svn:wc:ra_dav:version-url | ||
V 66 | ||
/twilio/!svn/ver/3533/src/php/www/site/resources/lib/twilio-rb/lib | ||
END | ||
twilio.rb | ||
K 25 | ||
svn:wc:ra_dav:version-url | ||
V 76 | ||
/twilio/!svn/ver/3533/src/php/www/site/resources/lib/twilio-rb/lib/twilio.rb | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
8 | ||
|
||
dir | ||
4035 | ||
https://svn.twilio.com/twilio/src/php/www/site/resources/lib/twilio-rb/lib | ||
https://svn.twilio.com/twilio | ||
|
||
|
||
|
||
2009-07-10T01:45:32.342055Z | ||
3533 | ||
kjconroy | ||
|
||
|
||
svn:special svn:externals svn:needs-lock | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
56c2f7cb-6bf4-4c7c-91e7-2865e9f5b938 | ||
|
||
twilio.rb | ||
file | ||
|
||
|
||
|
||
|
||
2009-07-09T22:19:20.000000Z | ||
87d0549e38874a7b031bf5c51786cb61 | ||
2009-07-10T01:45:32.342055Z | ||
3533 | ||
kjconroy | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
8 |
Oops, something went wrong.