webficient-twilio 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +20 -0
- data/README.rdoc +24 -0
- data/Rakefile +49 -0
- data/VERSION.yml +4 -0
- data/lib/twilio.rb +42 -0
- data/lib/twilio/account.rb +11 -0
- data/lib/twilio/call.rb +27 -0
- data/lib/twilio/connection.rb +17 -0
- data/lib/twilio/incoming_phone_number.rb +11 -0
- data/lib/twilio/local_phone_number.rb +16 -0
- data/lib/twilio/notification.rb +15 -0
- data/lib/twilio/outgoing_caller_id.rb +27 -0
- data/lib/twilio/recording.rb +19 -0
- data/lib/twilio/toll_free_phone_number.rb +16 -0
- data/lib/twilio/twilio_object.rb +11 -0
- data/lib/twilio/verb.rb +50 -0
- data/test/fixtures/xml/account.xml +11 -0
- data/test/fixtures/xml/account_renamed.xml +11 -0
- data/test/fixtures/xml/call.xml +18 -0
- data/test/fixtures/xml/call_new.xml +14 -0
- data/test/fixtures/xml/calls.xml +36 -0
- data/test/fixtures/xml/incoming_phone_number.xml +12 -0
- data/test/fixtures/xml/incoming_phone_numbers.xml +24 -0
- data/test/fixtures/xml/notification.xml +19 -0
- data/test/fixtures/xml/notifications.xml +32 -0
- data/test/fixtures/xml/outgoing_caller_id.xml +10 -0
- data/test/fixtures/xml/outgoing_caller_id_new.xml +7 -0
- data/test/fixtures/xml/outgoing_caller_ids.xml +20 -0
- data/test/fixtures/xml/recording.xml +10 -0
- data/test/fixtures/xml/recordings.xml +20 -0
- data/test/fixtures/xml/transcription.xml +13 -0
- data/test/fixtures/xml/transcriptions.xml +26 -0
- data/test/fixtures/yml/verb_responses.yml +8 -0
- data/test/test_helper.rb +29 -0
- data/test/twilio/account_test.rb +23 -0
- data/test/twilio/call_test.rb +59 -0
- data/test/twilio/connection_test.rb +15 -0
- data/test/twilio/incoming_phone_number_test.rb +22 -0
- data/test/twilio/local_phone_number_test.rb +23 -0
- data/test/twilio/notification_test.rb +28 -0
- data/test/twilio/outgoing_caller_id_test.rb +42 -0
- data/test/twilio/recording_test.rb +42 -0
- data/test/twilio/toll_free_phone_number_test.rb +23 -0
- data/test/twilio/verb_test.rb +34 -0
- metadata +126 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Phil Misiowiec, Webficient LLC
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
= twilio
|
2
|
+
|
3
|
+
This wrapper defines each of the interfaces currently supported by Twilio REST API.
|
4
|
+
|
5
|
+
Sample Usage:
|
6
|
+
|
7
|
+
First create a connection object:
|
8
|
+
|
9
|
+
c = Twilio::Connection.new('my_twilio_sid', 'my_auth_token')
|
10
|
+
|
11
|
+
Now instantiate other objects by passing in the connection:
|
12
|
+
|
13
|
+
a = Twilio::Account.new(c)
|
14
|
+
a.update_name('sparky')
|
15
|
+
|
16
|
+
call = Twilio::Call.new(c)
|
17
|
+
call.make('1234567890', '9876543210', 'http://mysite.com/connected_call')
|
18
|
+
|
19
|
+
recording = Twilio::Recording.new(c)
|
20
|
+
recording.list
|
21
|
+
|
22
|
+
== Copyright
|
23
|
+
|
24
|
+
Copyright (c) 2009 Phil Misiowiec, Webficient LLC. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "twilio"
|
8
|
+
gem.summary = %Q{Twilio API Client}
|
9
|
+
gem.email = "github@webficient.com"
|
10
|
+
gem.homepage = "http://github.com/webficient/twilio"
|
11
|
+
gem.authors = ["Phil Misiowiec"]
|
12
|
+
gem.add_dependency 'builder'
|
13
|
+
gem.add_dependency 'httparty'
|
14
|
+
end
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'rake/rdoctask'
|
20
|
+
Rake::RDocTask.new do |rdoc|
|
21
|
+
rdoc.rdoc_dir = 'rdoc'
|
22
|
+
rdoc.title = 'twilio'
|
23
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
24
|
+
rdoc.rdoc_files.include('README*')
|
25
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
26
|
+
end
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/*_test.rb'
|
32
|
+
test.verbose = false
|
33
|
+
end
|
34
|
+
|
35
|
+
begin
|
36
|
+
require 'rcov/rcovtask'
|
37
|
+
Rcov::RcovTask.new do |test|
|
38
|
+
test.libs << 'test'
|
39
|
+
test.pattern = 'test/**/*_test.rb'
|
40
|
+
test.verbose = true
|
41
|
+
end
|
42
|
+
rescue LoadError
|
43
|
+
task :rcov do
|
44
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
task :default => :test
|
data/VERSION.yml
ADDED
data/lib/twilio.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__))
|
2
|
+
|
3
|
+
#--
|
4
|
+
# Copyright (c) 2009 Phil Misiowiec, phil@webficient.com
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
# a copy of this software and associated documentation files (the
|
8
|
+
# "Software"), to deal in the Software without restriction, including
|
9
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
# the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be
|
15
|
+
# included in all copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
24
|
+
#++
|
25
|
+
|
26
|
+
require 'rubygems'
|
27
|
+
gem 'httparty', '>= 0.4.3'
|
28
|
+
require 'httparty'
|
29
|
+
gem 'builder', '>= 2.1.2'
|
30
|
+
require 'builder'
|
31
|
+
|
32
|
+
require 'twilio/twilio_object'
|
33
|
+
require 'twilio/account'
|
34
|
+
require 'twilio/call'
|
35
|
+
require 'twilio/connection'
|
36
|
+
require 'twilio/incoming_phone_number'
|
37
|
+
require 'twilio/local_phone_number'
|
38
|
+
require 'twilio/notification'
|
39
|
+
require 'twilio/outgoing_caller_id'
|
40
|
+
require 'twilio/recording'
|
41
|
+
require 'twilio/toll_free_phone_number'
|
42
|
+
require 'twilio/verb'
|
data/lib/twilio/call.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Twilio
|
2
|
+
class Call < TwilioObject
|
3
|
+
def make(caller, called, url, optional = {})
|
4
|
+
self.connection.class.post("/Calls", :body => {:Caller => caller, :Called => called, :Url => url}.merge(optional))
|
5
|
+
end
|
6
|
+
|
7
|
+
def list(optional = {})
|
8
|
+
self.connection.class.get("/Calls", :query => optional)
|
9
|
+
end
|
10
|
+
|
11
|
+
def get(call_sid)
|
12
|
+
self.connection.class.get("/Calls/#{call_sid}")
|
13
|
+
end
|
14
|
+
|
15
|
+
def segments(call_sid, call_segment_sid = nil)
|
16
|
+
self.connection.class.get("/Calls/#{call_sid}/Segments#{ '/' + call_segment_sid if call_segment_sid }")
|
17
|
+
end
|
18
|
+
|
19
|
+
def recordings(call_sid)
|
20
|
+
self.connection.class.get("/Calls/#{call_sid}/Recordings")
|
21
|
+
end
|
22
|
+
|
23
|
+
def notifications(call_sid)
|
24
|
+
self.connection.class.get("/Calls/#{call_sid}/Notifications")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Twilio
|
2
|
+
#The Connection class caches the Twilio API base path and authentication credentials.
|
3
|
+
#It is passed into the constructor of other TwilioObject's, avoiding the need to
|
4
|
+
#explicitly set credentials with each API call.
|
5
|
+
#
|
6
|
+
# Example:
|
7
|
+
# c = Twilio::Connection.new('my_twilio_sid', 'my_auth_token')
|
8
|
+
class Connection
|
9
|
+
include HTTParty
|
10
|
+
TWILIO_URL = "https://api.twilio.com/2008-08-01/Accounts"
|
11
|
+
|
12
|
+
def initialize(account_sid, auth_token)
|
13
|
+
self.class.base_uri "#{TWILIO_URL}/#{account_sid}"
|
14
|
+
self.class.basic_auth account_sid, auth_token
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Twilio
|
2
|
+
class IncomingPhoneNumber < TwilioObject
|
3
|
+
def list(optional = {})
|
4
|
+
self.connection.class.get("/IncomingPhoneNumbers", :query => optional)
|
5
|
+
end
|
6
|
+
|
7
|
+
def get(incoming_sid)
|
8
|
+
self.connection.class.get("/IncomingPhoneNumbers/#{incoming_sid}")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Twilio
|
2
|
+
class LocalPhoneNumber < TwilioObject
|
3
|
+
def create(url, area_code = nil, method = 'POST', friendly_name = nil)
|
4
|
+
self.connection.class.post("/IncomingPhoneNumbers/Local", :body => {
|
5
|
+
:Url => url,
|
6
|
+
:AreaCode => area_code,
|
7
|
+
:Method => method,
|
8
|
+
:FriendlyName => friendly_name
|
9
|
+
})
|
10
|
+
end
|
11
|
+
|
12
|
+
def list
|
13
|
+
self.connection.class.get("/IncomingPhoneNumbers/Local")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Twilio
|
2
|
+
class Notification < TwilioObject
|
3
|
+
def list(optional = {})
|
4
|
+
self.connection.class.get('/Notifications', :query => optional)
|
5
|
+
end
|
6
|
+
|
7
|
+
def get(notification_sid)
|
8
|
+
self.connection.class.get("/Notifications/#{notification_sid}")
|
9
|
+
end
|
10
|
+
|
11
|
+
def delete(notification_sid)
|
12
|
+
self.connection.class.delete("/Notifications/#{notification_sid}")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Twilio
|
2
|
+
class OutgoingCallerId < TwilioObject
|
3
|
+
def create(phone_number, friendly_name = phone_number, call_delay = 0)
|
4
|
+
self.connection.class.post("/OutgoingCallerIds", :body => {
|
5
|
+
:PhoneNumber => phone_number,
|
6
|
+
:FriendlyName => friendly_name,
|
7
|
+
:CallDelay => call_delay
|
8
|
+
})
|
9
|
+
end
|
10
|
+
|
11
|
+
def list(optional = {})
|
12
|
+
self.connection.class.get("/OutgoingCallerIds", :query => optional)
|
13
|
+
end
|
14
|
+
|
15
|
+
def get(callerid_sid)
|
16
|
+
self.connection.class.get("/OutgoingCallerIds/#{callerid_sid}")
|
17
|
+
end
|
18
|
+
|
19
|
+
def update_name(callerid_sid, name)
|
20
|
+
self.connection.class.put("/OutgoingCallerIds/#{callerid_sid}", :body => {:FriendlyName => name})
|
21
|
+
end
|
22
|
+
|
23
|
+
def delete(callerid_sid)
|
24
|
+
self.connection.class.delete("/OutgoingCallerIds/#{callerid_sid}")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Twilio
|
2
|
+
class Recording < TwilioObject
|
3
|
+
def list(optional = {})
|
4
|
+
self.connection.class.get("/Recordings", :query => optional)
|
5
|
+
end
|
6
|
+
|
7
|
+
def get(recording_sid)
|
8
|
+
self.connection.class.get("/Recordings/#{recording_sid}")
|
9
|
+
end
|
10
|
+
|
11
|
+
def delete(recording_sid)
|
12
|
+
self.connection.class.delete("/Recordings/#{recording_sid}")
|
13
|
+
end
|
14
|
+
|
15
|
+
def transcriptions(recording_sid, transcription_sid = nil)
|
16
|
+
self.connection.class.get("/Recordings/#{recording_sid}/Transcriptions#{ '/' + transcription_sid if transcription_sid }")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Twilio
|
2
|
+
class TollFreePhoneNumber < TwilioObject
|
3
|
+
def create(url, area_code = nil, method = 'POST', friendly_name = nil)
|
4
|
+
self.connection.class.post("/IncomingPhoneNumbers/TollFree", :body => {
|
5
|
+
:Url => url,
|
6
|
+
:AreaCode => area_code,
|
7
|
+
:Method => method,
|
8
|
+
:FriendlyName => friendly_name
|
9
|
+
})
|
10
|
+
end
|
11
|
+
|
12
|
+
def list
|
13
|
+
self.connection.class.get("/IncomingPhoneNumbers/TollFree")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/twilio/verb.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
module Twilio
|
2
|
+
class Verb
|
3
|
+
class << self
|
4
|
+
def say(text, options = {})
|
5
|
+
voice = options[:voice] || 'woman'
|
6
|
+
language = options[:language] || 'en'
|
7
|
+
loop_count = Integer(options[:loop] || 1)
|
8
|
+
pause = options[:pause]
|
9
|
+
|
10
|
+
xml = Builder::XmlMarkup.new
|
11
|
+
xml.instruct!
|
12
|
+
xml.Response {
|
13
|
+
if pause
|
14
|
+
loop_count.times do |i|
|
15
|
+
xml.Say(text, :voice => voice, :language => language, :loop => 1)
|
16
|
+
xml.Pause unless i+1 == loop_count
|
17
|
+
end
|
18
|
+
else
|
19
|
+
xml.Say(text, :voice => voice, :language => language, :loop => loop_count)
|
20
|
+
end
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def play(audio_url, options = {})
|
25
|
+
raise NotImplementedError.new 'Not yet implemented - coming soon'
|
26
|
+
end
|
27
|
+
|
28
|
+
def gather(options = {})
|
29
|
+
raise NotImplementedError.new 'Not yet implemented - coming soon'
|
30
|
+
end
|
31
|
+
|
32
|
+
def record(options = {})
|
33
|
+
raise NotImplementedError.new 'Not yet implemented - coming soon'
|
34
|
+
end
|
35
|
+
|
36
|
+
def dial(phone_number, options = {})
|
37
|
+
raise NotImplementedError.new 'Not yet implemented - coming soon'
|
38
|
+
end
|
39
|
+
|
40
|
+
def method_missing(method_id, *args)
|
41
|
+
if match = /(say|play|gather|record|dial)_(\d+)_times(_with_pause$*)/.match(method_id.to_s)
|
42
|
+
verb = match.captures.first
|
43
|
+
how_many_times = match.captures[1]
|
44
|
+
pause = match.captures[2] == '_with_pause'
|
45
|
+
self.send(verb, args.first, { :loop => how_many_times, :pause => pause})
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<TwilioResponse>
|
2
|
+
<Account>
|
3
|
+
<Sid>mysid</Sid>
|
4
|
+
<FriendlyName>My Nice Twilio Account</FriendlyName>
|
5
|
+
<Status>2</Status>
|
6
|
+
<StatusText>Active</StatusText>
|
7
|
+
<DateCreated>Wed, 02 Apr 2008 17:33:38 -0700</DateCreated>
|
8
|
+
<DateUpdated>Wed, 02 Apr 2008 17:34:18 -0700</DateUpdated>
|
9
|
+
<AuthToken>mytoken</AuthToken>
|
10
|
+
</Account>
|
11
|
+
</TwilioResponse>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<TwilioResponse>
|
2
|
+
<Account>
|
3
|
+
<Sid>mysid</Sid>
|
4
|
+
<FriendlyName>Bubba</FriendlyName>
|
5
|
+
<Status>2</Status>
|
6
|
+
<StatusText>Active</StatusText>
|
7
|
+
<DateCreated>Wed, 02 Apr 2008 17:33:38 -0700</DateCreated>
|
8
|
+
<DateUpdated>Wed, 02 Apr 2008 17:34:18 -0700</DateUpdated>
|
9
|
+
<AuthToken>mytoken</AuthToken>
|
10
|
+
</Account>
|
11
|
+
</TwilioResponse>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<TwilioResponse>
|
2
|
+
<Call>
|
3
|
+
<Sid>CA42ed11f93dc08b952027ffbc406d0868</Sid>
|
4
|
+
<DateCreated>Sat, 07 Feb 2009 13:15:19 -0800</DateCreated>
|
5
|
+
<DateUpdated>Sat, 07 Feb 2009 13:15:19 -0800</DateUpdated>
|
6
|
+
<CallSegmentSid/>
|
7
|
+
<AccountSid>mysid</AccountSid>
|
8
|
+
<Called>4159633717</Called>
|
9
|
+
<Caller>4156767925</Caller>
|
10
|
+
<PhoneNumberSid>PN01234567890123456789012345678900</PhoneNumberSid>
|
11
|
+
<Status>2</Status>
|
12
|
+
<StartTime>Thu, 03 Apr 2008 04:36:33 -0400</StartTime>
|
13
|
+
<EndTime>Thu, 03 Apr 2008 04:36:47 -0400</EndTime>
|
14
|
+
<Duration>14</Duration>
|
15
|
+
<Price/>
|
16
|
+
<Flags>1</Flags>
|
17
|
+
</Call>
|
18
|
+
</TwilioResponse>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<TwilioResponse>
|
2
|
+
<Call>
|
3
|
+
<Sid>CA42ed11f93dc08b952027ffbc406d0868</Sid>
|
4
|
+
<CallSegmentSid/> <AccountSid>AC309475e5fede1b49e100272a8640f438</AccountSid>
|
5
|
+
<Called>4155551212</Called>
|
6
|
+
<Caller>4158675309</Caller>
|
7
|
+
<PhoneNumberSid>PN01234567890123456789012345678900</PhoneNumberSid>
|
8
|
+
<Status>0</Status>
|
9
|
+
<StartTime>Thu, 03 Apr 2008 04:36:33 -0400</StartTime>
|
10
|
+
<EndTime/>
|
11
|
+
<Price/>
|
12
|
+
<Flags>1</Flags>
|
13
|
+
</Call>
|
14
|
+
</TwilioResponse>
|
@@ -0,0 +1,36 @@
|
|
1
|
+
<TwilioResponse>
|
2
|
+
<Calls page="0" numpages="1" pagesize="50" total="38" start="0" end="37">
|
3
|
+
<Call>
|
4
|
+
<Sid>CA42ed11f93dc08b952027ffbc406d0868</Sid>
|
5
|
+
<DateCreated>Sat, 07 Feb 2009 13:15:19 -0800</DateCreated>
|
6
|
+
<DateUpdated>Sat, 07 Feb 2009 13:15:19 -0800</DateUpdated>
|
7
|
+
<CallSegmentSid/>
|
8
|
+
<AccountSid>mysid</AccountSid>
|
9
|
+
<Called>4159633717</Called>
|
10
|
+
<Caller>4156767925</Caller>
|
11
|
+
<PhoneNumberSid>PN01234567890123456789012345678900</PhoneNumberSid>
|
12
|
+
<Status>2</Status>
|
13
|
+
<StartTime>Thu, 03 Apr 2008 04:36:33 -0400</StartTime>
|
14
|
+
<EndTime>Thu, 03 Apr 2008 04:36:47 -0400</EndTime>
|
15
|
+
<Duration>14</Duration>
|
16
|
+
<Price/>
|
17
|
+
<Flags>1</Flags>
|
18
|
+
</Call>
|
19
|
+
<Call>
|
20
|
+
<Sid>CA751e8fa0a0105cf26a0d7a9775fb4bfb</Sid>
|
21
|
+
<DateCreated>Sat, 07 Feb 2009 13:15:19 -0800</DateCreated>
|
22
|
+
<DateUpdated>Sat, 07 Feb 2009 13:15:19 -0800</DateUpdated>
|
23
|
+
<CallSegmentSid/>
|
24
|
+
<AccountSid>mysid</AccountSid>
|
25
|
+
<Called>2064287985</Called>
|
26
|
+
<Caller>4156767925</Caller>
|
27
|
+
<PhoneNumberSid>PNd59c2ba27ef48264773edb90476d1674</PhoneNumberSid>
|
28
|
+
<Status>2</Status>
|
29
|
+
<StartTime>Thu, 03 Apr 2008 01:37:05 -0400</StartTime>
|
30
|
+
<EndTime>Thu, 03 Apr 2008 01:37:40 -0400</EndTime>
|
31
|
+
<Duration>35</Duration>
|
32
|
+
<Price/>
|
33
|
+
<Flags>1</Flags>
|
34
|
+
</Call>
|
35
|
+
</Calls>
|
36
|
+
</TwilioResponse>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<TwilioResponse>
|
2
|
+
<IncomingPhoneNumber>
|
3
|
+
<Sid>PNe536dfda7c6184afab78d980cb8cdf43</Sid>
|
4
|
+
<AccountSid>mysid</AccountSid>
|
5
|
+
<FriendlyName>My Home Phone Number</FriendlyName>
|
6
|
+
<PhoneNumber>4158675309</PhoneNumber>
|
7
|
+
<Url>http://mycompany.com/handleMainLineCall.asp</Url>
|
8
|
+
<Method>GET</Method>
|
9
|
+
<DateCreated>Tue, 01 Apr 2008 11:26:32 -0700</DateCreated>
|
10
|
+
<DateUpdated>Tue, 01 Apr 2008 11:26:32 -0700</DateUpdated>
|
11
|
+
</IncomingPhoneNumber>
|
12
|
+
</TwilioResponse>
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<TwilioResponse>
|
2
|
+
<IncomingPhoneNumbers page="0" numpages="1" pagesize="50" total="2" start="0" end="0">
|
3
|
+
<IncomingPhoneNumber>
|
4
|
+
<Sid>PNe536dfda7c6184afab78d980cb8cdf43</Sid>
|
5
|
+
<AccountSid>mysid</AccountSid>
|
6
|
+
<FriendlyName>Company Main Line</FriendlyName>
|
7
|
+
<PhoneNumber>4158675309</PhoneNumber>
|
8
|
+
<Url>http://mycompany.com/handleMainLineCall.asp</Url>
|
9
|
+
<Method>GET</Method>
|
10
|
+
<DateCreated>Tue, 01 Apr 2008 11:26:32 -0700</DateCreated>
|
11
|
+
<DateUpdated>Tue, 01 Apr 2008 11:26:32 -0700</DateUpdated>
|
12
|
+
</IncomingPhoneNumber>
|
13
|
+
<IncomingPhoneNumber>
|
14
|
+
<Sid>PNe536dfda7c6DDd455fed980cb83345FF</Sid>
|
15
|
+
<AccountSid>mysid</AccountSid>
|
16
|
+
<FriendlyName>Company Support Line</FriendlyName>
|
17
|
+
<PhoneNumber>4158675310</PhoneNumber>
|
18
|
+
<Url>http://mycompany.com/handleSupportCall.php</Url>
|
19
|
+
<Method>POST</Method>
|
20
|
+
<DateCreated>Tue, 01 Apr 2008 11:26:32 -0700</DateCreated>
|
21
|
+
<DateUpdated>Tue, 01 Apr 2008 11:26:32 -0700</DateUpdated>
|
22
|
+
</IncomingPhoneNumber>
|
23
|
+
</IncomingPhoneNumbers>
|
24
|
+
</TwilioResponse>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<TwilioResponse>
|
2
|
+
<Notification>
|
3
|
+
<Sid>NO1fb7086ceb85caed2265f17d7bf7981c</Sid>
|
4
|
+
<DateCreated>Sat, 07 Feb 2009 13:15:19 -0800</DateCreated>
|
5
|
+
<DateUpdated>Sat, 07 Feb 2009 13:15:19 -0800</DateUpdated>
|
6
|
+
<AccountSid>mysid</AccountSid>
|
7
|
+
<CallSid>CA42ed11f93dc08b952027ffbc406d0868</CallSid>
|
8
|
+
<Log>0</Log>
|
9
|
+
<ErrorCode>12345</ErrorCode>
|
10
|
+
<MoreInfo>http://www.twilio.com/docs/errors/12345</MoreInfo>
|
11
|
+
<MessageText>Unable to parse XML response</MessageText>
|
12
|
+
<MessageDate>Thu, 03 Apr 2008 04:36:32 -0400</MessageDate>
|
13
|
+
<RequestURL>http://yourserver.com/handleCall.php</RequestURL>
|
14
|
+
<RequestMethod>POST</RequestMethod>
|
15
|
+
<RequestVariables>Caller=4158675309&Called=4155551212...</RequestVariables>
|
16
|
+
<ResponseHeaders>Content-Length: 500</ResponseHeaders>
|
17
|
+
<ResponseBody><h1>Error parsing PHP script</h1></ResponseBody>
|
18
|
+
</Notification>
|
19
|
+
</TwilioResponse>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<TwilioResponse>
|
2
|
+
<Notifications page="0" numpages="10" pagesize="50" total="498" start="0" end="49">
|
3
|
+
<Notification>
|
4
|
+
<Sid>NO1fb7086ceb85caed2265f17d7bf7981c</Sid>
|
5
|
+
<DateCreated>Sat, 07 Feb 2009 13:15:19 -0800</DateCreated>
|
6
|
+
<DateUpdated>Sat, 07 Feb 2009 13:15:19 -0800</DateUpdated>
|
7
|
+
<AccountSid>mysid</AccountSid>
|
8
|
+
<CallSid>CA42ed11f93dc08b952027ffbc406d0868</CallSid>
|
9
|
+
<Log>0</Log>
|
10
|
+
<ErrorCode>12345</ErrorCode>
|
11
|
+
<MoreInfo>http://www.twilio.com/docs/errors/12345</MoreInfo>
|
12
|
+
<RequestURL>http://yourserver.com/handleCall.php</RequestURL>
|
13
|
+
<RequestMethod>POST</RequestMethod>
|
14
|
+
<MessageText>Unable to parse XML response</MessageText>
|
15
|
+
<MessageDate>Thu, 03 Apr 2008 04:36:32 -0400</MessageDate>
|
16
|
+
</Notification>
|
17
|
+
<Notification>
|
18
|
+
<Sid>NOe936fdac57d238e56fd346b89820d342</Sid>
|
19
|
+
<DateCreated>Sat, 07 Feb 2009 13:15:19 -0800</DateCreated>
|
20
|
+
<DateUpdated>Sat, 07 Feb 2009 13:15:19 -0800</DateUpdated>
|
21
|
+
<AccountSid>mysid</AccountSid>
|
22
|
+
<CallSid></CallSid>
|
23
|
+
<Log>1</Log>
|
24
|
+
<ErrorCode>67890</ErrorCode>
|
25
|
+
<MoreInfo>http://www.twilio.com/docs/errors/67890</MoreInfo>
|
26
|
+
<RequestURL>http://api.twilio.com/2008-08-01/Accounts/AC309475e5fede1b49e100272a8640f438/Calls</RequestURL>
|
27
|
+
<RequestMethod>POST</RequestMethod>
|
28
|
+
<MessageText>Unknown parameter received by the REST API: foo=bar</MessageText>
|
29
|
+
<MessageDate>Thu, 03 Apr 2008 04:36:32 -0400</MessageDate>
|
30
|
+
</Notification>
|
31
|
+
</Notifications>
|
32
|
+
</TwilioResponse>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<TwilioResponse>
|
2
|
+
<OutgoingCallerId>
|
3
|
+
<Sid>PNe536dfda7c6184afab78d980cb8cdf43</Sid>
|
4
|
+
<AccountSid>mysid</AccountSid>
|
5
|
+
<FriendlyName>My Home Phone Number</FriendlyName>
|
6
|
+
<PhoneNumber>4158675309</PhoneNumber>
|
7
|
+
<DateCreated>Tue, 01 Apr 2008 11:26:32 -0700</DateCreated>
|
8
|
+
<DateUpdated>Tue, 01 Apr 2008 11:26:32 -0700</DateUpdated>
|
9
|
+
</OutgoingCallerId>
|
10
|
+
</TwilioResponse>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<TwilioResponse>
|
2
|
+
<OutgoingCallerIds page="0" numpages="1" pagesize="50" total="2" start="0" end="0">
|
3
|
+
<OutgoingCallerId>
|
4
|
+
<Sid>PNe536dfda7c6184afab78d980cb8cdf43</Sid>
|
5
|
+
<AccountSid>mysid</AccountSid>
|
6
|
+
<FriendlyName>Bob Cell Phone</FriendlyName>
|
7
|
+
<PhoneNumber>4158675309</PhoneNumber>
|
8
|
+
<DateCreated>Tue, 01 Apr 2008 11:26:32 -0700</DateCreated>
|
9
|
+
<DateUpdated>Tue, 01 Apr 2008 11:26:32 -0700</DateUpdated>
|
10
|
+
</OutgoingCallerId>
|
11
|
+
<OutgoingCallerId>
|
12
|
+
<Sid>PNe536dfda7c6DDd455fed980cb83345FF</Sid>
|
13
|
+
<AccountSid>mysid</AccountSid>
|
14
|
+
<FriendlyName>Company Main Line</FriendlyName>
|
15
|
+
<PhoneNumber>4158675310</PhoneNumber>
|
16
|
+
<DateCreated>Tue, 01 Apr 2008 11:26:32 -0700</DateCreated>
|
17
|
+
<DateUpdated>Tue, 01 Apr 2008 11:26:32 -0700</DateUpdated>
|
18
|
+
</OutgoingCallerId>
|
19
|
+
</OutgoingCallerIds>
|
20
|
+
</TwilioResponse>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<TwilioResponse>
|
2
|
+
<Recording>
|
3
|
+
<Sid>RE41331862605f3d662488fdafda2e175f</Sid>
|
4
|
+
<AccountSid>mysid</AccountSid>
|
5
|
+
<CallSid>CAcd420fcb3c4b86e360ea0cc27ebc8698</CallSid>
|
6
|
+
<Duration>15</Duration>
|
7
|
+
<DateCreated>Tue, 01 Apr 2008 01:07:15 -0400</DateCreated>
|
8
|
+
<DateUpdated>Tue, 01 Apr 2008 01:07:15 -0400</DateUpdated>
|
9
|
+
</Recording>
|
10
|
+
</TwilioResponse>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<TwilioResponse>
|
2
|
+
<Recordings page="0" numpages="1" pagesize="50" total="16" start="0" end="15">
|
3
|
+
<Recording>
|
4
|
+
<Sid>RE41331862605f3d662488fdafda2e175f</Sid>
|
5
|
+
<AccountSid>mysid</AccountSid>
|
6
|
+
<CallSid>CAcd420fcb3c4b86e360ea0cc27ebc8698</CallSid>
|
7
|
+
<Duration>123</Duration>
|
8
|
+
<DateCreated>Tue, 01 Apr 2008 01:07:15 -0400</DateCreated>
|
9
|
+
<DateUpdated>Tue, 01 Apr 2008 01:07:15 -0400</DateUpdated>
|
10
|
+
</Recording>
|
11
|
+
<Recording>
|
12
|
+
<Sid>RE50358f2565ad3c542e004161c3aecfd2</Sid>
|
13
|
+
<AccountSid>mysid</AccountSid>
|
14
|
+
<CallSid>CAcd420fcb3c4b86e360ea0cc27ebc8698</CallSid>
|
15
|
+
<Duration>45</Duration>
|
16
|
+
<DateCreated>Tue, 01 Apr 2008 01:07:10 -0400</DateCreated>
|
17
|
+
<DateUpdated>Tue, 01 Apr 2008 01:07:10 -0400</DateUpdated>
|
18
|
+
</Recording>
|
19
|
+
</Recordings>
|
20
|
+
</TwilioResponse>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<TwilioResponse>
|
2
|
+
<Transcription>
|
3
|
+
<Sid>TRbdece5b75f2cd8f6ef38e0a10f5c4447</Sid>
|
4
|
+
<DateCreated>1235986685</DateCreated>
|
5
|
+
<DateUpdated>1235957924</DateUpdated>
|
6
|
+
<AccountSid>mysid</AccountSid>
|
7
|
+
<Status>completed</Status>
|
8
|
+
<RecordingSid>RE3870404da563592ef6a72136438a879c</RecordingSid>
|
9
|
+
<Duration>9</Duration>
|
10
|
+
<TranscriptionText>This is the body a transcribed recording</TranscriptionText>
|
11
|
+
<Price>-0.03000</Price>
|
12
|
+
</Transcription>
|
13
|
+
</TwilioResponse>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<TwilioResponse>
|
2
|
+
<Transcriptions page="0" numpages="1" pagesize="50" total="2" start="0" end="1">
|
3
|
+
<Transcription>
|
4
|
+
<Sid>TR685e9a2bdf89b978491b1afada63f078</Sid>
|
5
|
+
<DateCreated>1235986685</DateCreated>
|
6
|
+
<DateUpdated>1235957975</DateUpdated>
|
7
|
+
<AccountSid>mysid</AccountSid>
|
8
|
+
<Status>completed</Status>
|
9
|
+
<RecordingSid>RE3870404da563592ef6a72136438a879c</RecordingSid>
|
10
|
+
<Duration>9</Duration>
|
11
|
+
<TranscriptionText>This is the body of one transcribed recording</TranscriptionText>
|
12
|
+
<Price>-0.25000</Price>
|
13
|
+
</Transcription>
|
14
|
+
<Transcription>
|
15
|
+
<Sid>TRbdece5b75f2cd8f6ef38e0a10f5c4447</Sid>
|
16
|
+
<DateCreated>1235986685</DateCreated>
|
17
|
+
<DateUpdated>1235957924</DateUpdated>
|
18
|
+
<AccountSid>mysid</AccountSid>
|
19
|
+
<Status>completed</Status>
|
20
|
+
<RecordingSid>RE3870404da563592ef6a72136438a879c</RecordingSid>
|
21
|
+
<Duration>9</Duration>
|
22
|
+
<TranscriptionText>This is the body of another transcribed recording</TranscriptionText>
|
23
|
+
<Price>-0.03000</Price>
|
24
|
+
</Transcription>
|
25
|
+
</Transcriptions>
|
26
|
+
</TwilioResponse>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
say_hi:
|
2
|
+
response: <?xml version="1.0" encoding="UTF-8"?><Response><Say loop="1" language="en" voice="woman">hi</Say></Response>
|
3
|
+
|
4
|
+
say_hi_three_times:
|
5
|
+
response: <?xml version="1.0" encoding="UTF-8"?><Response><Say loop="3" language="en" voice="woman">hi</Say></Response>
|
6
|
+
|
7
|
+
say_hi_three_times_with_pause:
|
8
|
+
response: <?xml version="1.0" encoding="UTF-8"?><Response><Say loop="1" language="en" voice="woman">hi</Say><Pause/><Say loop="1" language="en" voice="woman">hi</Say><Pause/><Say loop="1" language="en" voice="woman">hi</Say></Response>
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'fakeweb'
|
4
|
+
require 'shoulda'
|
5
|
+
require 'matchy'
|
6
|
+
require 'yaml'
|
7
|
+
|
8
|
+
FakeWeb.allow_net_connect = false
|
9
|
+
|
10
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
11
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
12
|
+
require 'twilio'
|
13
|
+
|
14
|
+
class Test::Unit::TestCase
|
15
|
+
end
|
16
|
+
|
17
|
+
def fixture(filename)
|
18
|
+
path = File.join(File.dirname(__FILE__), "fixtures/xml/#{filename}.xml")
|
19
|
+
File.read path
|
20
|
+
end
|
21
|
+
|
22
|
+
def twilio_url(url=nil)
|
23
|
+
"https://mysid:mytoken@api.twilio.com:443/2008-08-01/Accounts/mysid#{'/' + url if url}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def verb_response(verb)
|
27
|
+
path = File.join(File.dirname(__FILE__), "fixtures/yml/verb_responses.yml")
|
28
|
+
YAML.load_file(path)[verb.to_s]['response']
|
29
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class AccountTest < Test::Unit::TestCase
|
4
|
+
context "An account" do
|
5
|
+
setup do
|
6
|
+
@connection = Twilio::Connection.new('mysid', 'mytoken')
|
7
|
+
@account = Twilio::Account.new(@connection)
|
8
|
+
end
|
9
|
+
|
10
|
+
should "be retrievable" do
|
11
|
+
fake_response = fixture(:account)
|
12
|
+
FakeWeb.register_uri(:get, twilio_url, :string => fake_response)
|
13
|
+
assert_equal @account.get, fake_response
|
14
|
+
end
|
15
|
+
|
16
|
+
should "be able to update name" do
|
17
|
+
fake_response = fixture(:account_renamed)
|
18
|
+
FakeWeb.register_uri(:put, twilio_url, :string => fake_response)
|
19
|
+
response = @account.update_name('Bubba')
|
20
|
+
assert_equal response, fake_response
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class CallTest < Test::Unit::TestCase
|
4
|
+
context "A call" do
|
5
|
+
setup do
|
6
|
+
@connection = Twilio::Connection.new('mysid', 'mytoken')
|
7
|
+
@call = Twilio::Call.new(@connection)
|
8
|
+
end
|
9
|
+
|
10
|
+
should "be retrievable as a list" do
|
11
|
+
fake_response = fixture(:calls)
|
12
|
+
FakeWeb.register_uri(:get, twilio_url('Calls'), :string => fake_response)
|
13
|
+
assert_equal @call.list, fake_response
|
14
|
+
end
|
15
|
+
|
16
|
+
should "be retrievable individually" do
|
17
|
+
fake_response = fixture(:call)
|
18
|
+
FakeWeb.register_uri(:get, twilio_url('Calls/CA42ed11f93dc08b952027ffbc406d0868'), :string => fake_response)
|
19
|
+
assert_equal @call.get('CA42ed11f93dc08b952027ffbc406d0868'), fake_response
|
20
|
+
end
|
21
|
+
|
22
|
+
should "be made" do
|
23
|
+
fake_response = fixture(:call_new)
|
24
|
+
FakeWeb.register_uri(:post, twilio_url('Calls'), :string => fake_response)
|
25
|
+
response = @call.make('4158675309', '4155551212', 'http://test.local/call_handler')
|
26
|
+
assert_equal response, fake_response
|
27
|
+
end
|
28
|
+
|
29
|
+
context "with segments" do
|
30
|
+
should "returns a list of Call resources that were segments created in the same call" do
|
31
|
+
fake_response = fixture(:calls)
|
32
|
+
FakeWeb.register_uri(:get, twilio_url('Calls/CA42ed11f93dc08b952027ffbc406d0868/Segments'), :string => fake_response)
|
33
|
+
assert_equal @call.segments('CA42ed11f93dc08b952027ffbc406d0868'), fake_response
|
34
|
+
end
|
35
|
+
|
36
|
+
should "returns a single Call resource for the CallSid and CallSegmentSid provided" do
|
37
|
+
fake_response = fixture(:calls)
|
38
|
+
FakeWeb.register_uri(:get, twilio_url('Calls/CA42ed11f93dc08b952027ffbc406d0868/Segments/abc123'), :string => fake_response)
|
39
|
+
assert_equal @call.segments('CA42ed11f93dc08b952027ffbc406d0868', 'abc123'), fake_response
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "with recordings" do
|
44
|
+
should "returns a list of recordings that were generated during the call" do
|
45
|
+
fake_response = fixture(:recordings)
|
46
|
+
FakeWeb.register_uri(:get, twilio_url('Calls/CA42ed11f93dc08b952027ffbc406d0868/Recordings'), :string => fake_response)
|
47
|
+
assert_equal @call.recordings('CA42ed11f93dc08b952027ffbc406d0868'), fake_response
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "with notifications" do
|
52
|
+
should "description" do
|
53
|
+
fake_response = fixture(:notifications)
|
54
|
+
FakeWeb.register_uri(:get, twilio_url('Calls/CA42ed11f93dc08b952027ffbc406d0868/Notifications'), :string => fake_response)
|
55
|
+
assert_equal @call.notifications('CA42ed11f93dc08b952027ffbc406d0868'), fake_response
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class ConnectionTest < Test::Unit::TestCase
|
4
|
+
context "A Twilio connection" do
|
5
|
+
setup do
|
6
|
+
@connection = Twilio::Connection.new('mysid', 'mytoken')
|
7
|
+
end
|
8
|
+
|
9
|
+
context "when initializing" do
|
10
|
+
should "have correct url" do
|
11
|
+
assert_equal "#{Twilio::Connection::TWILIO_URL}/mysid", @connection.class.base_uri
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class IncomingPhoneNumberTest < Test::Unit::TestCase
|
4
|
+
context "An incoming phone number" do
|
5
|
+
setup do
|
6
|
+
@connection = Twilio::Connection.new('mysid', 'mytoken')
|
7
|
+
@incoming = Twilio::IncomingPhoneNumber.new(@connection)
|
8
|
+
end
|
9
|
+
|
10
|
+
should "be retrievable as a list" do
|
11
|
+
fake_response = fixture(:incoming_phone_numbers)
|
12
|
+
FakeWeb.register_uri(:get, twilio_url('IncomingPhoneNumbers'), :string => fake_response)
|
13
|
+
assert_equal @incoming.list, fake_response
|
14
|
+
end
|
15
|
+
|
16
|
+
should "be retrievable individually" do
|
17
|
+
fake_response = fixture(:incoming_phone_number)
|
18
|
+
FakeWeb.register_uri(:get, twilio_url('IncomingPhoneNumbers/PNe536dfda7c6184afab78d980cb8cdf43'), :string => fake_response)
|
19
|
+
assert_equal @incoming.get('PNe536dfda7c6184afab78d980cb8cdf43'), fake_response
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class LocalPhoneNumberTest < Test::Unit::TestCase
|
4
|
+
context "A local phone number" do
|
5
|
+
setup do
|
6
|
+
@connection = Twilio::Connection.new('mysid', 'mytoken')
|
7
|
+
@local = Twilio::LocalPhoneNumber.new(@connection)
|
8
|
+
end
|
9
|
+
|
10
|
+
should "be retrievable as a list" do
|
11
|
+
fake_response = fixture(:incoming_phone_numbers)
|
12
|
+
FakeWeb.register_uri(:get, twilio_url('IncomingPhoneNumbers/Local'), :string => fake_response)
|
13
|
+
assert_equal @local.list, fake_response
|
14
|
+
end
|
15
|
+
|
16
|
+
should "be created" do
|
17
|
+
fake_response = fixture(:incoming_phone_number)
|
18
|
+
FakeWeb.register_uri(:post, twilio_url('IncomingPhoneNumbers/Local'), :string => fake_response)
|
19
|
+
response = @local.create('http://test.local/call_handler')
|
20
|
+
assert_equal response, fake_response
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class NotificationTest < Test::Unit::TestCase
|
4
|
+
context "A recording" do
|
5
|
+
setup do
|
6
|
+
@connection = Twilio::Connection.new('mysid', 'mytoken')
|
7
|
+
@notification = Twilio::Notification.new(@connection)
|
8
|
+
end
|
9
|
+
|
10
|
+
should "be retrievable as a list" do
|
11
|
+
fake_response = fixture(:notifications)
|
12
|
+
FakeWeb.register_uri(:get, twilio_url('Notifications'), :string => fake_response)
|
13
|
+
assert_equal @notification.list, fake_response
|
14
|
+
end
|
15
|
+
|
16
|
+
should "be retrievable individually" do
|
17
|
+
fake_response = fixture(:notification)
|
18
|
+
FakeWeb.register_uri(:get, twilio_url('Notifications/NO1fb7086ceb85caed2265f17d7bf7981c'), :string => fake_response)
|
19
|
+
assert_equal @notification.get('NO1fb7086ceb85caed2265f17d7bf7981c'), fake_response
|
20
|
+
end
|
21
|
+
|
22
|
+
should "be deleted" do
|
23
|
+
FakeWeb.register_uri(:delete, twilio_url('Notifications/NO1fb7086ceb85caed2265f17d7bf7981c'), :status => [ 204, "HTTPNoContent" ])
|
24
|
+
response = @notification.delete('NO1fb7086ceb85caed2265f17d7bf7981c')
|
25
|
+
assert response
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class OutgoingCallerIdTest < Test::Unit::TestCase
|
4
|
+
context "An outgoing caller id" do
|
5
|
+
setup do
|
6
|
+
@connection = Twilio::Connection.new('mysid', 'mytoken')
|
7
|
+
@caller_id = Twilio::OutgoingCallerId.new(@connection)
|
8
|
+
end
|
9
|
+
|
10
|
+
should "be retrievable as a list" do
|
11
|
+
fake_response = fixture(:outgoing_caller_ids)
|
12
|
+
FakeWeb.register_uri(:get, twilio_url('OutgoingCallerIds'), :string => fake_response)
|
13
|
+
assert_equal @caller_id.list, fake_response
|
14
|
+
end
|
15
|
+
|
16
|
+
should "be retrievable individually" do
|
17
|
+
fake_response = fixture(:outgoing_caller_id)
|
18
|
+
FakeWeb.register_uri(:get, twilio_url('OutgoingCallerIds/PNe536dfda7c6184afab78d980cb8cdf43'), :string => fake_response)
|
19
|
+
assert_equal @caller_id.get('PNe536dfda7c6184afab78d980cb8cdf43'), fake_response
|
20
|
+
end
|
21
|
+
|
22
|
+
should "be created" do
|
23
|
+
fake_response = fixture(:outgoing_caller_id_new)
|
24
|
+
FakeWeb.register_uri(:post, twilio_url('OutgoingCallerIds'), :string => fake_response)
|
25
|
+
response = @caller_id.create('4158675309', 'My Home Phone')
|
26
|
+
assert_equal response, fake_response
|
27
|
+
end
|
28
|
+
|
29
|
+
should "be able to update name" do
|
30
|
+
fake_response = fixture(:outgoing_caller_id)
|
31
|
+
FakeWeb.register_uri(:put, twilio_url('OutgoingCallerIds/PNe536dfda7c6184afab78d980cb8cdf43'), :string => fake_response)
|
32
|
+
response = @caller_id.update_name('PNe536dfda7c6184afab78d980cb8cdf43', 'My office line')
|
33
|
+
assert_equal response, fake_response
|
34
|
+
end
|
35
|
+
|
36
|
+
should "be deleted" do
|
37
|
+
FakeWeb.register_uri(:delete, twilio_url('OutgoingCallerIds/PNe536dfda7c6184afab78d980cb8cdf43'), :status => [ 204, "HTTPNoContent" ])
|
38
|
+
response = @caller_id.delete('PNe536dfda7c6184afab78d980cb8cdf43')
|
39
|
+
assert response
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class RecordingTest < Test::Unit::TestCase
|
4
|
+
context "A recording" do
|
5
|
+
setup do
|
6
|
+
@connection = Twilio::Connection.new('mysid', 'mytoken')
|
7
|
+
@recording = Twilio::Recording.new(@connection)
|
8
|
+
end
|
9
|
+
|
10
|
+
should "be retrievable as a list" do
|
11
|
+
fake_response = fixture(:recordings)
|
12
|
+
FakeWeb.register_uri(:get, twilio_url('Recordings'), :string => fake_response)
|
13
|
+
assert_equal @recording.list, fake_response
|
14
|
+
end
|
15
|
+
|
16
|
+
should "be retrievable individually" do
|
17
|
+
fake_response = fixture(:recording)
|
18
|
+
FakeWeb.register_uri(:get, twilio_url('Recordings/RE41331862605f3d662488fdafda2e175f'), :string => fake_response)
|
19
|
+
assert_equal @recording.get('RE41331862605f3d662488fdafda2e175f'), fake_response
|
20
|
+
end
|
21
|
+
|
22
|
+
should "be deleted" do
|
23
|
+
FakeWeb.register_uri(:delete, twilio_url('Recordings/RE41331862605f3d662488fdafda2e175f'), :status => [ 204, "HTTPNoContent" ])
|
24
|
+
response = @recording.delete('RE41331862605f3d662488fdafda2e175f')
|
25
|
+
assert response
|
26
|
+
end
|
27
|
+
|
28
|
+
context "with transcriptions" do
|
29
|
+
should "be retrievable as a list" do
|
30
|
+
fake_response = fixture(:transcriptions)
|
31
|
+
FakeWeb.register_uri(:get, twilio_url('Recordings/RE41331862605f3d662488fdafda2e175f/Transcriptions'), :string => fake_response)
|
32
|
+
assert_equal @recording.transcriptions('RE41331862605f3d662488fdafda2e175f'), fake_response
|
33
|
+
end
|
34
|
+
|
35
|
+
should "be retrievable individually" do
|
36
|
+
fake_response = fixture(:transcription)
|
37
|
+
FakeWeb.register_uri(:get, twilio_url('Recordings/RE41331862605f3d662488fdafda2e175f/Transcriptions/TRbdece5b75f2cd8f6ef38e0a10f5c4447'), :string => fake_response)
|
38
|
+
assert_equal @recording.transcriptions('RE41331862605f3d662488fdafda2e175f', 'TRbdece5b75f2cd8f6ef38e0a10f5c4447'), fake_response
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class TollFreePhoneNumberTest < Test::Unit::TestCase
|
4
|
+
context "A toll free phone number" do
|
5
|
+
setup do
|
6
|
+
@connection = Twilio::Connection.new('mysid', 'mytoken')
|
7
|
+
@toll_free = Twilio::TollFreePhoneNumber.new(@connection)
|
8
|
+
end
|
9
|
+
|
10
|
+
should "be retrievable as a list" do
|
11
|
+
fake_response = fixture(:incoming_phone_numbers)
|
12
|
+
FakeWeb.register_uri(:get, twilio_url('IncomingPhoneNumbers/TollFree'), :string => fake_response)
|
13
|
+
assert_equal @toll_free.list, fake_response
|
14
|
+
end
|
15
|
+
|
16
|
+
should "be created" do
|
17
|
+
fake_response = fixture(:incoming_phone_number)
|
18
|
+
FakeWeb.register_uri(:post, twilio_url('IncomingPhoneNumbers/TollFree'), :string => fake_response)
|
19
|
+
response = @toll_free.create('http://test.local/call_handler')
|
20
|
+
assert_equal response, fake_response
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class VerbTest < Test::Unit::TestCase
|
4
|
+
context "A Twilio Verb" do
|
5
|
+
should "say 'Hi'" do
|
6
|
+
assert_equal verb_response(:say_hi), Twilio::Verb.say('hi')
|
7
|
+
end
|
8
|
+
|
9
|
+
should "say 'Hi' three times" do
|
10
|
+
assert_equal verb_response(:say_hi_three_times), Twilio::Verb.say_3_times('hi')
|
11
|
+
end
|
12
|
+
|
13
|
+
should "say 'Hi' three times with pause" do
|
14
|
+
assert_equal verb_response(:say_hi_three_times_with_pause), Twilio::Verb.say_3_times_with_pause('hi')
|
15
|
+
end
|
16
|
+
|
17
|
+
should "raise not implemented error with play" do
|
18
|
+
assert_raise(NotImplementedError) { Twilio::Verb.play('something') }
|
19
|
+
end
|
20
|
+
|
21
|
+
should "raise not implemented error with gather" do
|
22
|
+
assert_raise(NotImplementedError) { Twilio::Verb.gather('something') }
|
23
|
+
end
|
24
|
+
|
25
|
+
should "raise not implemented error with record" do
|
26
|
+
assert_raise(NotImplementedError) { Twilio::Verb.record('something') }
|
27
|
+
end
|
28
|
+
|
29
|
+
should "raise not implemented error with dial" do
|
30
|
+
assert_raise(NotImplementedError) { Twilio::Verb.record('dial') }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: webficient-twilio
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Phil Misiowiec
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-06-04 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: builder
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: httparty
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
description:
|
36
|
+
email: github@webficient.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- LICENSE
|
43
|
+
- README.rdoc
|
44
|
+
files:
|
45
|
+
- LICENSE
|
46
|
+
- README.rdoc
|
47
|
+
- Rakefile
|
48
|
+
- VERSION.yml
|
49
|
+
- lib/twilio.rb
|
50
|
+
- lib/twilio/account.rb
|
51
|
+
- lib/twilio/call.rb
|
52
|
+
- lib/twilio/connection.rb
|
53
|
+
- lib/twilio/incoming_phone_number.rb
|
54
|
+
- lib/twilio/local_phone_number.rb
|
55
|
+
- lib/twilio/notification.rb
|
56
|
+
- lib/twilio/outgoing_caller_id.rb
|
57
|
+
- lib/twilio/recording.rb
|
58
|
+
- lib/twilio/toll_free_phone_number.rb
|
59
|
+
- lib/twilio/twilio_object.rb
|
60
|
+
- lib/twilio/verb.rb
|
61
|
+
- test/fixtures/xml/account.xml
|
62
|
+
- test/fixtures/xml/account_renamed.xml
|
63
|
+
- test/fixtures/xml/call.xml
|
64
|
+
- test/fixtures/xml/call_new.xml
|
65
|
+
- test/fixtures/xml/calls.xml
|
66
|
+
- test/fixtures/xml/incoming_phone_number.xml
|
67
|
+
- test/fixtures/xml/incoming_phone_numbers.xml
|
68
|
+
- test/fixtures/xml/notification.xml
|
69
|
+
- test/fixtures/xml/notifications.xml
|
70
|
+
- test/fixtures/xml/outgoing_caller_id.xml
|
71
|
+
- test/fixtures/xml/outgoing_caller_id_new.xml
|
72
|
+
- test/fixtures/xml/outgoing_caller_ids.xml
|
73
|
+
- test/fixtures/xml/recording.xml
|
74
|
+
- test/fixtures/xml/recordings.xml
|
75
|
+
- test/fixtures/xml/transcription.xml
|
76
|
+
- test/fixtures/xml/transcriptions.xml
|
77
|
+
- test/fixtures/yml/verb_responses.yml
|
78
|
+
- test/test_helper.rb
|
79
|
+
- test/twilio/account_test.rb
|
80
|
+
- test/twilio/call_test.rb
|
81
|
+
- test/twilio/connection_test.rb
|
82
|
+
- test/twilio/incoming_phone_number_test.rb
|
83
|
+
- test/twilio/local_phone_number_test.rb
|
84
|
+
- test/twilio/notification_test.rb
|
85
|
+
- test/twilio/outgoing_caller_id_test.rb
|
86
|
+
- test/twilio/recording_test.rb
|
87
|
+
- test/twilio/toll_free_phone_number_test.rb
|
88
|
+
- test/twilio/verb_test.rb
|
89
|
+
has_rdoc: true
|
90
|
+
homepage: http://github.com/webficient/twilio
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options:
|
93
|
+
- --charset=UTF-8
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: "0"
|
101
|
+
version:
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: "0"
|
107
|
+
version:
|
108
|
+
requirements: []
|
109
|
+
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 1.2.0
|
112
|
+
signing_key:
|
113
|
+
specification_version: 2
|
114
|
+
summary: Twilio API Client
|
115
|
+
test_files:
|
116
|
+
- test/test_helper.rb
|
117
|
+
- test/twilio/account_test.rb
|
118
|
+
- test/twilio/call_test.rb
|
119
|
+
- test/twilio/connection_test.rb
|
120
|
+
- test/twilio/incoming_phone_number_test.rb
|
121
|
+
- test/twilio/local_phone_number_test.rb
|
122
|
+
- test/twilio/notification_test.rb
|
123
|
+
- test/twilio/outgoing_caller_id_test.rb
|
124
|
+
- test/twilio/recording_test.rb
|
125
|
+
- test/twilio/toll_free_phone_number_test.rb
|
126
|
+
- test/twilio/verb_test.rb
|