Permalink
Browse files

Version 3.0.0 - see changelog for new and breaking changes

  • Loading branch information...
1 parent 393d907 commit 564d99add6b40699e0cdffda318b03ff03a07cb0 @philm philm committed Mar 26, 2011
Showing with 877 additions and 944 deletions.
  1. +27 −0 CHANGELOG.rdoc
  2. +1 −6 Gemfile
  3. +16 −4 README.rdoc
  4. +5 −32 Rakefile
  5. +0 −5 VERSION.yml
  6. +18 −4 lib/twilio.rb
  7. +1 −1 lib/twilio/account.rb
  8. +15 −13 lib/twilio/available_phone_numbers.rb
  9. +4 −4 lib/twilio/call.rb
  10. +6 −6 lib/twilio/conference.rb
  11. +0 −26 lib/twilio/connection.rb
  12. +16 −2 lib/twilio/incoming_phone_number.rb
  13. +0 −26 lib/twilio/local_phone_number.rb
  14. +2 −2 lib/twilio/notification.rb
  15. +5 −4 lib/twilio/outgoing_caller_id.rb
  16. +2 −2 lib/twilio/recording.rb
  17. +2 −2 lib/twilio/sms.rb
  18. +0 −26 lib/twilio/toll_free_phone_number.rb
  19. +8 −5 lib/twilio/twilio_object.rb
  20. +1 −1 lib/twilio/version.rb
  21. +23 −0 spec/fixtures/xml/account.xml
  22. 0 {test → spec}/fixtures/xml/account_renamed.xml
  23. 0 {test → spec}/fixtures/xml/available_phone_numbers_local.xml
  24. 0 {test → spec}/fixtures/xml/available_phone_numbers_local_search.xml
  25. 0 {test → spec}/fixtures/xml/available_phone_numbers_toll_free.xml
  26. 0 {test → spec}/fixtures/xml/available_phone_numbers_toll_free_search.xml
  27. 0 {test → spec}/fixtures/xml/call.xml
  28. 0 {test → spec}/fixtures/xml/call_new.xml
  29. 0 {test → spec}/fixtures/xml/call_redirected.xml
  30. 0 {test → spec}/fixtures/xml/calls.xml
  31. +1 −1 {test → spec}/fixtures/xml/conference.xml
  32. 0 {test → spec}/fixtures/xml/conference_participant.xml
  33. 0 {test → spec}/fixtures/xml/conference_participant_muted.xml
  34. 0 {test → spec}/fixtures/xml/conference_participants.xml
  35. 0 {test → spec}/fixtures/xml/conferences.xml
  36. 0 {test → spec}/fixtures/xml/incoming_phone_number.xml
  37. 0 {test → spec}/fixtures/xml/incoming_phone_numbers.xml
  38. 0 {test → spec}/fixtures/xml/notification.xml
  39. 0 {test → spec}/fixtures/xml/notifications.xml
  40. 0 {test → spec}/fixtures/xml/outgoing_caller_id.xml
  41. 0 {test → spec}/fixtures/xml/outgoing_caller_id_new.xml
  42. 0 {test → spec}/fixtures/xml/outgoing_caller_ids.xml
  43. 0 {test → spec}/fixtures/xml/recording.xml
  44. 0 {test → spec}/fixtures/xml/recordings.xml
  45. 0 {test → spec}/fixtures/xml/sms.xml
  46. 0 {test → spec}/fixtures/xml/sms_messages.xml
  47. 0 {test → spec}/fixtures/xml/sms_new.xml
  48. 0 {test → spec}/fixtures/xml/sms_new_with_callback.xml
  49. 0 {test → spec}/fixtures/xml/transcription.xml
  50. 0 {test → spec}/fixtures/xml/transcriptions.xml
  51. 0 {test → spec}/fixtures/yml/verb_responses.yml
  52. +17 −0 spec/spec_helper.rb
  53. +52 −0 spec/support/twilio_helpers.rb
  54. +21 −0 spec/twilio/account_spec.rb
  55. +53 −0 spec/twilio/available_phone_numbers_spec.rb
  56. +64 −0 spec/twilio/call_spec.rb
  57. +58 −0 spec/twilio/conference_spec.rb
  58. +42 −0 spec/twilio/incoming_phone_number_spec.rb
  59. +21 −0 spec/twilio/live_connection_spec.rb
  60. +29 −0 spec/twilio/notification_spec.rb
  61. +43 −0 spec/twilio/outgoing_caller_id_spec.rb
  62. +44 −0 spec/twilio/recording_spec.rb
  63. +36 −0 spec/twilio/sms_spec.rb
  64. +235 −0 spec/twilio/verb_spec.rb
  65. +0 −11 test/fixtures/xml/account.xml
  66. +0 −33 test/test_helper.rb
  67. +0 −28 test/twilio/account_test.rb
  68. +0 −43 test/twilio/available_phone_numbers_test.rb
  69. +0 −66 test/twilio/call_test.rb
  70. +0 −46 test/twilio/conference_test.rb
  71. +0 −25 test/twilio/connection_test.rb
  72. +0 −31 test/twilio/incoming_phone_number_test.rb
  73. +0 −37 test/twilio/local_phone_number_test.rb
  74. +0 −35 test/twilio/notification_test.rb
  75. +0 −45 test/twilio/outgoing_caller_id_test.rb
  76. +0 −47 test/twilio/recording_test.rb
  77. +0 −27 test/twilio/sms_test.rb
  78. +0 −38 test/twilio/toll_free_phone_number_test.rb
  79. +0 −244 test/twilio/verb_test.rb
  80. +9 −16 twilio.gemspec
