twilio-ruby 3.11.5 → 3.12.3

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.
Files changed (62) hide show
  1. checksums.yaml +13 -5
  2. data/.gitignore +1 -1
  3. data/.travis.yml +20 -8
  4. data/AUTHORS.md +29 -25
  5. data/{CHANGES → CHANGES.md} +45 -1
  6. data/Gemfile +8 -1
  7. data/{LICENSE → LICENSE.md} +1 -1
  8. data/Makefile +1 -2
  9. data/README.md +57 -26
  10. data/Rakefile +8 -10
  11. data/docs/getting-started.rst +3 -3
  12. data/docs/usage/applications.rst +5 -5
  13. data/docs/usage/basics.rst +17 -4
  14. data/docs/usage/caller-ids.rst +2 -2
  15. data/docs/usage/conferences.rst +5 -5
  16. data/docs/usage/errors.rst +1 -1
  17. data/docs/usage/messages.rst +6 -6
  18. data/docs/usage/notifications.rst +2 -2
  19. data/docs/usage/phone-calls.rst +7 -7
  20. data/docs/usage/phone-numbers.rst +12 -12
  21. data/docs/usage/queues.rst +6 -6
  22. data/docs/usage/recordings.rst +5 -5
  23. data/docs/usage/sip.rst +5 -5
  24. data/docs/usage/token-generation.rst +18 -3
  25. data/docs/usage/transcriptions.rst +1 -1
  26. data/docs/usage/twiml.rst +1 -1
  27. data/docs/usage/validation.rst +27 -1
  28. data/examples/print-call-log.rb +1 -1
  29. data/lib/rack/twilio_webhook_authentication.rb +40 -0
  30. data/lib/twilio-ruby/rest/call_feedback.rb +28 -0
  31. data/lib/twilio-ruby/rest/call_feedback_summary.rb +13 -0
  32. data/lib/twilio-ruby/rest/calls.rb +6 -1
  33. data/lib/twilio-ruby/rest/client.rb +43 -5
  34. data/lib/twilio-ruby/rest/list_resource.rb +10 -4
  35. data/lib/twilio-ruby/rest/usage/records.rb +2 -2
  36. data/lib/twilio-ruby/twiml/response.rb +1 -0
  37. data/lib/twilio-ruby/util/capability.rb +6 -3
  38. data/lib/twilio-ruby/util/configuration.rb +7 -0
  39. data/lib/twilio-ruby/util/request_validator.rb +3 -2
  40. data/lib/twilio-ruby/version.rb +1 -1
  41. data/lib/twilio-ruby.rb +25 -0
  42. data/spec/rack/twilio_webhook_authentication_spec.rb +76 -0
  43. data/spec/rest/account_spec.rb +20 -20
  44. data/spec/rest/call_feedback_spec.rb +12 -0
  45. data/spec/rest/call_feedback_summary_spec.rb +9 -0
  46. data/spec/rest/call_spec.rb +4 -4
  47. data/spec/rest/client_spec.rb +114 -38
  48. data/spec/rest/conference_spec.rb +2 -2
  49. data/spec/rest/instance_resource_spec.rb +3 -3
  50. data/spec/rest/message_spec.rb +2 -2
  51. data/spec/rest/numbers_spec.rb +12 -12
  52. data/spec/rest/queue_spec.rb +2 -2
  53. data/spec/rest/recording_spec.rb +2 -2
  54. data/spec/spec_helper.rb +12 -3
  55. data/spec/support/fakeweb.rb +2 -0
  56. data/spec/twilio_spec.rb +15 -0
  57. data/spec/util/capability_spec.rb +167 -118
  58. data/spec/util/configuration_spec.rb +13 -0
  59. data/spec/util/request_validator_spec.rb +31 -3
  60. data/spec/util/url_encode_spec.rb +1 -1
  61. data/twilio-ruby.gemspec +28 -27
  62. metadata +46 -71
data/lib/twilio-ruby.rb CHANGED
@@ -5,10 +5,12 @@ require 'multi_json'
5
5
  require 'cgi'
