twilio-ruby 3.11.5 → 3.12.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/.gitignore +1 -1
- data/.travis.yml +20 -8
- data/AUTHORS.md +29 -25
- data/{CHANGES → CHANGES.md} +45 -1
- data/Gemfile +8 -1
- data/{LICENSE → LICENSE.md} +1 -1
- data/Makefile +1 -2
- data/README.md +57 -26
- data/Rakefile +8 -10
- data/docs/getting-started.rst +3 -3
- data/docs/usage/applications.rst +5 -5
- data/docs/usage/basics.rst +17 -4
- data/docs/usage/caller-ids.rst +2 -2
- data/docs/usage/conferences.rst +5 -5
- data/docs/usage/errors.rst +1 -1
- data/docs/usage/messages.rst +6 -6
- data/docs/usage/notifications.rst +2 -2
- data/docs/usage/phone-calls.rst +7 -7
- data/docs/usage/phone-numbers.rst +12 -12
- data/docs/usage/queues.rst +6 -6
- data/docs/usage/recordings.rst +5 -5
- data/docs/usage/sip.rst +5 -5
- data/docs/usage/token-generation.rst +18 -3
- data/docs/usage/transcriptions.rst +1 -1
- data/docs/usage/twiml.rst +1 -1
- data/docs/usage/validation.rst +27 -1
- data/examples/print-call-log.rb +1 -1
- data/lib/rack/twilio_webhook_authentication.rb +40 -0
- data/lib/twilio-ruby/rest/call_feedback.rb +28 -0
- data/lib/twilio-ruby/rest/call_feedback_summary.rb +13 -0
- data/lib/twilio-ruby/rest/calls.rb +6 -1
- data/lib/twilio-ruby/rest/client.rb +43 -5
- data/lib/twilio-ruby/rest/list_resource.rb +10 -4
- data/lib/twilio-ruby/rest/usage/records.rb +2 -2
- data/lib/twilio-ruby/twiml/response.rb +1 -0
- data/lib/twilio-ruby/util/capability.rb +6 -3
- data/lib/twilio-ruby/util/configuration.rb +7 -0
- data/lib/twilio-ruby/util/request_validator.rb +3 -2
- data/lib/twilio-ruby/version.rb +1 -1
- data/lib/twilio-ruby.rb +25 -0
- data/spec/rack/twilio_webhook_authentication_spec.rb +76 -0
- data/spec/rest/account_spec.rb +20 -20
- data/spec/rest/call_feedback_spec.rb +12 -0
- data/spec/rest/call_feedback_summary_spec.rb +9 -0
- data/spec/rest/call_spec.rb +4 -4
- data/spec/rest/client_spec.rb +114 -38
- data/spec/rest/conference_spec.rb +2 -2
- data/spec/rest/instance_resource_spec.rb +3 -3
- data/spec/rest/message_spec.rb +2 -2
- data/spec/rest/numbers_spec.rb +12 -12
- data/spec/rest/queue_spec.rb +2 -2
- data/spec/rest/recording_spec.rb +2 -2
- data/spec/spec_helper.rb +12 -3
- data/spec/support/fakeweb.rb +2 -0
- data/spec/twilio_spec.rb +15 -0
- data/spec/util/capability_spec.rb +167 -118
- data/spec/util/configuration_spec.rb +13 -0
- data/spec/util/request_validator_spec.rb +31 -3
- data/spec/util/url_encode_spec.rb +1 -1
- data/twilio-ruby.gemspec +28 -27
- 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
|
data/spec/rest/account_spec.rb
CHANGED
@@ -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.
|
11
|
-
@account.incoming_phone_numbers.instance_variable_get('@path').
|
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.
|
16
|
-
@account.available_phone_numbers.instance_variable_get('@path').
|
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.
|
21
|
-
@account.outgoing_caller_ids.instance_variable_get('@path').
|
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.
|
26
|
-
@account.calls.instance_variable_get('@path').
|
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.
|
31
|
-
@account.conferences.instance_variable_get('@path').
|
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.
|
36
|
-
@account.queues.instance_variable_get('@path').
|
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.
|
41
|
-
@account.sms.instance_variable_get('@path').
|
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.
|
46
|
-
@account.recordings.instance_variable_get('@path').
|
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.
|
51
|
-
@account.transcriptions.instance_variable_get('@path').
|
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.
|
56
|
-
@account.notifications.instance_variable_get('@path').
|
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
|
data/spec/rest/call_spec.rb
CHANGED
@@ -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.
|
11
|
-
@call.recordings.instance_variable_get('@path').
|
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.
|
16
|
-
@call.notifications.instance_variable_get('@path').
|
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
|
data/spec/rest/client_spec.rb
CHANGED
@@ -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.
|
21
|
-
twilio.instance_variable_get('@auth_token').
|
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.
|
28
|
-
connection.port.
|
29
|
-
connection.use_ssl
|
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.
|
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.
|
42
|
-
connection.port.
|
43
|
-
connection.use_ssl
|
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.
|
51
|
-
connection.use_ssl
|
52
|
-
connection.open_timeout.
|
53
|
-
connection.read_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
|
60
|
-
connection.proxy_address.
|
61
|
-
connection.proxy_port.
|
62
|
-
connection.address.
|
63
|
-
connection.port.
|
64
|
-
connection.use_ssl
|
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
|
71
|
-
connection.proxy_address.
|
72
|
-
connection.proxy_port.
|
73
|
-
connection.address.
|
74
|
-
connection.port.
|
75
|
-
connection.use_ssl
|
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.
|
81
|
-
twilio.accounts.instance_variable_get('@path').
|
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.
|
87
|
-
twilio.account.instance_variable_get('@path').
|
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 = {
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
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.
|
7
|
-
conference.participants.instance_variable_get('@path').
|
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').
|
7
|
-
resource.instance_variable_get('@client').
|
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.
|
13
|
+
expect(resource.some_key).to eq('someValue')
|
14
14
|
end
|
15
15
|
end
|
data/spec/rest/message_spec.rb
CHANGED
@@ -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.
|
10
|
-
@message.media.instance_variable_get('@path').
|
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
|
data/spec/rest/numbers_spec.rb
CHANGED
@@ -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.
|
11
|
-
@country.local.instance_variable_get('@path').
|
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.
|
16
|
-
@country.toll_free.instance_variable_get('@path').
|
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.
|
21
|
-
@country.mobile.instance_variable_get('@path').
|
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.
|
34
|
-
@incoming_phone_numbers.local.instance_variable_get('@path').
|
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.
|
39
|
-
@incoming_phone_numbers.toll_free.instance_variable_get('@path').
|
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.
|
44
|
-
@incoming_phone_numbers.mobile.instance_variable_get('@path').
|
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
|
data/spec/rest/queue_spec.rb
CHANGED
@@ -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.
|
7
|
-
queue.members.instance_variable_get('@path').
|
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
|
data/spec/rest/recording_spec.rb
CHANGED
@@ -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.
|
7
|
-
call.transcriptions.instance_variable_get('@path').
|
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
|
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
|
-
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.expect_with :rspec do |c|
|
13
|
+
c.syntax = :expect
|
14
|
+
end
|
15
|
+
end
|
data/spec/twilio_spec.rb
ADDED
@@ -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
|