View
27 CHANGELOG.rdoc
@@ -0,0 +1,27 @@
+= Twilio Gem Changelog
+
+== 3.0
+
+* SSL validation (thanks Kyle Humberto)
+* Available phone numbers search support (thanks Mark Turner)
+* Deprecated Twilio::Connection method has been removed, use Twilio.connect(...)
+* LocalPhoneNumber and TollFreeNumber have been removed to reflect API changes
+* New phone numbers are now provisioned via the IncomingPhoneNumber class
+* Several classes improved to avoid adding a stray "?" when no params were set
+* Compatibility with 1.9.2 (and tested on 1.8.7 MRI and REE)
+* Now uses Bundler, Rspec 2, and WebMock
+
+== 2.9
+
+* Compatibility with Twilio's 2010-04-01 API publish
+
+== 2.8
+
+* SMS callback URLs
+* Ability to delete phone numbers
+
+== 2.7
+
+* SMS functionality
+
+For earlier versions, see https://github.com/webficient/twilio/commits/master
View
7 Gemfile
@@ -1,9 +1,4 @@
source "http://rubygems.org"
# Specify your gem's dependencies in twilio.gemspec
-gemspec
-
-group :test do
- gem 'fakeweb'
- gem 'shoulda'
-end
+gemspec
View
20 README.rdoc
@@ -34,14 +34,26 @@ and you can nest multiple verbs inside a block:
== Installation
- sudo gem install twilio -s http://gemcutter.org
+ gem install twilio
-If you need to tweak the source code, clone this repository and do a rake build and rake install.
+== Contributing
+
+1. Run 'bundle' from the command line to install dependencies
+2. Write test(s) for your patch
+3. Submit a pull request
+
+Note: don't require 'rubygems' in any file (http://www.rubyinside.com/why-using-require-rubygems-is-wrong-1478.html)
== Copyright
-Copyright (c) 2009-2010 Phil Misiowiec, Webficient LLC. See LICENSE for details.
+Copyright (c) 2009-2011 Phil Misiowiec, Webficient LLC. See LICENSE for details.
== Contributors
-Kyle Daigle, Yuri Gadow, Jonathan Rudenberg, Jeff Wigal, Alex K Wolfe
+* Kyle Daigle
+* Yuri Gadow
+* Kyle Humberto
+* Jonathan Rudenberg
+* Mark Turner
+* Jeff Wigal
+* Alex K Wolfe
View
37 Rakefile
@@ -1,36 +1,9 @@
-require "rubygems"
-begin
-require 'bundler'
+require 'bundler/setup'
Bundler::GemHelper.install_tasks
-rescue LoadError
- puts "bundler not installed"
-end
-require 'rake/rdoctask'
-Rake::RDocTask.new do |rdoc|
- rdoc.rdoc_dir = 'rdoc'
- rdoc.title = 'twilio'
- rdoc.options << '--line-numbers' << '--inline-source'
- rdoc.rdoc_files.include('README*')
- rdoc.rdoc_files.include('lib/**/*.rb')
-end
+require 'rake'
+require 'rspec/core/rake_task'
-require 'rake/testtask'
-Rake::TestTask.new(:test) do |test|
- test.libs << 'lib' << 'test'
- test.pattern = 'test/**/*_test.rb'
- test.verbose = false
-end
+RSpec::Core::RakeTask.new
-begin
- require 'rcov/rcovtask'
- Rcov::RcovTask.new do |test|
- test.libs << 'test'
- test.pattern = 'test/**/*_test.rb'
- test.verbose = true
- end
-rescue LoadError
- task :rcov do
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
- end
-end
+task :default => :spec
View
5 VERSION.yml
@@ -1,5 +0,0 @@
----
-:major: 2
-:build:
-:minor: 9
-:patch: 0
View
22 lib/twilio.rb
@@ -23,17 +23,31 @@
require 'httparty'
require 'builder'
+
require 'twilio/twilio_object'
+
require 'twilio/account'
require 'twilio/available_phone_numbers'
require 'twilio/call'
require 'twilio/conference'
-require 'twilio/connection'
require 'twilio/incoming_phone_number'
-require 'twilio/local_phone_number'
require 'twilio/notification'
require 'twilio/outgoing_caller_id'
require 'twilio/recording'
require 'twilio/sms'
-require 'twilio/toll_free_phone_number'
-require 'twilio/verb'
+require 'twilio/verb'
+
+module Twilio
+ include HTTParty
+ TWILIO_URL = "https://api.twilio.com/2010-04-01/Accounts"
+ SSL_CA_PATH = "/etc/ssl/certs"
+
+ # The connect method caches your Twilio account id and authentication token
+ # Example:
+ # Twilio.connect('AC309475e5fede1b49e100272a8640f438', '3a2630a909aadbf60266234756fb15a0')
+ def self.connect(account_sid, auth_token)
+ self.base_uri "#{TWILIO_URL}/#{account_sid}"
+ self.basic_auth account_sid, auth_token
+ self.default_options[:ssl_ca_path] ||= SSL_CA_PATH unless self.default_options[:ssl_ca_file]
+ end
+end
View
2 lib/twilio/account.rb
@@ -2,7 +2,7 @@ module Twilio
# The Account resource represents your Twilio Account.
class Account < TwilioObject
def get
- Twilio.get('')
+ Twilio.get('')
end
def update_name(name)
View
28 lib/twilio/available_phone_numbers.rb
@@ -11,19 +11,21 @@ class AvailablePhoneNumbers < TwilioObject
# numbers.
def search(opts={})
iso_country_code = opts[:iso_country_code] || 'US'
- resource = opts[:resource]
- Twilio.get("/AvailablePhoneNumbers/#{iso_country_code}/#{resource}",
- :query => {
- :AreaCode => opts[:area_code],
- :InPostalCode => opts[:postal_code],
- :InRegion => opts[:in_region],
- :Contains => opts[:contains],
- :NearLatLong => opts[:near_lat_long],
- :NearNumber => opts[:near_number],
- :InLata => opts[:in_lata],
- :InRateCenter => opts[:in_rate_center],
- :Distance => opts[:distance]
- }.reject {|k,v| v == nil})
+ resource = opts.delete(:resource)
+
+ params = {
+ :AreaCode => opts[:area_code],
+ :InPostalCode => opts[:postal_code],
+ :InRegion => opts[:in_region],
+ :Contains => opts[:contains],
+ :NearLatLong => opts[:near_lat_long],
+ :NearNumber => opts[:near_number],
+ :InLata => opts[:in_lata],
+ :InRateCenter => opts[:in_rate_center],
+ :Distance => opts[:distance]
+ }.reject {|k,v| v == nil} unless opts.empty?
+
+ Twilio.get("/AvailablePhoneNumbers/#{iso_country_code}/#{resource}", :query => params)
end
# The search_local method searches for numbers in local areas (i.e. state, zip, etc..)
View
8 lib/twilio/call.rb
@@ -6,12 +6,12 @@ class Call < TwilioObject
# Example:
# Twilio.connect('my_twilio_sid', 'my_auth_token')
# Twilio::Call.make(CALLER_ID, user_number, 'http://myapp.com/twilio_response_handler')
- def make(from, to, url, optional = {})
- Twilio.post("/Calls", :body => {:From => from, :To => to, :Url => url}.merge(optional))
+ def make(from, to, url, opts = {})
+ Twilio.post("/Calls", :body => {:From => from, :To => to, :Url => url}.merge(opts))
end
- def list(optional = {})
- Twilio.get("/Calls", :query => optional)
+ def list(opts = {})
+ Twilio.get("/Calls", :query => (opts.empty? ? nil : opts))
end
def get(call_sid)
View
12 lib/twilio/conference.rb
@@ -4,20 +4,20 @@ module Twilio
# a Conference Instance Resource is created to represent the conference room
# and a Participant Instance Resource is created to represent the caller who joined.
class Conference < TwilioObject
- def list(optional = {})
- Twilio.get("/Conferences", :query => optional)
+ def list(opts = {})
+ Twilio.get("/Conferences", :query => (opts.empty? ? nil : opts))
end
def get(conference_sid)
- Twilio.get("/Conferences/#{conference_sid}")
+ Twilio.get("/Conferences/#{conference_sid}")
end
- def participants(conference_sid, optional = {})
- Twilio.get("/Conferences/#{conference_sid}/Participants", :query => optional)
+ def participants(conference_sid, opts = {})
+ Twilio.get("/Conferences/#{conference_sid}/Participants", :query => (opts.empty? ? nil : opts))
end
def participant(conference_sid, call_sid)
- Twilio.get("/Conferences/#{conference_sid}/Participants/#{call_sid}")
+ Twilio.get("/Conferences/#{conference_sid}/Participants/#{call_sid}")
end
def mute_participant(conference_sid, call_sid)
View
26 lib/twilio/connection.rb
@@ -1,26 +0,0 @@
-module Twilio
- include HTTParty
- TWILIO_URL = "https://api.twilio.com/2010-04-01/Accounts"
- SSL_CA_PATH = "/etc/ssl/certs"
- # The connect method caches your Twilio account id and authentication token
- # Example:
- # Twilio.connect('AC309475e5fede1b49e100272a8640f438', '3a2630a909aadbf60266234756fb15a0')
- def self.connect(account_sid, auth_token)
- self.base_uri "#{TWILIO_URL}/#{account_sid}"
- self.basic_auth account_sid, auth_token
- self.default_options[:ssl_ca_path] ||= SSL_CA_PATH unless self.default_options[:ssl_ca_file]
- end
-
- # DEPRECATED - use Twilio.connect
- class Connection
- include HTTParty
- TWILIO_URL = "https://api.twilio.com/2008-08-01/Accounts"
-
- def initialize(account_sid, auth_token)
- self.class.base_uri "#{TWILIO_URL}/#{account_sid}"
- self.class.basic_auth account_sid, auth_token
- self.class.default_options[:ssl_ca_path] ||= SSL_CA_PATH unless self.class.default_options[:ssl_ca_file]
- end
- end
-
-end
View
18 lib/twilio/incoming_phone_number.rb
@@ -5,12 +5,26 @@ module Twilio
# Twilio.connect('my_twilio_sid', 'my_auth_token')
# Twilio::IncomingPhoneNumber.list
class IncomingPhoneNumber < TwilioObject
- def list(optional = {})
- Twilio.get("/IncomingPhoneNumbers", :query => optional)
+ def list(opts = {})
+ Twilio.get("/IncomingPhoneNumbers", :query => (opts.empty? ? nil : opts))
end
def get(incoming_sid)
Twilio.get("/IncomingPhoneNumbers/#{incoming_sid}")
end
+
+ # Creates a phone number in Twilio. You must first find an existing number using
+ # the AvailablePhoneNumber class before creating one here.
+ #
+ # Required: you must either set PhoneNumber or AreaCode as a required option
+ # For additional options, see http://www.twilio.com/docs/api/rest/incoming-phone-numbers
+ def create(opts)
+ raise "You must set either :PhoneNumber or :AreaCode" if !opts.include?(:AreaCode) && !opts.include?(:PhoneNumber)
+ Twilio.post("/IncomingPhoneNumbers", :body => opts)
+ end
+
+ def delete(incoming_sid)
+ Twilio.delete("/IncomingPhoneNumbers/#{incoming_sid}")
+ end
end
end
View
26 lib/twilio/local_phone_number.rb
@@ -1,26 +0,0 @@
-module Twilio
- # This sub-resource represents only Local phone numbers, or in other words, not toll-free numbers.
- # Also allows you to request a new local phone number be added to your account.
- # Example:
- # Twilio.connect('my_twilio_sid', 'my_auth_token')
- # Twilio::LocalPhoneNumber.list
- class LocalPhoneNumber < TwilioObject
- def create(url, area_code = nil, method = 'POST', friendly_name = nil, options = {})
- Twilio.post("/IncomingPhoneNumbers/Local", :body => {
- :VoiceUrl => url,
- :AreaCode => area_code,
- :VoiceMethod => method,
- :FriendlyName => friendly_name
- }.merge(options))
- end
-
- def list
- Twilio.get("/IncomingPhoneNumbers/Local")
- end
-
- def delete(phone_number_sid)
- Twilio.delete("/IncomingPhoneNumbers/#{phone_number_sid}")
- end
-
- end
-end
View
4 lib/twilio/notification.rb
@@ -5,8 +5,8 @@ module Twilio
# Twilio.connect('my_twilio_sid', 'my_auth_token')
# Twilio::Notification.list
class Notification < TwilioObject
- def list(optional = {})
- Twilio.get('/Notifications', :query => optional)
+ def list(opts = {})
+ Twilio.get('/Notifications', :query => (opts.empty? ? nil : opts))
end
def get(notification_sid)
View
9 lib/twilio/outgoing_caller_id.rb
@@ -5,16 +5,17 @@ module Twilio
# Twilio.connect('my_twilio_sid', 'my_auth_token')
# Twilio::OutgoingCallerId.list
class OutgoingCallerId < TwilioObject
- def create(phone_number, friendly_name = phone_number, call_delay = 0)
+ def create(phone_number, friendly_name = phone_number, call_delay = 0, extension = nil)
Twilio.post("/OutgoingCallerIds", :body => {
:PhoneNumber => phone_number,
:FriendlyName => friendly_name,
- :CallDelay => call_delay
+ :CallDelay => call_delay,
+ :Extension => extension
})
end
- def list(optional = {})
- Twilio.get("/OutgoingCallerIds", :query => optional)
+ def list(opts = {})
+ Twilio.get("/OutgoingCallerIds", :query => (opts.empty? ? nil : opts))
end
def get(callerid_sid)
View
4 lib/twilio/recording.rb
@@ -5,8 +5,8 @@ module Twilio
# Twilio.connect('my_twilio_sid', 'my_auth_token')
# Twilio::Recording.list
class Recording < TwilioObject
- def list(optional = {})
- Twilio.get("/Recordings", :query => optional)
+ def list(opts = {})
+ Twilio.get("/Recordings", :query => (opts.empty? ? nil : opts))
end
def get(recording_sid)
View
4 lib/twilio/sms.rb
@@ -10,8 +10,8 @@ def message(from, to, body, callback_url=nil)
Twilio.post("/SMS/Messages", :body => {:From => from, :To => to, :Body => body}.merge(callback))
end
- def list(optional = {})
- Twilio.get("/SMS/Messages", :query => optional)
+ def list(opts = {})
+ Twilio.get("/SMS/Messages", :query => (opts.empty? ? nil : opts))
end
def get(sms_message_sid)
View
26 lib/twilio/toll_free_phone_number.rb
@@ -1,26 +0,0 @@
-module Twilio
- # This sub-resource represents only Toll Free phone numbers, or in other words, not local numbers.
- # Also allows you to request a new toll free phone number be added to your account.
- # Example:
- # Twilio.connect('my_twilio_sid', 'my_auth_token')
- # Twilio::TollFreePhoneNumber.list
- class TollFreePhoneNumber < TwilioObject
- def create(url, area_code = nil, method = 'POST', friendly_name = nil)
- Twilio.post("/IncomingPhoneNumbers/TollFree", :body => {
- :VoiceUrl => url,
- :AreaCode => area_code,
- :VoiceMethod => method,
- :FriendlyName => friendly_name
- })
- end
-
- def list
- Twilio.get("/IncomingPhoneNumbers/TollFree")
- end
-
- def delete(phone_number_sid)
- Twilio.delete("/IncomingPhoneNumbers/#{phone_number_sid}")
- end
-
- end
-end
View
13 lib/twilio/twilio_object.rb
@@ -1,16 +1,19 @@
module Twilio
- class TwilioObject #:nodoc: all
- attr_reader :connection
-
- def initialize(connection = nil)
- @connection = connection
+ class TwilioObject #:nodoc: all
+ def initialize
end
class << self
def method_missing(method_id, *args) #:nodoc:
o = self.new
o.send(method_id, *args)
+ rescue HTTParty::UnsupportedURIScheme
+ raise "You must set Twilio.connect before calling #{self.inspect}##{method_id}"
end
end
+
+ def connected?
+ self.class.base_uri
+ end
end
end
View
2 lib/twilio/version.rb
@@ -1,3 +1,3 @@
module Twilio
- VERSION = "2.8.1"
+ VERSION = "3.0.0"
end
View
23 spec/fixtures/xml/account.xml
@@ -0,0 +1,23 @@
+<TwilioResponse>
+ <Account>
+ <Sid>mysid</Sid>
+ <FriendlyName>Do you like my friendly name?</FriendlyName>
+ <Status>active</Status>
+ <DateCreated>Wed, 04 Aug 2010 21:37:41 +0000</DateCreated>
+ <DateUpdated>Fri, 06 Aug 2010 01:15:02 +0000</DateUpdated>
+ <AuthToken>mytoken</AuthToken>
+ <Uri>/2010-04-01/Accounts/ACba8bc05eacf94afdae398e642c9cc32d</Uri>
+ <SubresourceUris>
+ <AvailablePhoneNumbers>/2010-04-01/Accounts/ACba8bc05eacf94afdae398e642c9cc32d/AvailablePhoneNumbers</AvailablePhoneNumbers>
+ <Calls>/2010-04-01/Accounts/ACba8bc05eacf94afdae398e642c9cc32d/Calls</Calls>
+ <Conferences>/2010-04-01/Accounts/ACba8bc05eacf94afdae398e642c9cc32d/Conferences</Conferences>
+ <IncomingPhoneNumbers>/2010-04-01/Accounts/ACba8bc05eacf94afdae398e642c9cc32d/IncomingPhoneNumbers</IncomingPhoneNumbers>
+ <Notifications>/2010-04-01/Accounts/ACba8bc05eacf94afdae398e642c9cc32d/Notifications</Notifications>
+ <OutgoingCallerIds>/2010-04-01/Accounts/ACba8bc05eacf94afdae398e642c9cc32d/OutgoingCallerIds</OutgoingCallerIds>
+ <Recordings>/2010-04-01/Accounts/ACba8bc05eacf94afdae398e642c9cc32d/Recordings</Recordings>
+ <Sandbox>/2010-04-01/Accounts/ACba8bc05eacf94afdae398e642c9cc32d/Sandbox</Sandbox>
+ <SMSMessages>/2010-04-01/Accounts/ACba8bc05eacf94afdae398e642c9cc32d/SMS/Messages</SMSMessages>
+ <Transcriptions>/2010-04-01/Accounts/ACba8bc05eacf94afdae398e642c9cc32d/Transcriptions</Transcriptions>
+ </SubresourceUris>
+ </Account>
+</TwilioResponse>
View
0 test/fixtures/xml/account_renamed.xml → spec/fixtures/xml/account_renamed.xml
File renamed without changes.
View
0 ...res/xml/available_phone_numbers_local.xml → ...res/xml/available_phone_numbers_local.xml
File renamed without changes.
View
0 .../available_phone_numbers_local_search.xml → .../available_phone_numbers_local_search.xml
File renamed without changes.
View
0 ...xml/available_phone_numbers_toll_free.xml → ...xml/available_phone_numbers_toll_free.xml
File renamed without changes.
View
0 ...ilable_phone_numbers_toll_free_search.xml → ...ilable_phone_numbers_toll_free_search.xml
File renamed without changes.
View
0 test/fixtures/xml/call.xml → spec/fixtures/xml/call.xml
File renamed without changes.
View
0 test/fixtures/xml/call_new.xml → spec/fixtures/xml/call_new.xml
File renamed without changes.
View
0 test/fixtures/xml/call_redirected.xml → spec/fixtures/xml/call_redirected.xml
File renamed without changes.
View
0 test/fixtures/xml/calls.xml → spec/fixtures/xml/calls.xml
File renamed without changes.
View
2 test/fixtures/xml/conference.xml → spec/fixtures/xml/conference.xml
@@ -1,6 +1,6 @@
<TwilioResponse>
<Conference>
- <Sid>CFd0a50bbe038c437e87f6c82db8f37f21</Sid>
+ <Sid>CF9f2ead1ae43cdabeab102fa30d938378</Sid>
<AccountSid>mysid</AccountSid>
<FriendlyName>1234</FriendlyName>
<Status>2</Status>
View
0 test/fixtures/xml/conference_participant.xml → spec/fixtures/xml/conference_participant.xml
File renamed without changes.
View
0 ...ures/xml/conference_participant_muted.xml → ...ures/xml/conference_participant_muted.xml
File renamed without changes.
View
0 .../fixtures/xml/conference_participants.xml → .../fixtures/xml/conference_participants.xml
File renamed without changes.
View
0 test/fixtures/xml/conferences.xml → spec/fixtures/xml/conferences.xml
File renamed without changes.
View
0 test/fixtures/xml/incoming_phone_number.xml → spec/fixtures/xml/incoming_phone_number.xml
File renamed without changes.
View
0 test/fixtures/xml/incoming_phone_numbers.xml → spec/fixtures/xml/incoming_phone_numbers.xml
File renamed without changes.
View
0 test/fixtures/xml/notification.xml → spec/fixtures/xml/notification.xml
File renamed without changes.
View
0 test/fixtures/xml/notifications.xml → spec/fixtures/xml/notifications.xml
File renamed without changes.
View
0 test/fixtures/xml/outgoing_caller_id.xml → spec/fixtures/xml/outgoing_caller_id.xml
File renamed without changes.
View
0 test/fixtures/xml/outgoing_caller_id_new.xml → spec/fixtures/xml/outgoing_caller_id_new.xml
File renamed without changes.
View
0 test/fixtures/xml/outgoing_caller_ids.xml → spec/fixtures/xml/outgoing_caller_ids.xml
File renamed without changes.
View
0 test/fixtures/xml/recording.xml → spec/fixtures/xml/recording.xml
File renamed without changes.
View
0 test/fixtures/xml/recordings.xml → spec/fixtures/xml/recordings.xml
File renamed without changes.
View
0 test/fixtures/xml/sms.xml → spec/fixtures/xml/sms.xml
File renamed without changes.
View
0 test/fixtures/xml/sms_messages.xml → spec/fixtures/xml/sms_messages.xml
File renamed without changes.
View
0 test/fixtures/xml/sms_new.xml → spec/fixtures/xml/sms_new.xml
File renamed without changes.
View
0 test/fixtures/xml/sms_new_with_callback.xml → spec/fixtures/xml/sms_new_with_callback.xml
File renamed without changes.
View
0 test/fixtures/xml/transcription.xml → spec/fixtures/xml/transcription.xml
File renamed without changes.
View
0 test/fixtures/xml/transcriptions.xml → spec/fixtures/xml/transcriptions.xml
File renamed without changes.
View
0 test/fixtures/yml/verb_responses.yml → spec/fixtures/yml/verb_responses.yml
File renamed without changes.
View
17 spec/spec_helper.rb
@@ -0,0 +1,17 @@
+require 'bundler'
+Bundler.setup
+
+require 'twilio'
+
+require 'support/twilio_helpers'
+require 'webmock/rspec'
+
+RSpec.configure do |config|
+ config.include TwilioHelpers
+ config.before(:suite) do
+ WebMock.disable_net_connect!
+ end
+ config.after(:suite) do
+ WebMock.allow_net_connect!
+ end
+end
View
52 spec/support/twilio_helpers.rb
@@ -0,0 +1,52 @@
+module TwilioHelpers #:nodoc:
+
+ def stub_http_request(http_method, fixture_name, *opts)
+ if opts
+ request_options = opts.pop if opts.last.is_a?(Hash)
+ resource = opts.pop
+ end
+
+ fake_response = fixture(fixture_name)
+ url = twilio_url(resource)
+
+ if request_options
+ stub_request(http_method, url).with(request_options).to_return(:body => fake_response)
+ else
+ stub_request(http_method, url).to_return(:body => fake_response)
+ end
+
+ return fake_response, url
+ end
+
+ def stub_get(fixture, *opts)
+ stub_http_request(:get, fixture, *opts)
+ end
+
+ def stub_post(fixture, *opts)
+ stub_http_request(:post, fixture, *opts)
+ end
+
+ def stub_put(fixture, *opts)
+ stub_http_request(:put, fixture, *opts)
+ end
+
+ def stub_delete(fixture, *opts)
+ stub_http_request(:delete, fixture, *opts)
+ end
+
+ def verb_response(verb)
+ path = File.join(File.dirname(__FILE__), "../fixtures/yml/verb_responses.yml")
+ YAML.load_file(path)[verb.to_s]['response']
+ end
+
+ private
+
+ def twilio_url(url=nil)
+ "https://mysid:mytoken@api.twilio.com:443/2010-04-01/Accounts/mysid#{'/' + url if url}"
+ end
+
+ def fixture(filename)
+ path = File.join(File.dirname(__FILE__), "../fixtures/xml/#{filename}.xml")
+ File.read path
+ end
+end
View
21 spec/twilio/account_spec.rb
@@ -0,0 +1,21 @@
+require 'spec_helper'
+
+describe 'Account' do
+ before(:all) do
+ Twilio.connect('mysid', 'mytoken')
+ end
+
+ it "gets an account" do
+ response, url = stub_get(:account)
+
+ Twilio::Account.get.should == response
+ WebMock.should have_requested(:get, twilio_url)
+ end
+
+ it "updates name" do
+ response, url = stub_put(:account_renamed)
+
+ Twilio::Account.update_name('Bubba').should == response
+ WebMock.should have_requested(:put, twilio_url).with(:body => {:FriendlyName => 'Bubba'})
+ end
+end
View
53 spec/twilio/available_phone_numbers_spec.rb
@@ -0,0 +1,53 @@
+require 'spec_helper'
+
+describe "Available Phone Numbers" do
+ before(:all) do
+ Twilio.connect('mysid', 'mytoken')
+ end
+
+ context "Local Number" do
+ it "is searchable" do
+ response, url = stub_get(:available_phone_numbers_local, 'AvailablePhoneNumbers/US/Local')
+
+ Twilio::AvailablePhoneNumbers.search_local.should == response
+ WebMock.should have_requested(:get, url)
+ end
+
+ it "is searchable by area code" do
+ response, url = stub_get(:available_phone_numbers_local_search, 'AvailablePhoneNumbers/US/Local?AreaCode=510')
+
+ Twilio::AvailablePhoneNumbers.search_local(:area_code => 510).should == response
+ WebMock.should have_requested(:get, url)
+ end
+
+ it "is searchable by postal code" do
+ response, url = stub_get(:available_phone_numbers_local_search, 'AvailablePhoneNumbers/US/Local?InPostalCode=94612')
+
+ Twilio::AvailablePhoneNumbers.search_local(:postal_code => 94612).should == response
+ WebMock.should have_requested(:get, url)
+ end
+
+ it "is searchable using multiple parameters" do
+ response, url = stub_get(:available_phone_numbers_local_search, 'AvailablePhoneNumbers/US/Local?NearLatLong=37.806940%2C-122.270360&InRateCenter=OKLD0349T&NearNumber=15105551213&Distance=50&InRegion=CA&InLata=722&Contains=510555****')
+
+ Twilio::AvailablePhoneNumbers.search_local(:in_region => 'CA', :contains => '510555****', :near_lat_long => '37.806940,-122.270360', :near_number => '15105551213', :in_lata => 722, :in_rate_center => 'OKLD0349T', :distance => 50).should == response
+ WebMock.should have_requested(:get, url)
+ end
+ end
+
+ context "Toll-free Number" do
+ it "is searchable" do
+ response, url = stub_get(:available_phone_numbers_toll_free, 'AvailablePhoneNumbers/US/TollFree')
+
+ Twilio::AvailablePhoneNumbers.search_toll_free.should == response
+ WebMock.should have_requested(:get, url)
+ end
+
+ it "is searchable as a vanity number" do
+ response, url = stub_get(:available_phone_numbers_toll_free_search, 'AvailablePhoneNumbers/US/TollFree?Contains=STORM')
+
+ Twilio::AvailablePhoneNumbers.search_toll_free(:contains => 'STORM').should == response
+ WebMock.should have_requested(:get, url)
+ end
+ end
+end
View
64 spec/twilio/call_spec.rb
@@ -0,0 +1,64 @@
+require 'spec_helper'
+
+describe "Call" do
+ before(:all) do
+ Twilio.connect('mysid', 'mytoken')
+ @call_sid = 'CA42ed11f93dc08b952027ffbc406d0868'
+ end
+
+ it "can be made" do
+ response, url = stub_post(:call_new, 'Calls')
+
+ Twilio::Call.make('4158675309', '4155551212', 'http://localhost:3000/call_handler').should == response
+ WebMock.should have_requested(:post, url)
+ end
+
+ it "can be redirected" do
+ response, url = stub_post(:call_redirected, "Calls/#{@call_sid}")
+
+ Twilio::Call.redirect(@call_sid, 'http://localhost:3000/redirect_handler').should == response
+ WebMock.should have_requested(:post, url)
+ end
+
+ it "gets a list of calls" do
+ response, url = stub_get(:calls, 'Calls')
+
+ Twilio::Call.list.should == response
+ WebMock.should have_requested(:get, url)
+ end
+
+ it "gets a specific call" do
+ response, url = stub_get(:calls, "Calls/#{@call_sid}")
+
+ Twilio::Call.get(@call_sid).should == response
+ WebMock.should have_requested(:get, url)
+ end
+
+ it "gets a list of call segments" do
+ response, url = stub_get(:calls, "Calls/#{@call_sid}/Segments")
+
+ Twilio::Call.segments(@call_sid).should == response
+ WebMock.should have_requested(:get, url)
+ end
+
+ it "gets a specific call segment" do
+ response, url = stub_get(:calls, "Calls/#{@call_sid}/Segments/abc123")
+
+ Twilio::Call.segments(@call_sid, 'abc123').should == response
+ WebMock.should have_requested(:get, url)
+ end
+
+ it "gets a list of call recordings" do
+ response, url = stub_get(:recordings, "Calls/#{@call_sid}/Recordings")
+
+ Twilio::Call.recordings(@call_sid).should == response
+ WebMock.should have_requested(:get, url)
+ end
+
+ it "gets a list of call notifications" do
+ response, url = stub_get(:notifications, "Calls/#{@call_sid}/Notifications")
+
+ Twilio::Call.notifications(@call_sid).should == response
+ WebMock.should have_requested(:get, url)
+ end
+end
View
58 spec/twilio/conference_spec.rb
@@ -0,0 +1,58 @@
+require 'spec_helper'
+
+describe "Conference" do
+ before(:all) do
+ Twilio.connect('mysid', 'mytoken')
+ @conference_sid = 'CF9f2ead1ae43cdabeab102fa30d938378'
+ @call_sid = 'CA9ae8e040497c0598481c2031a154919e'
+ end
+
+ it "gets a list of conferences" do
+ response, url = stub_get(:conferences, 'Conferences')
+
+ Twilio::Conference.list.should == response
+ WebMock.should have_requested(:get, url)
+ end
+
+ it "gets a specific conference" do
+ response, url = stub_get(:conference, "Conferences/#{@conference_sid}")
+
+ Twilio::Conference.get(@conference_sid).should == response
+ WebMock.should have_requested(:get, url)
+ end
+
+ it "gets a list of participants" do
+ response, url = stub_get(:conference_participants, "Conferences/#{@conference_sid}/Participants")
+
+ Twilio::Conference.participants(@conference_sid).should == response
+ WebMock.should have_requested(:get, url)
+ end
+
+ it "gets a specific participant" do
+ response, url = stub_get(:conference_participant, "Conferences/#{@conference_sid}/Participants/#{@call_sid}")
+
+ Twilio::Conference.participant(@conference_sid, @call_sid).should == response
+ WebMock.should have_requested(:get, url)
+ end
+
+ it "can mute a particant" do
+ response, url = stub_post(:conference_participant_muted, "Conferences/#{@conference_sid}/Participants/#{@call_sid}", :body => 'Muted=true')
+
+ Twilio::Conference.mute_participant(@conference_sid, @call_sid).should == response
+ WebMock.should have_requested(:post, url)
+ end
+
+ it "can unmute a participant" do
+ response, url = stub_post(:conference_participant, "Conferences/#{@conference_sid}/Participants/#{@call_sid}", :body => 'Muted=false')
+
+ Twilio::Conference.unmute_participant(@conference_sid, @call_sid).should == response
+ WebMock.should have_requested(:post, url)
+ end
+
+ it "can be kicked" do
+ response, url = stub_delete(:conference_participant, "Conferences/#{@conference_sid}/Participants/#{@call_sid}")
+
+ Twilio::Conference.kick_participant(@conference_sid, @call_sid).should == response
+ WebMock.should have_requested(:delete, url)
+ end
+end
View
42 spec/twilio/incoming_phone_number_spec.rb
@@ -0,0 +1,42 @@
+require 'spec_helper'
+
+describe "Incoming Phone Number" do
+ before(:all) do
+ Twilio.connect('mysid', 'mytoken')
+ @incoming_sid = 'PNe536dfda7c6184afab78d980cb8cdf43'
+ end
+
+ it "gets a specific phone number" do
+ response, url = stub_get(:incoming_phone_number, "IncomingPhoneNumbers/#{@incoming_sid}")
+
+ Twilio::IncomingPhoneNumber.get(@incoming_sid).should == response
+ WebMock.should have_requested(:get, url)
+ end
+
+ it "gets a list of phone numbers" do
+ response, url = stub_get(:incoming_phone_numbers, 'IncomingPhoneNumbers')
+
+ Twilio::IncomingPhoneNumber.list.should == response
+ WebMock.should have_requested(:get, url)
+ end
+
+ context "creating" do
+ it "is created" do
+ response, url = stub_post(:incoming_phone_number, 'IncomingPhoneNumbers')
+
+ Twilio::IncomingPhoneNumber.create(:PhoneNumber => '8055551212').should == response
+ WebMock.should have_requested(:post, url)
+ end
+
+ it "raises an exception if PhoneNumber or AreaCode are not set" do
+ expect { Twilio::IncomingPhoneNumber.create(:FriendlyName => 'Booyah') }.to raise_exception
+ end
+ end
+
+ it "is deleted" do
+ response, url = stub_delete(:incoming_phone_number, "IncomingPhoneNumbers/#{@incoming_sid}")
+
+ Twilio::IncomingPhoneNumber.delete(@incoming_sid).should == response
+ WebMock.should have_requested(:delete, url)
+ end
+end
View
21 spec/twilio/live_connection_spec.rb
@@ -0,0 +1,21 @@
+require 'spec_helper'
+
+# uncomment and add your own tests here
+=begin
+describe "testing with a live connection" do
+ before(:all) do
+ WebMock.allow_net_connect!
+ @sid = 'abc123'
+ @token = '123'
+ Twilio.connect(@sid, @token)
+ end
+
+ after(:all) do
+ WebMock.disable_net_connect!
+ end
+
+ it "gets real account" do
+ Twilio::Account.get.should include("TwilioResponse")
+ end
+end
+=end
View
29 spec/twilio/notification_spec.rb
@@ -0,0 +1,29 @@
+require 'spec_helper'
+
+describe "Notification" do
+ before(:all) do
+ Twilio.connect('mysid', 'mytoken')
+ @notification_sid = 'NO1fb7086ceb85caed2265f17d7bf7981c'
+ end
+
+ it "gets a list of notifications" do
+ response, url = stub_get(:notifications, 'Notifications')
+
+ Twilio::Notification.list.should == response
+ WebMock.should have_requested(:get, url)
+ end
+
+ it "gets a specific notification" do
+ response, url = stub_get(:notification, "Notifications/#{@notification_sid}")
+
+ Twilio::Notification.get(@notification_sid).should == response
+ WebMock.should have_requested(:get, url)
+ end
+
+ it "is deleted" do
+ response, url = stub_delete(:notification, "Notifications/#{@notification_sid}")
+
+ Twilio::Notification.delete(@notification_sid).should == response
+ WebMock.should have_requested(:delete, url)
+ end
+end
View
43 spec/twilio/outgoing_caller_id_spec.rb
@@ -0,0 +1,43 @@
+require 'spec_helper'
+
+describe "Outgoing Caller ID" do
+ before(:all) do
+ Twilio.connect('mysid', 'mytoken')
+ @callerid_sid = 'PNe536dfda7c6184afab78d980cb8cdf43'
+ end
+
+ it "gets a list of caller id's" do
+ response, url = stub_get(:outgoing_caller_ids, 'OutgoingCallerIds')
+
+ Twilio::OutgoingCallerId.list.should == response
+ WebMock.should have_requested(:get, url)
+ end
+
+ it "gets a specific caller id" do
+ response, url = stub_get(:outgoing_caller_id, "OutgoingCallerIds/#{@callerid_sid}")
+
+ Twilio::OutgoingCallerId.get(@callerid_sid).should == response
+ WebMock.should have_requested(:get, url)
+ end
+
+ it "is created" do
+ response, url = stub_post(:outgoing_caller_id_new, 'OutgoingCallerIds')
+
+ Twilio::OutgoingCallerId.create('4158675309', 'My Home Phone').should == response
+ WebMock.should have_requested(:post, url)
+ end
+
+ it "is deleted" do
+ response, url = stub_delete(:outgoing_caller_id, "OutgoingCallerIds/#{@callerid_sid}")
+
+ Twilio::OutgoingCallerId.delete(@callerid_sid).should == response
+ WebMock.should have_requested(:delete, url)
+ end
+
+ it "updates name" do
+ response, url = stub_put(:outgoing_caller_id, "OutgoingCallerIds/#{@callerid_sid}")
+
+ Twilio::OutgoingCallerId.update_name(@callerid_sid, 'My office line').should == response
+ WebMock.should have_requested(:put, url)
+ end
+end
View
44 spec/twilio/recording_spec.rb
@@ -0,0 +1,44 @@
+require 'spec_helper'
+
+describe "Recording" do
+ before(:all) do
+ Twilio.connect('mysid', 'mytoken')
+ @recording_sid = 'RE41331862605f3d662488fdafda2e175f'
+ @transcription_sid = 'TRbdece5b75f2cd8f6ef38e0a10f5c4447'
+ end
+
+ it "gets a list of recordings" do
+ response, url = stub_get(:recordings, 'Recordings')
+
+ Twilio::Recording.list.should == response
+ WebMock.should have_requested(:get, url)
+ end
+
+ it "gets a specific recording" do
+ response, url = stub_get(:recording, "Recordings/#{@recording_sid}")
+
+ Twilio::Recording.get(@recording_sid).should == response
+ WebMock.should have_requested(:get, url)
+ end
+
+ it "is deleted" do
+ response, url = stub_delete(:recording, "Recordings/#{@recording_sid}")
+
+ Twilio::Recording.delete(@recording_sid).should == response
+ WebMock.should have_requested(:delete, url)
+ end
+
+ it "gets a list of transcriptions" do
+ response, url = stub_get(:transcriptions, "Recordings/#{@recording_sid}/Transcriptions")
+
+ Twilio::Recording.transcriptions(@recording_sid).should == response
+ WebMock.should have_requested(:get, url)
+ end
+
+ it "gets a specific transcription" do
+ response, url = stub_get(:transcriptions, "Recordings/#{@recording_sid}/Transcriptions/#{@transcription_sid}")
+
+ Twilio::Recording.transcriptions(@recording_sid, @transcription_sid).should == response
+ WebMock.should have_requested(:get, url)
+ end
+end
View
36 spec/twilio/sms_spec.rb
@@ -0,0 +1,36 @@
+require 'spec_helper'
+
+describe "SMS" do
+ before(:all) do
+ Twilio.connect('mysid', 'mytoken')
+ @sms_sid = 'SM872fb94e3b358913777cdb313f25b46f'
+ end
+
+ it "gets a list of SMS messages" do
+ response, url = stub_get(:sms_messages, 'SMS/Messages')
+
+ Twilio::Sms.list.should == response
+ WebMock.should have_requested(:get, url)
+ end
+
+ it "gets a specific SMS message" do
+ response, url = stub_get(:sms, "SMS/Messages/#{@sms_sid}")
+
+ Twilio::Sms.get(@sms_sid).should == response
+ WebMock.should have_requested(:get, url)
+ end
+
+ it "is created" do
+ response, url = stub_post(:sms_new, "SMS/Messages")
+
+ Twilio::Sms.message('4155551212', '5558675309', 'Hi Jenny! Want to grab dinner?').should == response
+ WebMock.should have_requested(:post, url)
+ end
+
+ it "is created with a callback URL" do
+ response, url = stub_post(:sms_new_with_callback, "SMS/Messages")
+
+ Twilio::Sms.message('4155551212', '5558675309', 'Hi Jenny! Want to grab dinner?', 'http://example.com/callback').should == response
+ WebMock.should have_requested(:post, url)
+ end
+end
View
235 spec/twilio/verb_spec.rb
@@ -0,0 +1,235 @@
+require 'spec_helper'
+
+describe "Verb" do
+
+ context "Say" do
+ it "says 'hi'" do
+ Twilio::Verb.say('hi').should match %r{<Say( loop="1"| language="en"| voice="man"){3}>hi</Say>}
+ end
+
+ it "says 'hi' with female voice" do
+ Twilio::Verb.say('hi', :voice => 'woman').should match %r{<Say( loop="1"| language="en"| voice="woman"){3}>hi</Say>}
+ end
+
+ it "says 'hola' in Spanish with female voice" do
+ Twilio::Verb.say('hola', :voice => 'woman', :language => 'es').should match %r{<Say( loop="1"| language="es"| voice="woman"){3}>hola</Say>}
+ end
+
+ it "says 'hi' three times" do
+ Twilio::Verb.say('hi', :loop => 3).should match %r{<Say( loop="3"| language="en"| voice="man"){3}>hi</Say>}
+ end
+
+ it "says 'hi' three times with pause" do
+ Twilio::Verb.say('hi', :loop => 3, :pause => true).should match %r{<Say( language="en"| voice="man"){2}>hi</Say><Pause/><Say( language="en"| voice="man"){2}>hi</Say><Pause/><Say( language="en"| voice="man"){2}>hi</Say>}
+ end
+
+ it "says 'hi' with pause and say 'bye'" do
+ verb = Twilio::Verb.new { |v|
+ v.say 'hi', :loop => 1
+ v.pause
+ v.say 'bye'
+ }.response.should match %r{<Say( loop="1"| language="en"| voice="man"){3}>hi</Say><Pause></Pause><Say( loop="1"| language="en"| voice="man"){3}>bye</Say>}
+ end
+
+ it "says 'hi' with 2 second pause and say 'bye'" do
+ verb = Twilio::Verb.new { |v|
+ v.say 'hi'
+ v.pause :length => 2
+ v.say 'bye'
+ }.response.should match %r{<Say( loop="1"| language="en"| voice="man"){3}>hi</Say><Pause length="2"/><Say( loop="1"| language="en"| voice="man"){3}>bye</Say>}
+ end
+ end
+
+ context "Play" do
+ it "plays mp3 response" do
+ Twilio::Verb.play('http://foo.com/cowbell.mp3').should == verb_response(:play_mp3)
+ end
+
+ it "plays mp3 response two times" do
+ Twilio::Verb.play('http://foo.com/cowbell.mp3', :loop => 2).should == verb_response(:play_mp3_two_times)
+ end
+
+ it "plays mp3 response two times with pause" do
+ Twilio::Verb.play('http://foo.com/cowbell.mp3', :loop => 2, :pause => true).should == verb_response(:play_mp3_two_times_with_pause)
+ end
+ end
+
+ context "Gather" do
+ it "gathers" do
+ Twilio::Verb.gather.should == verb_response(:gather)
+ end
+
+ it "gathers with action" do
+ Twilio::Verb.gather(:action => 'http://foobar.com').should == verb_response(:gather_with_action)
+ end
+
+ it "gathers with GET method" do
+ Twilio::Verb.gather(:method => 'GET').should == verb_response(:gather_with_get_method)
+ end
+
+ it "gathers with timeout" do
+ Twilio::Verb.gather(:timeout => 10).should == verb_response(:gather_with_timeout)
+ end
+
+ it "gathers with finish key" do
+ Twilio::Verb.gather(:finishOnKey => '*').should == verb_response(:gather_with_finish_key)
+ end
+
+ it "gathers with num digits" do
+ Twilio::Verb.gather(:numDigits => 5).should == verb_response(:gather_with_num_digits)
+ end
+
+ it "gathers with all options set" do
+ Twilio::Verb.gather(:action => 'http://foobar.com',
+ :finishOnKey => '*',
+ :method => 'GET',
+ :numDigits => 5,
+ :timeout => 10).should match %r{<Gather( finishOnKey="\*"| action="http://foobar.com"| method="GET"| numDigits="5"| timeout="10"){5}/>}
+ end
+
+ it "gathers and says instructions" do
+ verb = Twilio::Verb.new { |v|
+ v.gather {
+ v.say 'Please enter your account number followed by the pound sign'
+ }
+ v.say "We didn't receive any input. Goodbye!"
+ }.response.should match %r{<Gather><Say( loop="1"| language="en"| voice="man"){3}>Please enter your account number followed by the pound sign</Say></Gather><Say( loop="1"| language="en"| voice="man"){3}>We didn't receive any input. Goodbye!</Say>}
+ end
+
+ it "gathers with timeout and says instructions" do
+ verb = Twilio::Verb.new { |v|
+ v.gather(:timeout => 10) {
+ v.say 'Please enter your account number followed by the pound sign'
+ }
+ v.say "We didn't receive any input. Goodbye!"
+ }.response.should match %r{<Gather timeout="10"><Say( loop="1"| language="en"| voice="man"){3}>Please enter your account number followed by the pound sign</Say></Gather><Say( loop="1"| language="en"| voice="man"){3}>We didn't receive any input. Goodbye!</Say>}
+ end
+ end
+
+ context "Record" do
+ it "records" do
+ Twilio::Verb.record.should == verb_response(:record)
+ end
+
+ it "records with action" do
+ Twilio::Verb.record(:action => 'http://foobar.com').should == verb_response(:record_with_action)
+ end
+
+ it "records with GET method" do
+ Twilio::Verb.record(:method => 'GET').should == verb_response(:record_with_get_method)
+ end
+
+ it "records with timeout" do
+ Twilio::Verb.record(:timeout => 10).should == verb_response(:record_with_timeout)
+ end
+
+ it "records with finish key" do
+ Twilio::Verb.record(:finishOnKey => '*').should == verb_response(:record_with_finish_key)
+ end
+
+ it "records with max length" do
+ Twilio::Verb.record(:maxLength => 1800).should == verb_response(:record_with_max_length)
+ end
+
+ it "records with transcribe" do
+ Twilio::Verb.record(:transcribe => true, :transcribeCallback => '/handle_transcribe').should match %r{<Record( transcribe="true"| transcribeCallback="/handle_transcribe"){2}/>}
+ end
+ end
+
+ context "Dial" do
+ it "dials" do
+ Twilio::Verb.dial('415-123-4567').should == verb_response(:dial)
+ end
+
+ it "dials with action" do
+ Twilio::Verb.dial('415-123-4567', :action => 'http://foobar.com').should == verb_response(:dial_with_action)
+ end
+
+ it "dials with GET method" do
+ Twilio::Verb.dial('415-123-4567', :method => 'GET').should == verb_response(:dial_with_get_method)
+ end
+
+ it "dials with timeout" do
+ Twilio::Verb.dial('415-123-4567', :timeout => 10).should == verb_response(:dial_with_timeout)
+ end
+
+ it "dials with hangup on star" do
+ Twilio::Verb.dial('415-123-4567', :hangupOnStar => true).should == verb_response(:dial_with_hangup_on_star)
+ end
+
+ it "dials with time limit" do
+ Twilio::Verb.dial('415-123-4567', :timeLimit => 3600).should == verb_response(:dial_with_time_limit)
+ end
+
+ it "dials with caller id" do
+ Twilio::Verb.dial('415-123-4567', :callerId => '858-987-6543').should == verb_response(:dial_with_caller_id)
+ end
+
+ it "dials with timeout and caller id" do
+ Twilio::Verb.dial('415-123-4567', :timeout => 10, :callerId => '858-987-6543').should match %r{<Dial( timeout="10"| callerId="858-987-6543"){2}>415-123-4567</Dial>}
+ end
+
+ it "dials with redirect" do
+ verb = Twilio::Verb.new { |v|
+ v.dial '415-123-4567'
+ v.redirect 'http://www.foo.com/nextInstructions'
+ }.response.should == verb_response(:dial_with_redirect)
+ end
+
+ it "dials with number and send digits" do
+ verb = Twilio::Verb.new { |v|
+ v.dial {
+ v.number('415-123-4567', :sendDigits => 'wwww1928')
+ }
+ }.response.should == verb_response(:dial_with_number_and_send_digits)
+ end
+
+ it "dials multiple numbers" do
+ verb = Twilio::Verb.new { |v|
+ v.dial {
+ v.number '415-123-4567'
+ v.number '415-123-4568'
+ v.number '415-123-4569'
+ }
+ }.response.should == verb_response(:dial_multiple_numbers)
+ end
+
+ it "dials a conference" do
+ verb = Twilio::Verb.new { |v|
+ v.dial {
+ v.conference 'MyRoom'
+ }
+ }.response.should == verb_response(:dial_conference)
+ end
+
+ it "dials a muted conference" do
+ verb = Twilio::Verb.new { |v|
+ v.dial {
+ v.conference 'MyRoom', :mute => :true
+ }
+ }.response.should == verb_response(:dial_muted_conference)
+ end
+ end
+
+ context "Hang Up" do
+ it "hangs up" do
+ Twilio::Verb.hangup.should == verb_response(:hangup)
+ end
+
+ it "says hi and hangs up" do
+ verb = Twilio::Verb.new { |v|
+ v.say 'hi'
+ v.hangup
+ }.response.should match %r{<Say( loop="1"| language="en"| voice="man"){3}>hi</Say><Hangup/>}
+ end
+ end
+
+ context "SMS" do
+ it "sends a simple SMS message" do
+ verb = Twilio::Verb.new { |v|
+ v.sms 'Join us at the bar', :to => "8005554321", :from => "9006661111", :action => "/smsService", :method => "GET"
+ }.response.should match %r{<Sms( to="8005554321"| from="9006661111"| action="/smsService"| method="GET"){4}>Join us at the bar</Sms>}
+ end
+ end
+
+end
View
11 test/fixtures/xml/account.xml
@@ -1,11 +0,0 @@
-<TwilioResponse>
- <Account>
- <Sid>mysid</Sid>
- <FriendlyName>My Nice Twilio Account</FriendlyName>
- <Status>2</Status>
- <StatusText>Active</StatusText>
- <DateCreated>Wed, 02 Apr 2008 17:33:38 -0700</DateCreated>
- <DateUpdated>Wed, 02 Apr 2008 17:34:18 -0700</DateUpdated>
- <AuthToken>mytoken</AuthToken>
- </Account>
-</TwilioResponse>
View
33 test/test_helper.rb
@@ -1,33 +0,0 @@
-require 'test/unit'
-require 'fakeweb'
-require 'shoulda'
-require 'yaml'
-require 'twilio'
-
-FakeWeb.allow_net_connect = false
-
-class Test::Unit::TestCase #:nodoc: all
-end
-
-def fixture(filename) #:nodoc:
- path = File.join(File.dirname(__FILE__), "fixtures/xml/#{filename}.xml")
- File.read path
-end
-
-def stub_response(verb, fixture_name, options = {}) #:nodoc:
- fake_response = fixture(fixture_name)
- resource = options.delete(:resource)
- options = { :body => fake_response }.merge(options)
- FakeWeb.register_uri(verb, twilio_url(resource), options)
-
- fake_response
-end
-
-def twilio_url(url=nil) #:nodoc:
- "https://mysid:mytoken@api.twilio.com:443/2010-04-01/Accounts/mysid#{'/' + url if url}"
-end
-
-def verb_response(verb) #:nodoc:
- path = File.join(File.dirname(__FILE__), "fixtures/yml/verb_responses.yml")
- YAML.load_file(path)[verb.to_s]['response']
-end
View
28 test/twilio/account_test.rb
@@ -1,28 +0,0 @@
-require 'test_helper'
-
-class AccountTest < Test::Unit::TestCase #:nodoc: all
- context "An account" do
- setup do
- Twilio.connect('mysid', 'mytoken')
- end
-
- should "be retrievable" do
- assert_equal stub_response(:get, :account), Twilio::Account.get
- end
-
- should "be able to update name" do
- assert_equal stub_response(:put, :account_renamed), Twilio::Account.update_name('Bubba')
- end
-
- context "using deprecated API" do
- setup do
- @connection = Twilio::Connection.new('mysid', 'mytoken')
- @account = Twilio::Account.new(@connection)
- end
-
- should "be retrievable" do
- assert_equal stub_response(:get, :account), @account.get
- end
- end
- end
-end
View
43 test/twilio/available_phone_numbers_test.rb
@@ -1,43 +0,0 @@
-require 'test_helper'
-
-class AvailablePhoneNumbersTest < Test::Unit::TestCase #:nodoc: all
- context "Available Number Searching" do
- setup do
- Twilio.connect('mysid', 'mytoken')
- end
-
- context "Local Numbers" do
- should "be searchable" do
- assert_equal stub_response(:get, :available_phone_numbers_local, :resource => 'AvailablePhoneNumbers/US/Local'),
- Twilio::AvailablePhoneNumbers.search_local
- end
-
- should "be searchable by area code" do
- assert_equal stub_response(:get, :available_phone_numbers_local_search, :resource => 'AvailablePhoneNumbers/US/Local?AreaCode=510'),
- Twilio::AvailablePhoneNumbers.search_local(:area_code => 510)
- end
-
- should "be searchable by Postal Code" do
- assert_equal stub_response(:get, :available_phone_numbers_local_search, :resource => 'AvailablePhoneNumbers/US/Local?InPostalCode=94612'),
- Twilio::AvailablePhoneNumbers.search_local(:postal_code => 94612)
- end
-
- should "be searchable by the rest of the paramters" do
- assert_equal stub_response(:get, :available_phone_numbers_local_search, :resource => 'AvailablePhoneNumbers/US/Local?NearLatLong=37.806940%2C-122.270360&InRateCenter=OKLD0349T&NearNumber=15105551213&Distance=50&InRegion=CA&InLata=722&Contains=510555****'),
- Twilio::AvailablePhoneNumbers.search_local(:in_region => 'CA', :contains => '510555****', :near_lat_long => '37.806940,-122.270360', :near_number => '15105551213', :in_lata => 722, :in_rate_center => 'OKLD0349T', :distance => 50)
- end
- end
-
- context "Toll-free numbers" do
- should "be searchable" do
- assert_equal stub_response(:get, :available_phone_numbers_toll_free, :resource => 'AvailablePhoneNumbers/US/TollFree'),
- Twilio::AvailablePhoneNumbers.search_toll_free
- end
-
- should "be able to find vanity numbers" do
- assert_equal stub_response(:get, :available_phone_numbers_toll_free_search, :resource => 'AvailablePhoneNumbers/US/TollFree?Contains=STORM'),
- Twilio::AvailablePhoneNumbers.search_toll_free(:contains => 'STORM')
- end
- end
- end
-end
View
66 test/twilio/call_test.rb
@@ -1,66 +0,0 @@
-require 'test_helper'
-
-class CallTest < Test::Unit::TestCase #:nodoc: all
- context "A call" do
- setup do
- Twilio.connect('mysid', 'mytoken')
- end
-
- should "be retrievable as a list" do
- assert_equal stub_response(:get, :calls, :resource => 'Calls'), Twilio::Call.list
- end
-
- should "be retrievable individually" do
- assert_equal stub_response(:get, :call, :resource => 'Calls/CA42ed11f93dc08b952027ffbc406d0868'),
- Twilio::Call.get('CA42ed11f93dc08b952027ffbc406d0868')
- end
-
- should "be made" do
- assert_equal stub_response(:post, :call_new, :resource => 'Calls'),
- Twilio::Call.make('4158675309', '4155551212', 'http://test.local/call_handler')
- end
-
- should "be redirected" do
- assert_equal stub_response(:post, :call_redirected, :resource => 'Calls/CA42ed11f93dc08b952027ffbc406d0868'),
- Twilio::Call.redirect('CA42ed11f93dc08b952027ffbc406d0868', 'http://www.myapp.com/myhandler.php')
- end
-
- context "with segments" do
- should "returns a list of Call resources that were segments created in the same call" do
- assert_equal stub_response(:get, :calls, :resource => 'Calls/CA42ed11f93dc08b952027ffbc406d0868/Segments'),
- Twilio::Call.segments('CA42ed11f93dc08b952027ffbc406d0868')
- end
-
- should "returns a single Call resource for the CallSid and CallSegmentSid provided" do
- assert_equal stub_response(:get, :calls, :resource => 'Calls/CA42ed11f93dc08b952027ffbc406d0868/Segments/abc123'),
- Twilio::Call.segments('CA42ed11f93dc08b952027ffbc406d0868', 'abc123')
- end
- end
-
- context "with recordings" do
- should "returns a list of recordings that were generated during the call" do
- assert_equal stub_response(:get, :recordings, :resource => 'Calls/CA42ed11f93dc08b952027ffbc406d0868/Recordings'),
- Twilio::Call.recordings('CA42ed11f93dc08b952027ffbc406d0868')
- end
- end
-
- context "with notifications" do
- should "description" do
- assert_equal stub_response(:get, :notifications, :resource => 'Calls/CA42ed11f93dc08b952027ffbc406d0868/Notifications'),
- Twilio::Call.notifications('CA42ed11f93dc08b952027ffbc406d0868')
- end
- end
-
- context "using deprecated API" do
- setup do
- @connection = Twilio::Connection.new('mysid', 'mytoken')
- @call = Twilio::Call.new(@connection)
- end
-
- should "be made" do
- assert_equal stub_response(:post, :call_new, :resource => 'Calls'),
- @call.make('4158675309', '4155551212', 'http://test.local/call_handler')
- end
- end
- end
-end
View
46 test/twilio/conference_test.rb
@@ -1,46 +0,0 @@
-require 'test_helper'
-
-class ConferenceTest < Test::Unit::TestCase #:nodoc: all
- context "A conference" do
- setup do
- Twilio.connect('mysid', 'mytoken')
- end
-
- should "be retrievable as a list" do
- assert_equal stub_response(:get, :conferences, :resource => 'Conferences'), Twilio::Conference.list
- end
-
- should "be retrievable individually" do
- assert_equal stub_response(:get, :conference, :resource => 'Conferences/CFd0a50bbe038c437e87f6c82db8f37f21'),
- Twilio::Conference.get('CFd0a50bbe038c437e87f6c82db8f37f21')
- end
-
- context "participant" do
- should "be retrievable as a list" do
- assert_equal stub_response(:get, :conference_participants, :resource => 'Conferences/CF9f2ead1ae43cdabeab102fa30d938378/Participants'),
- Twilio::Conference.participants('CF9f2ead1ae43cdabeab102fa30d938378')
- end
-
- should "be retrievable individually" do
- assert_equal stub_response(:get, :conference_participant, :resource => 'Conferences/CF9f2ead1ae43cdabeab102fa30d938378/Participants/CA9ae8e040497c0598481c2031a154919e'),
- Twilio::Conference.participant('CF9f2ead1ae43cdabeab102fa30d938378', 'CA9ae8e040497c0598481c2031a154919e')
- end
-
- should "be muted" do
- assert_equal stub_response(:post, :conference_participant_muted, :resource => 'Conferences/CF9f2ead1ae43cdabeab102fa30d938378/Participants/CA9ae8e040497c0598481c2031a154919e'),
- Twilio::Conference.mute_participant('CF9f2ead1ae43cdabeab102fa30d938378', 'CA9ae8e040497c0598481c2031a154919e')
- end
-
- should "be unmuted" do
- assert_equal stub_response(:post, :conference_participant, :resource => 'Conferences/CF9f2ead1ae43cdabeab102fa30d938378/Participants/CA9ae8e040497c0598481c2031a154919e'),
- Twilio::Conference.unmute_participant('CF9f2ead1ae43cdabeab102fa30d938378', 'CA9ae8e040497c0598481c2031a154919e')
- end
-
- should "be kicked" do
- stub_response(:delete, :conference_participant, :resource => 'Conferences/CF9f2ead1ae43cdabeab102fa30d938378/Participants/CA9ae8e040497c0598481c2031a154919e',
- :status => [ 204, "HTTPNoContent" ])
- assert Twilio::Conference.kick_participant('CF9f2ead1ae43cdabeab102fa30d938378', 'CA9ae8e040497c0598481c2031a154919e')
- end
- end
- end
-end
View
25 test/twilio/connection_test.rb
@@ -1,25 +0,0 @@
-require 'test_helper'
-
-class ConnectionTest < Test::Unit::TestCase #:nodoc: all
- context "A Twilio connection" do
- setup do
- @connection = Twilio::Connection.new('mysid', 'mytoken')
- end
-
- context "when initializing" do
- should "have correct url" do
- assert_equal "#{Twilio::Connection::TWILIO_URL}/mysid", @connection.class.base_uri
- end
- end
-
- context "when invoked as class method" do
- setup do
- Twilio.connect('mysid', 'mytoken')
- end
-
- should "have correct url" do
- assert_equal "#{Twilio::TWILIO_URL}/mysid", Twilio.base_uri
- end
- end
- end
-end
View
31 test/twilio/incoming_phone_number_test.rb
@@ -1,31 +0,0 @@
-require 'test_helper'
-
-class IncomingPhoneNumberTest < Test::Unit::TestCase #:nodoc: all
- context "An incoming phone number" do
- setup do
- Twilio.connect('mysid', 'mytoken')
- end
-
- should "be retrievable individually" do
- assert_equal stub_response(:get, :incoming_phone_number, :resource => 'IncomingPhoneNumbers/PNe536dfda7c6184afab78d980cb8cdf43'),
- Twilio::IncomingPhoneNumber.get('PNe536dfda7c6184afab78d980cb8cdf43')
- end
-
- should "be retrievable as a list" do
- assert_equal stub_response(:get, :incoming_phone_numbers, :resource => 'IncomingPhoneNumbers'),
- Twilio::IncomingPhoneNumber.list
- end
-
- context "using deprecated API" do
- setup do
- @connection = Twilio::Connection.new('mysid', 'mytoken')
- @incoming = Twilio::IncomingPhoneNumber.new(@connection)
- end
-
- should "be retrievable individually" do
- assert_equal stub_response(:get, :incoming_phone_number, :resource => 'IncomingPhoneNumbers/PNe536dfda7c6184afab78d980cb8cdf43'),
- @incoming.get('PNe536dfda7c6184afab78d980cb8cdf43')
- end
- end
- end
-end
View
37 test/twilio/local_phone_number_test.rb
@@ -1,37 +0,0 @@
-require 'test_helper'
-
-class LocalPhoneNumberTest < Test::Unit::TestCase #:nodoc: all
- context "A local phone number" do
- setup do
- Twilio.connect('mysid', 'mytoken')
- end
-
- should "be retrievable as a list" do
- assert_equal stub_response(:get, :incoming_phone_numbers, :resource => 'IncomingPhoneNumbers/Local'),
- Twilio::LocalPhoneNumber.list
- end
-
- should "be created" do
- assert_equal stub_response(:post, :incoming_phone_number, :resource => 'IncomingPhoneNumbers/Local'),
- Twilio::LocalPhoneNumber.create('http://test.local/call_handler')
- end
-
- should "be deleted" do
- stub_response(:delete, :incoming_phone_number, { :resource => 'IncomingPhoneNumbers/PNe536dfda7c6184afab78d980cb8cdf43',
- :status => [ 204, "HTTPNoContent" ] })
- assert Twilio::LocalPhoneNumber.delete('PNe536dfda7c6184afab78d980cb8cdf43')
- end
-
- context "using deprecated API" do
- setup do
- @connection = Twilio::Connection.new('mysid', 'mytoken')
- @local = Twilio::LocalPhoneNumber.new(@connection)
- end
-
- should "be retrievable as a list" do
- assert_equal stub_response(:get, :incoming_phone_numbers, :resource => 'IncomingPhoneNumbers/Local'),
- @local.list
- end
- end
- end
-end
View
35 test/twilio/notification_test.rb
@@ -1,35 +0,0 @@
-require 'test_helper'
-
-class NotificationTest < Test::Unit::TestCase #:nodoc: all
- context "A recording" do
- setup do
- Twilio.connect('mysid', 'mytoken')
- end
-
- should "be retrievable as a list" do
- assert_equal stub_response(:get, :notifications, :resource => 'Notifications'), Twilio::Notification.list
- end
-
- should "be retrievable individually" do
- assert_equal stub_response(:get, :notification, :resource => 'Notifications/NO1fb7086ceb85caed2265f17d7bf7981c'),
- Twilio::Notification.get('NO1fb7086ceb85caed2265f17d7bf7981c')
- end
-
- should "be deleted" do
- stub_response(:delete, :notification, { :resource => 'Notifications/NO1fb7086ceb85caed2265f17d7bf7981c',
- :status => [ 204, "HTTPNoContent" ] })
- assert Twilio::Notification.delete('NO1fb7086ceb85caed2265f17d7bf7981c')
- end
-
- context "using deprecated API" do
- setup do
- @connection = Twilio::Connection.new('mysid', 'mytoken')
- @notification = Twilio::Notification.new(@connection)
- end
-
- should "be retrievable as a list" do
- assert_equal stub_response(:get, :notifications, :resource => 'Notifications'), @notification.list
- end
- end
- end
-end
View
45 test/twilio/outgoing_caller_id_test.rb
@@ -1,45 +0,0 @@
-require 'test_helper'
-
-class OutgoingCallerIdTest < Test::Unit::TestCase #:nodoc: all
- context "An outgoing caller id" do
- setup do
- Twilio.connect('mysid', 'mytoken')
- end
-
- should "be retrievable as a list" do
- assert_equal stub_response(:get, :outgoing_caller_ids, :resource => 'OutgoingCallerIds'), Twilio::OutgoingCallerId.list
- end
-
- should "be retrievable individually" do
- assert_equal stub_response(:get, :outgoing_caller_id, :resource => 'OutgoingCallerIds/PNe536dfda7c6184afab78d980cb8cdf43'),
- Twilio::OutgoingCallerId.get('PNe536dfda7c6184afab78d980cb8cdf43')
- end
-
- should "be created" do
- assert_equal stub_response(:post, :outgoing_caller_id_new, :resource => 'OutgoingCallerIds'),
- Twilio::OutgoingCallerId.create('4158675309', 'My Home Phone')
- end
-
- should "be able to update name" do
- assert_equal stub_response(:put, :outgoing_caller_id, :resource => 'OutgoingCallerIds/PNe536dfda7c6184afab78d980cb8cdf43'),
- Twilio::OutgoingCallerId.update_name('PNe536dfda7c6184afab78d980cb8cdf43', 'My office line')
- end
-
- should "be deleted" do
- stub_response(:delete, :outgoing_caller_id, :resource => 'OutgoingCallerIds/PNe536dfda7c6184afab78d980cb8cdf43',
- :status => [ 204, "HTTPNoContent" ])
- assert Twilio::OutgoingCallerId.delete('PNe536dfda7c6184afab78d980cb8cdf43')
- end
-
- context "using deprecated API" do
- setup do
- @connection = Twilio::Connection.new('mysid', 'mytoken')
- @caller_id = Twilio::OutgoingCallerId.new(@connection)
- end
-
- should "be retrievable as a list" do
- assert_equal stub_response(:get, :outgoing_caller_ids, :resource => 'OutgoingCallerIds'), @caller_id.list
- end
- end
- end
-end
View
47 test/twilio/recording_test.rb
@@ -1,47 +0,0 @@
-require 'test_helper'
-
-class RecordingTest < Test::Unit::TestCase #:nodoc: all
- context "A recording" do
- setup do
- Twilio.connect('mysid', 'mytoken')
- end
-
- should "be retrievable as a list" do
- assert_equal stub_response(:get, :recordings, :resource => 'Recordings'), Twilio::Recording.list
- end
-
- should "be retrievable individually" do
- assert_equal stub_response(:get, :recording, :resource => 'Recordings/RE41331862605f3d662488fdafda2e175f'),
- Twilio::Recording.get('RE41331862605f3d662488fdafda2e175f')
- end
-
- should "be deleted" do
- stub_response(:delete, :recording, :resource => 'Recordings/RE41331862605f3d662488fdafda2e175f',
- :status => [ 204, "HTTPNoContent" ])
- assert Twilio::Recording.delete('RE41331862605f3d662488fdafda2e175f')
- end
-
- context "with transcriptions" do
- should "be retrievable as a list" do
- assert_equal stub_response(:get, :transcriptions, :resource => 'Recordings/RE41331862605f3d662488fdafda2e175f/Transcriptions'),
- Twilio::Recording.transcriptions('RE41331862605f3d662488fdafda2e175f')
- end
-
- should "be retrievable individually" do
- assert_equal stub_response(:get, :transcription, :resource => 'Recordings/RE41331862605f3d662488fdafda2e175f/Transcriptions/TRbdece5b75f2cd8f6ef38e0a10f5c4447'),
- Twilio::Recording.transcriptions('RE41331862605f3d662488fdafda2e175f', 'TRbdece5b75f2cd8f6ef38e0a10f5c4447')
- end
- end
-
- context "using deprecated API" do
- setup do
- @connection = Twilio::Connection.new('mysid', 'mytoken')
- @recording = Twilio::Recording.new(@connection)
- end
-
- should "be retrievable as a list" do
- assert_equal stub_response(:get, :recordings, :resource => 'Recordings'), @recording.list
- end
- end
- end
-end
View
27 test/twilio/sms_test.rb
@@ -1,27 +0,0 @@
-require 'test_helper'
-
-class SmsTest < Test::Unit::TestCase #:nodoc: all
- context "A call" do
- setup do
- Twilio.connect('mysid', 'mytoken')
- end
-
- should "be messaged" do
- assert_equal stub_response(:post, :sms_new, :resource => 'SMS/Messages'),
- Twilio::Sms.message('4155551212', '5558675309', 'Hi Jenny! Want to grab dinner?')
- end
- should "be messaged with a callback URL" do
- assert_equal stub_response(:post, :sms_new_with_callback, :resource => 'SMS/Messages'),
- Twilio::Sms.message('4155551212', '5558675309', 'Hi Jenny! Want to grab dinner?', 'http://example.com/callback')
- end
-
- should "be retrievable as a list" do
- assert_equal stub_response(:get, :sms_messages, :resource => 'SMS/Messages'), Twilio::Sms.list
- end
-
- should "retrieve an individual sms" do
- assert_equal stub_response(:get, :sms, :resource => 'SMS/Messages/SM872fb94e3b358913777cdb313f25b46f'),
- Twilio::Sms.get('SM872fb94e3b358913777cdb313f25b46f')
- end
- end
-end
View
38 test/twilio/toll_free_phone_number_test.rb
@@ -1,38 +0,0 @@
-require 'test_helper'
-
-class TollFreePhoneNumberTest < Test::Unit::TestCase #:nodoc: all
- context "A toll free phone number" do
- setup do
- Twilio.connect('mysid', 'mytoken')
- end
-
- should "be retrievable as a list" do
- assert_equal stub_response(:get, :incoming_phone_numbers, :resource => 'IncomingPhoneNumbers/TollFree'),
- Twilio::TollFreePhoneNumber.list
- end
-
- should "be created" do
- assert_equal stub_response(:post, :incoming_phone_number, :resource => 'IncomingPhoneNumbers/TollFree'),
- Twilio::TollFreePhoneNumber.create('http://test.local/call_handler')
- end
-
- should "be deleted" do
- stub_response(:delete, :incoming_phone_number, { :resource => 'IncomingPhoneNumbers/PNe536dfda7c6184afab78d980cb8cdf43',
- :status => [ 204, "HTTPNoContent" ] })
- assert Twilio::TollFreePhoneNumber.delete('PNe536dfda7c6184afab78d980cb8cdf43')
- end
-
-
- context "using deprecated API" do
- setup do
- @connection = Twilio::Connection.new('mysid', 'mytoken')
- @toll_free = Twilio::TollFreePhoneNumber.new(@connection)
- end
-
- should "be retrievable as a list" do
- assert_equal stub_response(:get, :incoming_phone_numbers, :resource => 'IncomingPhoneNumbers/TollFree'),
- @toll_free.list
- end
- end
- end
-end
View
244 test/twilio/verb_test.rb
@@ -1,244 +0,0 @@
-require 'test_helper'
-
-class VerbTest < Test::Unit::TestCase #:nodoc: all
- context "A Twilio Verb" do
- should "say 'hi'" do
- assert_match %r{<Say( loop="1"| language="en"| voice="man"){3}>hi</Say>},
- Twilio::Verb.say('hi')
- end
-
- should "say 'hi' with female voice" do
- assert_match %r{<Say( loop="1"| language="en"| voice="woman"){3}>hi</Say>},
- Twilio::Verb.say('hi', :voice => 'woman')
- end
-
- should "say 'hola' in Spanish with female voice" do
- assert_match %r{<Say( loop="1"| language="es"| voice="woman"){3}>hola</Say>},
- Twilio::Verb.say('hola', :voice => 'woman', :language => 'es')
- end
-
- should "say 'hi' three times" do
- assert_match %r{<Say( loop="3"| language="en"| voice="man"){3}>hi</Say>},
- Twilio::Verb.say('hi', :loop => 3)
- end
-
- should "say 'hi' three times with pause" do
- assert_match %r{<Say( language="en"| voice="man"){2}>hi</Say><Pause/><Say( language="en"| voice="man"){2}>hi</Say><Pause/><Say( language="en"| voice="man"){2}>hi</Say>},
- Twilio::Verb.say('hi', :loop => 3, :pause => true)
- end
-
- should "say 'hi' with pause and say 'bye'" do
- verb = Twilio::Verb.new { |v|
- v.say 'hi', :loop => 1
- v.pause
- v.say 'bye'
- }
- assert_match %r{<Say( loop="1"| language="en"| voice="man"){3}>hi</Say><Pause></Pause><Say( loop="1"| language="en"| voice="man"){3}>bye</Say>}, verb.response
- end
-
- should "say 'hi' with 2 second pause and say 'bye'" do
- verb = Twilio::Verb.new { |v|
- v.say 'hi'
- v.pause :length => 2
- v.say 'bye'
- }
- assert_match %r{<Say( loop="1"| language="en"| voice="man"){3}>hi</Say><Pause length="2"/><Say( loop="1"| language="en"| voice="man"){3}>bye</Say>}, verb.response
- end
-
- should "play mp3 response" do
- assert_equal verb_response(:play_mp3), Twilio::Verb.play('http://foo.com/cowbell.mp3')
- end
-
- should "play mp3 response two times" do
- assert_equal verb_response(:play_mp3_two_times), Twilio::Verb.play('http://foo.com/cowbell.mp3', :loop => 2)
- end
-
- should "play mp3 response two times with pause" do
- assert_equal verb_response(:play_mp3_two_times_with_pause),
- Twilio::Verb.play('http://foo.com/cowbell.mp3', :loop => 2, :pause => true)
- end
-
- should "gather" do
- assert_equal verb_response(:gather), Twilio::Verb.gather
- end
-
- should "gather with action" do
- assert_equal verb_response(:gather_with_action), Twilio::Verb.gather(:action => 'http://foobar.com')
- end
-
- should "gather with GET method" do
- assert_equal verb_response(:gather_with_get_method), Twilio::Verb.gather(:method => 'GET')
- end
-