6
6
  require 'openssl'
7
7
  require 'base64'
8
+ require 'forwardable'
8
9
  require 'jwt'
9
10
 
10
11
  require 'twilio-ruby/version' unless defined?(Twilio::VERSION)
11
12
  require 'twilio-ruby/util'
13
+ require 'twilio-ruby/util/configuration'
12
14
  require 'twilio-ruby/util/request_validator'
13
15
  require 'twilio-ruby/util/capability'
14
16
  require 'twilio-ruby/twiml/response'
@@ -19,6 +21,8 @@ require 'twilio-ruby/rest/instance_resource'
19
21
  require 'twilio-ruby/rest/sandbox'
20
22
  require 'twilio-ruby/rest/accounts'
21
23
  require 'twilio-ruby/rest/calls'
24
+ require 'twilio-ruby/rest/call_feedback'
25
+ require 'twilio-ruby/rest/call_feedback_summary'
22
26
  require 'twilio-ruby/rest/sms'
23
27
  require 'twilio-ruby/rest/sms/short_codes'
24
28
  require 'twilio-ruby/rest/sms/messages'
@@ -56,3 +60,24 @@ require 'twilio-ruby/rest/recordings'
56
60
  require 'twilio-ruby/rest/transcriptions'
57
61
  require 'twilio-ruby/rest/notifications'
58
62
  require 'twilio-ruby/rest/client'
63
+ require 'rack/twilio_webhook_authentication'
64
+
65
+ module Twilio
66
+ extend SingleForwardable
67
+
68
+ def_delegators :configuration, :account_sid, :auth_token
69
+
70
+ ##
71
+ # Pre-configure with account SID and auth token so that you don't need to
72
+ # pass them to various initializers each time.
73
+ def self.configure(&block)
74
+ yield configuration
75
+ end
76
+
77
+ ##
78
+ # Returns an existing or instantiates a new configuration object.
79
+ def self.configuration
80
+ @configuration ||= Util::Configuration.new
81
+ end
82
+ private_class_method :configuration
83
+ end
@@ -0,0 +1,76 @@
1
+ require 'spec_helper'
2
+ require 'rack/mock'
3
+
4
+ describe Rack::TwilioWebhookAuthentication do
5
+ before do
6
+ @app = lambda {|env| [200, {'Content-Type' => 'text/plain'}, ['Hello']] }
7
+ end
8
+
9
+ describe 'new' do
10
+ it 'should initialize with an app, auth token and a path' do
11
+ expect {
12
+ Rack::TwilioWebhookAuthentication.new(@app, 'ABC', /\/voice/)
13
+ }.not_to raise_error
14
+ end
15
+
16
+ it 'should initialize with an app, auth token and paths' do
17
+ expect {
18
+ Rack::TwilioWebhookAuthentication.new(@app, 'ABC', /\/voice/, /\/sms/)
19
+ }.not_to raise_error
20
+ end
21
+ end
22
+
23
+ describe 'calling against one path' do
24
+ before do
25
+ @middleware = Rack::TwilioWebhookAuthentication.new(@app, 'ABC', /\/voice/)
26
+ end
27
+
28
+ it 'should not intercept when the path doesn\'t match' do
29
+ expect(Twilio::Util::RequestValidator).to_not receive(:validate)
30
+ request = Rack::MockRequest.env_for('/sms')
31
+ status, headers, body = @middleware.call(request)
32
+ expect(status).to be(200)
33
+ end
34
+
35
+ it 'should allow a request through if it validates' do
36
+ expect_any_instance_of(Twilio::Util::RequestValidator).to receive(:validate).and_return(true)
37
+ request = Rack::MockRequest.env_for('/voice')
38
+ status, headers, body = @middleware.call(request)
39
+ expect(status).to be(200)
40
+ end
41
+
42
+ it 'should short circuit a request to 403 if it does not validate' do
43
+ expect_any_instance_of(Twilio::Util::RequestValidator).to receive(:validate).and_return(false)
44
+ request = Rack::MockRequest.env_for('/voice')
45
+ status, headers, body = @middleware.call(request)
46
+ expect(status).to be(403)
47
+ end
48
+ end
49
+
50
+ describe 'calling against many paths' do
51
+ before do
52
+ @middleware = Rack::TwilioWebhookAuthentication.new(@app, 'ABC', /\/voice/, /\/sms/)
53
+ end
54
+
55
+ it 'should not intercept when the path doesn\'t match' do
56
+ expect(Twilio::Util::RequestValidator).to_not receive(:validate)
57
+ request = Rack::MockRequest.env_for('icesms')
58
+ status, headers, body = @middleware.call(request)
59
+ expect(status).to be(200)
60
+ end
61
+
62
+ it 'shold allow a request through if it validates' do
63
+ expect_any_instance_of(Twilio::Util::RequestValidator).to receive(:validate).and_return(true)
64
+ request = Rack::MockRequest.env_for('/sms')
65
+ status, headers, body = @middleware.call(request)
66
+ expect(status).to be(200)
67
+ end
68
+
69
+ it 'should short circuit a request to 403 if it does not validate' do
70
+ expect_any_instance_of(Twilio::Util::RequestValidator).to receive(:validate).and_return(false)
71
+ request = Rack::MockRequest.env_for('/sms')
72
+ status, headers, body = @middleware.call(request)
73
+ expect(status).to be(403)
74
+ end
75
+ end
76
+ end
@@ -7,52 +7,52 @@ describe Twilio::REST::Account do
7
7
  end
8
8
 
9
9
  it 'sets up incoming phone numbers resources object' do
10
- @account.should respond_to(:incoming_phone_numbers)
11
- @account.incoming_phone_numbers.instance_variable_get('@path').should == 'someUri/IncomingPhoneNumbers'
10
+ expect(@account).to respond_to(:incoming_phone_numbers)
11
+ expect(@account.incoming_phone_numbers.instance_variable_get('@path')).to eq('someUri/IncomingPhoneNumbers')
12
12
  end
13
13
 
14
14
  it 'sets up an available phone numbers resources object' do
15
- @account.should respond_to(:available_phone_numbers)
16
- @account.available_phone_numbers.instance_variable_get('@path').should == 'someUri/AvailablePhoneNumbers'
15
+ expect(@account).to respond_to(:available_phone_numbers)
16
+ expect(@account.available_phone_numbers.instance_variable_get('@path')).to eq('someUri/AvailablePhoneNumbers')
17
17
  end
18
18
 
19
19
  it 'sets up an outgoing caller ids resources object' do
20
- @account.should respond_to(:outgoing_caller_ids)
21
- @account.outgoing_caller_ids.instance_variable_get('@path').should == 'someUri/OutgoingCallerIds'
20
+ expect(@account).to respond_to(:outgoing_caller_ids)
21
+ expect(@account.outgoing_caller_ids.instance_variable_get('@path')).to eq('someUri/OutgoingCallerIds')
22
22
  end
23
23
 
24
24
  it 'sets up a calls resources object' do
25
- @account.should respond_to(:calls)
26
- @account.calls.instance_variable_get('@path').should == 'someUri/Calls'
25
+ expect(@account).to respond_to(:calls)
26
+ expect(@account.calls.instance_variable_get('@path')).to eq('someUri/Calls')
27
27
  end
28
28
 
29
29
  it 'sets up a conferences resources object' do
30
- @account.should respond_to(:conferences)
31
- @account.conferences.instance_variable_get('@path').should == 'someUri/Conferences'
30
+ expect(@account).to respond_to(:conferences)
31
+ expect(@account.conferences.instance_variable_get('@path')).to eq('someUri/Conferences')
32
32
  end
33
33
 
34
34
  it 'sets up a queues resources object' do
35
- @account.should respond_to(:queues)
36
- @account.queues.instance_variable_get('@path').should == 'someUri/Queues'
35
+ expect(@account).to respond_to(:queues)
36
+ expect(@account.queues.instance_variable_get('@path')).to eq('someUri/Queues')
37
37
  end
38
38
 
39
39
  it 'sets up a sms resource object' do
40
- @account.should respond_to(:sms)
41
- @account.sms.instance_variable_get('@path').should == 'someUri/SMS'
40
+ expect(@account).to respond_to(:sms)
41
+ expect(@account.sms.instance_variable_get('@path')).to eq('someUri/SMS')
42
42
  end
43
43
 
44
44
  it 'sets up a recordings resources object' do
45
- @account.should respond_to(:recordings)
46
- @account.recordings.instance_variable_get('@path').should == 'someUri/Recordings'
45
+ expect(@account).to respond_to(:recordings)
46
+ expect(@account.recordings.instance_variable_get('@path')).to eq('someUri/Recordings')
47
47
  end
48
48
 
49
49
  it 'sets up a transcriptions resources object' do
50
- @account.should respond_to(:transcriptions)
51
- @account.transcriptions.instance_variable_get('@path').should == 'someUri/Transcriptions'
50
+ expect(@account).to respond_to(:transcriptions)
51
+ expect(@account.transcriptions.instance_variable_get('@path')).to eq('someUri/Transcriptions')
52
52
  end
53
53
 
54
54
  it 'sets up a notifications resources object' do
55
- @account.should respond_to(:notifications)
56
- @account.notifications.instance_variable_get('@path').should == 'someUri/Notifications'
55
+ expect(@account).to respond_to(:notifications)
56
+ expect(@account.notifications.instance_variable_get('@path')).to eq('someUri/Notifications')
57
57
  end
58
58
  end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe Twilio::REST::Feedback do
4
+ before do
5
+ @call = Twilio::REST::Call.new('someUri', 'someClient')
6
+ end
7
+
8
+ it 'sets up a feedback resources object' do
9
+ expect(@call).to respond_to(:feedback)
10
+ expect(@call.feedback.instance_variable_get('@path')).to eq('someUri/Feedback')
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe Twilio::REST::FeedbackSummary do
4
+ it 'creates a feedback summary object' do
5
+ calls = Twilio::REST::Calls.new('someUri', 'someClient')
6
+ expect(calls).to respond_to(:feedback_summary)
7
+ expect(calls.feedback_summary.instance_variable_get('@path')).to eq('someUri/FeedbackSummary')
8
+ end
9
+ end
@@ -7,12 +7,12 @@ describe Twilio::REST::Call do
7
7
  end
8
8
 
9
9
  it 'sets up a recordings resources object' do
10
- @call.should respond_to(:recordings)
11
- @call.recordings.instance_variable_get('@path').should == 'someUri/Recordings'
10
+ expect(@call).to respond_to(:recordings)
11
+ expect(@call.recordings.instance_variable_get('@path')).to eq('someUri/Recordings')
12
12
  end
13
13
 
14
14
  it 'sets up a notifications resources object' do
15
- @call.should respond_to(:notifications)
16
- @call.notifications.instance_variable_get('@path').should == 'someUri/Notifications'
15
+ expect(@call).to respond_to(:notifications)
16
+ expect(@call.notifications.instance_variable_get('@path')).to eq('someUri/Notifications')
17
17
  end
18
18
  end
@@ -1,6 +1,65 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Twilio::REST::Client do
4
+ describe 'config at class level' do
5
+ after(:each) do
6
+ Twilio.instance_variable_set('@configuration', nil)
7
+ end
8
+
9
+ it 'should set the account sid and auth token with a config block' do
10
+ Twilio.configure do |config|
11
+ config.account_sid = 'someSid'
12
+ config.auth_token = 'someToken'
13
+ end
14
+
15
+ client = Twilio::REST::Client.new
16
+ expect(client.account_sid).to eq('someSid')
17
+ expect(client.instance_variable_get('@auth_token')).to eq('someToken')
18
+ end
19
+
20
+ it 'should overwrite account sid and auth token if passed to initializer' do
21
+ Twilio.configure do |config|
22
+ config.account_sid = 'someSid'
23
+ config.auth_token = 'someToken'
24
+ end
25
+
26
+ client = Twilio::REST::Client.new 'otherSid', 'otherToken'
27
+ expect(client.account_sid).to eq('otherSid')
28
+ expect(client.instance_variable_get('@auth_token')).to eq('otherToken')
29
+ end
30
+
31
+ it 'should overwrite the account sid if only the sid is given' do
32
+ Twilio.configure do |config|
33
+ config.account_sid = 'someSid'
34
+ config.auth_token = 'someToken'
35
+ end
36
+
37
+ client = Twilio::REST::Client.new 'otherSid'
38
+ expect(client.account_sid).to eq('otherSid')
39
+ expect(client.instance_variable_get('@auth_token')).to eq('someToken')
40
+ end
41
+
42
+ it 'should allow options after setting up auth with config' do
43
+ Twilio.configure do |config|
44
+ config.account_sid = 'someSid'
45
+ config.auth_token = 'someToken'
46
+ end
47
+
48
+ client = Twilio::REST::Client.new :host => 'api.faketwilio.com'
49
+
50
+ connection = client.instance_variable_get('@connection')
51
+ expect(connection.address).to eq('api.faketwilio.com')
52
+ end
53
+
54
+ it 'should throw an argument error if the sid and token isn\'t set' do
55
+ expect { Twilio::REST::Client.new }.to raise_error(ArgumentError)
56
+ end
57
+
58
+ it 'should throw an argument error if only the account_sid is set' do
59
+ expect { Twilio::REST::Client.new 'someSid' }.to raise_error(ArgumentError)
60
+ end
61
+ end
62
+
4
63
  it 'should not raise an error if the response body is empty' do
5
64
  FakeWeb.register_uri(:any, %r/api\.twilio\.com/, :body => '')
6
65
  twilio = Twilio::REST::Client.new('someSid', 'someToken')
@@ -17,84 +76,101 @@ describe Twilio::REST::Client do
17
76
 
18
77
  it 'should set up a new client instance with the given sid and token' do
19
78
  twilio = Twilio::REST::Client.new('someSid', 'someToken')
20
- twilio.account_sid.should == 'someSid'
21
- twilio.instance_variable_get('@auth_token').should == 'someToken'
79
+ expect(twilio.account_sid).to eq('someSid')
80
+ expect(twilio.instance_variable_get('@auth_token')).to eq('someToken')
22
81
  end
23
-
82
+
24
83
  it 'should set up the proper default http ssl connection' do
25
84
  twilio = Twilio::REST::Client.new('someSid', 'someToken')
26
85
  connection = twilio.instance_variable_get('@connection')
27
- connection.address.should == 'api.twilio.com'
28
- connection.port.should == 443
29
- connection.use_ssl?.should == true
86
+ expect(connection.address).to eq('api.twilio.com')
87
+ expect(connection.port).to eq(443)
88
+ expect(connection.use_ssl?).to eq(true)
30
89
  end
31
-
90
+
32
91
  it 'should set up the requested ssl verification ca_file if provided' do
33
92
  twilio = Twilio::REST::Client.new('someSid', 'someToken', :ssl_ca_file => '/path/to/ca/file')
34
93
  connection = twilio.instance_variable_get('@connection')
35
- connection.ca_file.should == '/path/to/ca/file'
94
+ expect(connection.ca_file).to eq('/path/to/ca/file')
36
95
  end
37
96
 
38
97
  it 'should set up the proper http ssl connection when a different domain is given' do
39
98
  twilio = Twilio::REST::Client.new('someSid', 'someToken', :host => 'api.faketwilio.com')
40
99
  connection = twilio.instance_variable_get('@connection')
41
- connection.address.should == 'api.faketwilio.com'
42
- connection.port.should == 443
43
- connection.use_ssl?.should == true
100
+ expect(connection.address).to eq('api.faketwilio.com')
101
+ expect(connection.port).to eq(443)
102
+ expect(connection.use_ssl?).to eq(true)
44
103
  end
45
104
 
46
105
  it 'should adjust the open and read timeouts on the underlying Net::HTTP object when asked' do
47
106
  timeout = rand(30)
48
107
  twilio = Twilio::REST::Client.new('someSid', 'someToken', :timeout => timeout)
49
108
  connection = twilio.instance_variable_get('@connection')
50
- connection.port.should == 443
51
- connection.use_ssl?.should == true
52
- connection.open_timeout.should == timeout
53
- connection.read_timeout.should == timeout
109
+ expect(connection.port).to eq(443)
110
+ expect(connection.use_ssl?).to eq(true)
111
+ expect(connection.open_timeout).to eq(timeout)
112
+ expect(connection.read_timeout).to eq(timeout)
54
113
  end
55
114
 
56
115
  it 'should set up the proper http ssl connection when a proxy_host is given' do
57
116
  twilio = Twilio::REST::Client.new('someSid', 'someToken', :host => 'api.faketwilio.com', :proxy_addr => 'localhost')
58
117
  connection = twilio.instance_variable_get('@connection')
59
- connection.proxy?.should == true
60
- connection.proxy_address.should == 'localhost'
61
- connection.proxy_port.should == 80
62
- connection.address.should == 'api.faketwilio.com'
63
- connection.port.should == 443
64
- connection.use_ssl?.should == true
118
+ expect(connection.proxy?).to eq(true)
119
+ expect(connection.proxy_address).to eq('localhost')
120
+ expect(connection.proxy_port).to eq(80)
121
+ expect(connection.address).to eq('api.faketwilio.com')
122
+ expect(connection.port).to eq(443)
123
+ expect(connection.use_ssl?).to eq(true)
65
124
  end
66
125
 
67
126
  it 'should set up the proper http ssl connection when a proxy_host and proxy_port are given' do
68
127
  twilio = Twilio::REST::Client.new('someSid', 'someToken', :host => 'api.faketwilio.com', :proxy_addr => 'localhost', :proxy_port => 13128)
69
128
  connection = twilio.instance_variable_get('@connection')
70
- connection.proxy?.should == true
71
- connection.proxy_address.should == 'localhost'
72
- connection.proxy_port.should == 13128
73
- connection.address.should == 'api.faketwilio.com'
74
- connection.port.should == 443
75
- connection.use_ssl?.should == true
129
+ expect(connection.proxy?).to eq(true)
130
+ expect(connection.proxy_address).to eq('localhost')
131
+ expect(connection.proxy_port).to eq(13128)
132
+ expect(connection.address).to eq('api.faketwilio.com')
133
+ expect(connection.port).to eq(443)
134
+ expect(connection.use_ssl?).to eq(true)
76
135
  end
77
136
 
78
137
  it 'should set up an accounts resources object' do
79
138
  twilio = Twilio::REST::Client.new('someSid', 'someToken')
80
- twilio.should respond_to(:accounts)
81
- twilio.accounts.instance_variable_get('@path').should == '/2010-04-01/Accounts'
139
+ expect(twilio).to respond_to(:accounts)
140
+ expect(twilio.accounts.instance_variable_get('@path')).to eq('/2010-04-01/Accounts')
82
141
  end
83
142
 
84
143
  it 'should set up an account object with the given sid' do
85
144
  twilio = Twilio::REST::Client.new('someSid', 'someToken')
86
- twilio.should respond_to(:account)
87
- twilio.account.instance_variable_get('@path').should == '/2010-04-01/Accounts/someSid'
145
+ expect(twilio).to respond_to(:account)
146
+ expect(twilio.account.instance_variable_get('@path')).to eq('/2010-04-01/Accounts/someSid')
147
+ end
148
+
149
+ [
150
+ :sandbox, :available_phone_numbers, :incoming_phone_numbers,
151
+ :calls, :outgoing_caller_ids, :conferences, :sms, :recordings,
152
+ :transcriptions, :notifications, :applications, :connect_apps,
153
+ :authorized_connect_apps, :queues, :usage, :messages, :media, :sip
154
+ ].each do |method|
155
+ it "should delegate the client method #{method} to the account object" do
156
+ client = Twilio::REST::Client.new('someSid', 'someToken')
157
+ expect(client).to respond_to(method)
158
+ expect(client.send(method)).to eq(client.account.send(method))
159
+ end
88
160
  end
89
161
 
90
162
  it 'should convert all parameter names to Twilio-style names' do
91
163
  twilio = Twilio::REST::Client.new('someSid', 'someToken')
92
- untwilified = {:sms_url => 'someUrl', 'voiceFallbackUrl' => 'anotherUrl',
93
- 'Status_callback' => 'yetAnotherUrl'}
94
- twilified = {:SmsUrl => 'someUrl', :VoiceFallbackUrl => 'anotherUrl',
95
- :StatusCallback => 'yetAnotherUrl'}
96
- twilio.instance_eval do
97
- twilify(untwilified).should == twilified
98
- end
164
+ untwilified = {
165
+ :sms_url => 'someUrl',
166
+ 'voiceFallbackUrl' => 'anotherUrl',
167
+ 'Status_callback' => 'yetAnotherUrl'
168
+ }
169
+ twilified = {
170
+ :SmsUrl => 'someUrl',
171
+ :VoiceFallbackUrl => 'anotherUrl',
172
+ :StatusCallback => 'yetAnotherUrl'
173
+ }
174
+ expect(twilio.twilify(untwilified)).to eq(twilified)
99
175
  end
100
176
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe Twilio::REST::Conference do
4
4
  it 'should set up a participants resources object' do
5
5
  conference = Twilio::REST::Conference.new('someUri', 'someClient')
6
- conference.should respond_to(:participants)
7
- conference.participants.instance_variable_get('@path').should == 'someUri/Participants'
6
+ expect(conference).to respond_to(:participants)
7
+ expect(conference.participants.instance_variable_get('@path')).to eq('someUri/Participants')
8
8
  end
9
9
  end
@@ -3,13 +3,13 @@ require 'spec_helper'
3
3
  describe Twilio::REST::InstanceResource do
4
4
  it 'should set up an internal reference to the uri and client' do
5
5
  resource = Twilio::REST::InstanceResource.new('some/uri', 'someClient')
6
- resource.instance_variable_get('@path').should == 'some/uri'
7
- resource.instance_variable_get('@client').should == 'someClient'
6
+ expect(resource.instance_variable_get('@path')).to eq('some/uri')
7
+ expect(resource.instance_variable_get('@client')).to eq('someClient')
8
8
  end
9
9
 
10
10
  it 'should set up object properties if passed' do
11
11
  params = {'SomeKey' => 'someValue'}
12
12
  resource = Twilio::REST::InstanceResource.new('uri', 'client', params)
13
- resource.some_key.should == 'someValue'
13
+ expect(resource.some_key).to eq('someValue')
14
14
  end
15
15
  end
@@ -6,7 +6,7 @@ describe Twilio::REST::Message do
6
6
  end
7
7
 
8
8
  it 'sets up a media resources object' do
9
- @message.should respond_to(:media)
10
- @message.media.instance_variable_get('@path').should == 'someUri/Media'
9
+ expect(@message).to respond_to(:media)
10
+ expect(@message.media.instance_variable_get('@path')).to eq('someUri/Media')
11
11
  end
12
12
  end
@@ -7,18 +7,18 @@ describe Twilio::REST::Country do
7
7
  end
8
8
 
9
9
  it 'sets up a local resources object' do
10
- @country.should respond_to(:local)
11
- @country.local.instance_variable_get('@path').should == 'someUri/Local'
10
+ expect(@country).to respond_to(:local)
11
+ expect(@country.local.instance_variable_get('@path')).to eq('someUri/Local')
12
12
  end
13
13
 
14
14
  it 'sets up a toll_free resources object' do
15
- @country.should respond_to(:toll_free)
16
- @country.toll_free.instance_variable_get('@path').should == 'someUri/TollFree'
15
+ expect(@country).to respond_to(:toll_free)
16
+ expect(@country.toll_free.instance_variable_get('@path')).to eq('someUri/TollFree')
17
17
  end
18
18
 
19
19
  it 'sets up a mobile resources object' do
20
- @country.should respond_to(:mobile)
21
- @country.mobile.instance_variable_get('@path').should == 'someUri/Mobile'
20
+ expect(@country).to respond_to(:mobile)
21
+ expect(@country.mobile.instance_variable_get('@path')).to eq('someUri/Mobile')
22
22
  end
23
23
 
24
24
  end
@@ -30,17 +30,17 @@ describe Twilio::REST::NumberType do
30
30
  end
31
31
 
32
32
  it 'sets up a local resources object' do
33
- @incoming_phone_numbers.should respond_to(:local)
34
- @incoming_phone_numbers.local.instance_variable_get('@path').should == 'someUri/Local'
33
+ expect(@incoming_phone_numbers).to respond_to(:local)
34
+ expect(@incoming_phone_numbers.local.instance_variable_get('@path')).to eq('someUri/Local')
35
35
  end
36
36
 
37
37
  it 'sets up a toll_free resources object' do
38
- @incoming_phone_numbers.should respond_to(:toll_free)
39
- @incoming_phone_numbers.toll_free.instance_variable_get('@path').should == 'someUri/TollFree'
38
+ expect(@incoming_phone_numbers).to respond_to(:toll_free)
39
+ expect(@incoming_phone_numbers.toll_free.instance_variable_get('@path')).to eq('someUri/TollFree')
40
40
  end
41
41
 
42
42
  it 'sets up a mobile resources object' do
43
- @incoming_phone_numbers.should respond_to(:mobile)
44
- @incoming_phone_numbers.mobile.instance_variable_get('@path').should == 'someUri/Mobile'
43
+ expect(@incoming_phone_numbers).to respond_to(:mobile)
44
+ expect(@incoming_phone_numbers.mobile.instance_variable_get('@path')).to eq('someUri/Mobile')
45
45
  end
46
46
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe Twilio::REST::Queue do
4
4
  it 'should set up a members resources object' do
5
5
  queue = Twilio::REST::Queue.new('someUri', 'someClient')
6
- queue.should respond_to(:members)
7
- queue.members.instance_variable_get('@path').should == 'someUri/Members'
6
+ expect(queue).to respond_to(:members)
7
+ expect(queue.members.instance_variable_get('@path')).to eq('someUri/Members')
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe Twilio::REST::Recording do
4
4
  it 'should set up a transcriptions resources object' do
5
5
  call = Twilio::REST::Recording.new('someUri', 'someClient')
6
- call.should respond_to(:transcriptions)
7
- call.transcriptions.instance_variable_get('@path').should == 'someUri/Transcriptions'
6
+ expect(call).to respond_to(:transcriptions)
7
+ expect(call.transcriptions.instance_variable_get('@path')).to eq('someUri/Transcriptions')
8
8
  end
9
9
  end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,15 @@
1
- $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+
3
+ require 'bundler'
4
+ Bundler.setup
5
+
6
+ Dir.glob(File.expand_path("../support/**/*.rb", __FILE__), &method(:require))
7
+
2
8
  require 'twilio-ruby'
3
- require 'fakeweb'
4
9
  require 'rack'
5
10
 
6
- FakeWeb.allow_net_connect = false
11
+ RSpec.configure do |config|
12
+ config.expect_with :rspec do |c|
13
+ c.syntax = :expect
14
+ end
15
+ end
@@ -0,0 +1,2 @@
1
+ require 'fakeweb'
2
+ FakeWeb.allow_net_connect = false
@@ -0,0 +1,15 @@
1
+ describe Twilio do
2
+ after(:each) do
3
+ Twilio.instance_variable_set('@configuration', nil)
4
+ end
5
+
6
+ it 'should set the account sid and auth token with a config block' do
7
+ Twilio.configure do |config|
8
+ config.account_sid = 'someSid'
9
+ config.auth_token = 'someToken'
10
+ end
11
+
12
+ expect(Twilio.account_sid).to eq('someSid')
13
+ expect(Twilio.auth_token).to eq('someToken')
14
+ end
15
+ end