twilio-ruby 3.11.5 → 4.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.
- checksums.yaml +13 -5
- data/.gitignore +1 -1
- data/.travis.yml +20 -9
- data/AUTHORS.md +32 -25
- data/CHANGES.md +203 -0
- data/Gemfile +8 -1
- data/{LICENSE → LICENSE.md} +4 -2
- data/Makefile +1 -2
- data/README.md +70 -39
- data/Rakefile +8 -10
- data/docs/faq.rst +3 -3
- data/docs/getting-started.rst +17 -12
- data/docs/index.rst +15 -0
- data/docs/usage/accounts.rst +6 -6
- data/docs/usage/addresses.rst +101 -0
- data/docs/usage/applications.rst +10 -10
- data/docs/usage/basics.rst +17 -4
- data/docs/usage/caller-ids.rst +4 -2
- data/docs/usage/conferences.rst +11 -11
- data/docs/usage/errors.rst +7 -7
- data/docs/usage/messages.rst +48 -20
- data/docs/usage/notifications.rst +6 -4
- data/docs/usage/phone-calls.rst +33 -14
- data/docs/usage/phone-numbers.rst +45 -31
- data/docs/usage/queues.rst +8 -8
- data/docs/usage/recordings.rst +12 -10
- data/docs/usage/sip.rst +15 -14
- data/docs/usage/taskrouter-tokens.rst +98 -0
- data/docs/usage/taskrouter.rst +226 -0
- data/docs/usage/token-generation.rst +19 -4
- data/docs/usage/transcriptions.rst +3 -2
- data/docs/usage/twiml.rst +7 -7
- data/docs/usage/validation.rst +39 -3
- data/examples/examples.rb +44 -20
- data/examples/print-call-log.rb +1 -1
- data/lib/rack/twilio_webhook_authentication.rb +47 -0
- data/lib/twilio-ruby/rest/accounts.rb +2 -1
- data/lib/twilio-ruby/rest/addresses/dependent_phone_numbers.rb +6 -0
- data/lib/twilio-ruby/rest/addresses.rb +12 -0
- data/lib/twilio-ruby/rest/base_client.rb +127 -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 +10 -5
- data/lib/twilio-ruby/rest/client.rb +44 -109
- data/lib/twilio-ruby/rest/conferences/participants.rb +2 -2
- data/lib/twilio-ruby/rest/incoming_phone_numbers.rb +1 -1
- data/lib/twilio-ruby/rest/instance_resource.rb +2 -16
- data/lib/twilio-ruby/rest/list_resource.rb +20 -30
- data/lib/twilio-ruby/rest/lookups/phone_numbers.rb +17 -0
- data/lib/twilio-ruby/rest/lookups_client.rb +99 -0
- data/lib/twilio-ruby/rest/messages.rb +5 -0
- data/lib/twilio-ruby/rest/next_gen_list_resource.rb +36 -0
- data/lib/twilio-ruby/rest/outgoing_caller_ids.rb +1 -1
- data/lib/twilio-ruby/rest/queues/members.rb +1 -1
- data/lib/twilio-ruby/rest/sip.rb +1 -3
- data/lib/twilio-ruby/rest/sms/messages.rb +23 -0
- data/lib/twilio-ruby/rest/task_router/activities.rb +8 -0
- data/lib/twilio-ruby/rest/task_router/events.rb +8 -0
- data/lib/twilio-ruby/rest/task_router/reservations.rb +8 -0
- data/lib/twilio-ruby/rest/task_router/statistics.rb +26 -0
- data/lib/twilio-ruby/rest/task_router/task_queues.rb +17 -0
- data/lib/twilio-ruby/rest/task_router/task_queues_statistics.rb +15 -0
- data/lib/twilio-ruby/rest/task_router/tasks.rb +15 -0
- data/lib/twilio-ruby/rest/task_router/workers.rb +13 -0
- data/lib/twilio-ruby/rest/task_router/workers_statistics.rb +8 -0
- data/lib/twilio-ruby/rest/task_router/workflow_statistics.rb +7 -0
- data/lib/twilio-ruby/rest/task_router/workflows.rb +11 -0
- data/lib/twilio-ruby/rest/task_router/workspace_statistics.rb +7 -0
- data/lib/twilio-ruby/rest/task_router/workspaces.rb +17 -0
- data/lib/twilio-ruby/rest/task_router_client.rb +176 -0
- data/lib/twilio-ruby/rest/tokens.rb +7 -0
- data/lib/twilio-ruby/rest/usage/records.rb +2 -2
- data/lib/twilio-ruby/rest/utils.rb +35 -11
- data/lib/twilio-ruby/task_router/capability.rb +87 -0
- data/lib/twilio-ruby/task_router.rb +0 -0
- data/lib/twilio-ruby/twiml/response.rb +1 -0
- data/lib/twilio-ruby/util/capability.rb +10 -7
- data/lib/twilio-ruby/util/client_config.rb +29 -0
- data/lib/twilio-ruby/util/configuration.rb +7 -0
- data/lib/twilio-ruby/util/request_validator.rb +18 -3
- data/lib/twilio-ruby/version.rb +1 -1
- data/lib/twilio-ruby.rb +48 -0
- data/spec/rack/twilio_webhook_authentication_spec.rb +110 -0
- data/spec/rest/account_spec.rb +51 -20
- data/spec/rest/address_spec.rb +11 -0
- 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 +8 -4
- data/spec/rest/client_spec.rb +209 -51
- data/spec/rest/conference_spec.rb +4 -2
- data/spec/rest/instance_resource_spec.rb +4 -4
- data/spec/rest/lookups/phone_number_spec.rb +8 -0
- data/spec/rest/message_spec.rb +2 -2
- data/spec/rest/numbers_spec.rb +25 -13
- data/spec/rest/queue_spec.rb +4 -2
- data/spec/rest/recording_spec.rb +4 -2
- data/spec/rest/sms/message_spec.rb +37 -0
- data/spec/rest/sms/messages_spec.rb +31 -0
- data/spec/rest/task_router/reservation_spec.rb +9 -0
- data/spec/rest/task_router/task_queue_spec.rb +9 -0
- data/spec/rest/token_spec.rb +7 -0
- data/spec/rest/utils_spec.rb +45 -0
- data/spec/spec_helper.rb +12 -3
- data/spec/support/fakeweb.rb +2 -0
- data/spec/task_router_spec.rb +114 -0
- data/spec/twilio_spec.rb +15 -0
- data/spec/util/capability_spec.rb +167 -118
- data/spec/util/client_config_spec.rb +21 -0
- data/spec/util/configuration_spec.rb +15 -0
- data/spec/util/request_validator_spec.rb +31 -3
- data/spec/util/url_encode_spec.rb +2 -2
- data/twilio-ruby.gemspec +28 -27
- metadata +93 -71
- data/CHANGES +0 -47
data/spec/rest/client_spec.rb
CHANGED
|
@@ -1,15 +1,74 @@
|
|
|
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
|
-
FakeWeb.register_uri(:any, %r/api\.twilio\.com/, :
|
|
64
|
+
FakeWeb.register_uri(:any, %r/api\.twilio\.com/, body: '')
|
|
6
65
|
twilio = Twilio::REST::Client.new('someSid', 'someToken')
|
|
7
66
|
Twilio::REST::IncomingPhoneNumber.new('/phone_number', twilio).delete
|
|
8
67
|
end
|
|
9
68
|
|
|
10
69
|
it 'should not raise an error if the response body is nil' do
|
|
11
|
-
response = double(:response, :
|
|
12
|
-
connection = double(:connection, :
|
|
70
|
+
response = double(:response, body: nil)
|
|
71
|
+
connection = double(:connection, request: response)
|
|
13
72
|
twilio = Twilio::REST::Client.new('someSid', 'someToken')
|
|
14
73
|
twilio.instance_variable_set(:@connection, connection)
|
|
15
74
|
Twilio::REST::IncomingPhoneNumber.new('/phone_number', twilio).delete
|
|
@@ -17,84 +76,183 @@ 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
|
-
twilio = Twilio::REST::Client.new(
|
|
92
|
+
twilio = Twilio::REST::Client.new(
|
|
93
|
+
'someSid', 'someToken', ssl_ca_file: '/path/to/ca/file'
|
|
94
|
+
)
|
|
34
95
|
connection = twilio.instance_variable_get('@connection')
|
|
35
|
-
connection.ca_file.
|
|
96
|
+
expect(connection.ca_file).to eq('/path/to/ca/file')
|
|
36
97
|
end
|
|
37
98
|
|
|
38
|
-
it 'should set up the proper http ssl connection when a different
|
|
39
|
-
|
|
99
|
+
it 'should set up the proper http ssl connection when a different ' \
|
|
100
|
+
'domain is given' do
|
|
101
|
+
twilio = Twilio::REST::Client.new(
|
|
102
|
+
'someSid', 'someToken', host: 'api.faketwilio.com'
|
|
103
|
+
)
|
|
40
104
|
connection = twilio.instance_variable_get('@connection')
|
|
41
|
-
connection.address.
|
|
42
|
-
connection.port.
|
|
43
|
-
connection.use_ssl
|
|
105
|
+
expect(connection.address).to eq('api.faketwilio.com')
|
|
106
|
+
expect(connection.port).to eq(443)
|
|
107
|
+
expect(connection.use_ssl?).to eq(true)
|
|
44
108
|
end
|
|
45
109
|
|
|
46
|
-
it 'should adjust the open and read timeouts on the underlying Net::HTTP
|
|
110
|
+
it 'should adjust the open and read timeouts on the underlying Net::HTTP ' \
|
|
111
|
+
'object when asked' do
|
|
47
112
|
timeout = rand(30)
|
|
48
|
-
twilio = Twilio::REST::Client.new('someSid', 'someToken', :
|
|
113
|
+
twilio = Twilio::REST::Client.new('someSid', 'someToken', timeout: timeout)
|
|
49
114
|
connection = twilio.instance_variable_get('@connection')
|
|
50
|
-
connection.port.
|
|
51
|
-
connection.use_ssl
|
|
52
|
-
connection.open_timeout.
|
|
53
|
-
connection.read_timeout.
|
|
115
|
+
expect(connection.port).to eq(443)
|
|
116
|
+
expect(connection.use_ssl?).to eq(true)
|
|
117
|
+
expect(connection.open_timeout).to eq(timeout)
|
|
118
|
+
expect(connection.read_timeout).to eq(timeout)
|
|
54
119
|
end
|
|
55
120
|
|
|
56
|
-
it 'should set up the proper http ssl connection when a proxy_host is
|
|
57
|
-
|
|
121
|
+
it 'should set up the proper http ssl connection when a proxy_host is ' \
|
|
122
|
+
'given' do
|
|
123
|
+
twilio = Twilio::REST::Client.new(
|
|
124
|
+
'someSid',
|
|
125
|
+
'someToken',
|
|
126
|
+
host: 'api.faketwilio.com',
|
|
127
|
+
proxy_addr: 'localhost'
|
|
128
|
+
)
|
|
58
129
|
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
|
|
130
|
+
expect(connection.proxy?).to eq(true)
|
|
131
|
+
expect(connection.proxy_address).to eq('localhost')
|
|
132
|
+
expect(connection.proxy_port).to eq(80)
|
|
133
|
+
expect(connection.address).to eq('api.faketwilio.com')
|
|
134
|
+
expect(connection.port).to eq(443)
|
|
135
|
+
expect(connection.use_ssl?).to eq(true)
|
|
65
136
|
end
|
|
66
137
|
|
|
67
|
-
it 'should set up the proper http ssl connection when a proxy_host and
|
|
68
|
-
|
|
138
|
+
it 'should set up the proper http ssl connection when a proxy_host and ' \
|
|
139
|
+
'proxy_port are given' do
|
|
140
|
+
twilio = Twilio::REST::Client.new(
|
|
141
|
+
'someSid',
|
|
142
|
+
'someToken',
|
|
143
|
+
host: 'api.faketwilio.com',
|
|
144
|
+
proxy_addr: 'localhost',
|
|
145
|
+
proxy_port: 13128
|
|
146
|
+
)
|
|
69
147
|
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
|
|
148
|
+
expect(connection.proxy?).to eq(true)
|
|
149
|
+
expect(connection.proxy_address).to eq('localhost')
|
|
150
|
+
expect(connection.proxy_port).to eq(13128)
|
|
151
|
+
expect(connection.address).to eq('api.faketwilio.com')
|
|
152
|
+
expect(connection.port).to eq(443)
|
|
153
|
+
expect(connection.use_ssl?).to eq(true)
|
|
76
154
|
end
|
|
77
155
|
|
|
78
156
|
it 'should set up an accounts resources object' do
|
|
79
157
|
twilio = Twilio::REST::Client.new('someSid', 'someToken')
|
|
80
|
-
twilio.
|
|
81
|
-
twilio.accounts.instance_variable_get('@path').
|
|
158
|
+
expect(twilio).to respond_to(:accounts)
|
|
159
|
+
expect(twilio.accounts.instance_variable_get('@path')).to eq(
|
|
160
|
+
'/2010-04-01/Accounts'
|
|
161
|
+
)
|
|
82
162
|
end
|
|
83
163
|
|
|
84
164
|
it 'should set up an account object with the given sid' do
|
|
85
165
|
twilio = Twilio::REST::Client.new('someSid', 'someToken')
|
|
86
|
-
twilio.
|
|
87
|
-
twilio.account.instance_variable_get('@path').
|
|
166
|
+
expect(twilio).to respond_to(:account)
|
|
167
|
+
expect(twilio.account.instance_variable_get('@path')).to eq(
|
|
168
|
+
'/2010-04-01/Accounts/someSid'
|
|
169
|
+
)
|
|
88
170
|
end
|
|
89
171
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
172
|
+
[
|
|
173
|
+
:sandbox, :available_phone_numbers, :incoming_phone_numbers,
|
|
174
|
+
:calls, :outgoing_caller_ids, :conferences, :sms, :recordings,
|
|
175
|
+
:transcriptions, :notifications, :applications, :connect_apps,
|
|
176
|
+
:authorized_connect_apps, :queues, :usage, :messages, :media, :sip
|
|
177
|
+
].each do |method|
|
|
178
|
+
it "should delegate the client method #{method} to the account object" do
|
|
179
|
+
client = Twilio::REST::Client.new('someSid', 'someToken')
|
|
180
|
+
expect(client).to respond_to(method)
|
|
181
|
+
expect(client.send(method)).to eq(client.account.send(method))
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
it 'should throw an argument error if the workspace_sid is not set' do
|
|
186
|
+
expect { Twilio::REST::TaskRouterClient.new 'someSid', 'someToken' }.to raise_error(ArgumentError)
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
it 'should have its host set to taskrouter.twilio.com' do
|
|
190
|
+
client = Twilio::REST::TaskRouterClient.new('someSid', 'someToken', 'someSid')
|
|
191
|
+
connection = client.instance_variable_get('@connection')
|
|
192
|
+
expect(connection.address).to eq('taskrouter.twilio.com')
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
it 'should have task queue statistics resource' do
|
|
196
|
+
FakeWeb.register_uri(:get, %r/taskrouter\.twilio\.com/, body: '{}')
|
|
197
|
+
client = Twilio::REST::TaskRouterClient.new('someSid', 'someToken', 'someSid')
|
|
198
|
+
expect(client).to respond_to(:task_queue_statistics)
|
|
199
|
+
expect(client.task_queue_statistics('someSid').instance_variable_get('@path')).to eq('/v1/Workspaces/someSid/TaskQueues/someSid/Statistics')
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
it 'should have task queues statistics resource' do
|
|
203
|
+
FakeWeb.register_uri(:get, %r/taskrouter\.twilio\.com/, body: '{"meta": {"key": "task_queues_statistics"}, "task_queues_statistics": [{"task_queue_sid": "WQ123"}]}')
|
|
204
|
+
client = Twilio::REST::TaskRouterClient.new('someSid', 'someToken', 'someSid')
|
|
205
|
+
expect(client).to respond_to(:task_queues_statistics)
|
|
206
|
+
expect(client.task_queues_statistics[0].task_queue_sid).to eq('WQ123')
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
it 'should have worker statistics resource' do
|
|
210
|
+
FakeWeb.register_uri(:get, %r/taskrouter\.twilio\.com/, body: '{}')
|
|
211
|
+
client = Twilio::REST::TaskRouterClient.new('someSid', 'someToken', 'someSid')
|
|
212
|
+
expect(client).to respond_to(:worker_statistics)
|
|
213
|
+
expect(client.worker_statistics('someSid').instance_variable_get('@path')).to eq('/v1/Workspaces/someSid/Workers/someSid/Statistics')
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
it 'should have workers statistics resource' do
|
|
217
|
+
FakeWeb.register_uri(:get, %r/taskrouter\.twilio\.com/, body: '{}')
|
|
218
|
+
client = Twilio::REST::TaskRouterClient.new('someSid', 'someToken', 'someSid')
|
|
219
|
+
expect(client).to respond_to(:workers_statistics)
|
|
220
|
+
expect(client.workers_statistics.instance_variable_get('@path')).to eq('/v1/Workspaces/someSid/Workers/Statistics')
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
it 'should have workflow statistics resource' do
|
|
224
|
+
FakeWeb.register_uri(:get, %r/taskrouter\.twilio\.com/, body: '{}')
|
|
225
|
+
client = Twilio::REST::TaskRouterClient.new('someSid', 'someToken', 'someSid')
|
|
226
|
+
expect(client).to respond_to(:workflow_statistics)
|
|
227
|
+
expect(client.workflow_statistics('someSid').instance_variable_get('@path')).to eq('/v1/Workspaces/someSid/Workflows/someSid/Statistics')
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
it 'should have workspace statistics resource' do
|
|
231
|
+
FakeWeb.register_uri(:get, %r/taskrouter\.twilio\.com/, body: '{}')
|
|
232
|
+
client = Twilio::REST::TaskRouterClient.new('someSid', 'someToken', 'someSid')
|
|
233
|
+
expect(client).to respond_to(:workspace_statistics)
|
|
234
|
+
expect(client.workspace_statistics.instance_variable_get('@path')).to eq('/v1/Workspaces/someSid/Statistics')
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
it 'should set up a workspaces resource object' do
|
|
238
|
+
client = Twilio::REST::TaskRouterClient.new('someSid', 'someToken', 'someSid')
|
|
239
|
+
expect(client).to respond_to(:workspaces)
|
|
240
|
+
expect(client.workspaces.instance_variable_get('@path')).to eq('/v1/Workspaces')
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
it 'should set up a workspace resource object' do
|
|
244
|
+
client = Twilio::REST::TaskRouterClient.new('someSid', 'someToken', 'someSid')
|
|
245
|
+
expect(client).to respond_to(:workspace)
|
|
246
|
+
expect(client.workspace.instance_variable_get('@path')).to eq('/v1/Workspaces/someSid')
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
[
|
|
250
|
+
:activities, :tasks, :task_queues, :workers, :workflows
|
|
251
|
+
].each do |method|
|
|
252
|
+
it "should delegate the client method #{method} to the workspace object" do
|
|
253
|
+
client = Twilio::REST::TaskRouterClient.new('someSid', 'someToken', 'someSid')
|
|
254
|
+
expect(client).to respond_to(method)
|
|
255
|
+
expect(client.send(method)).to eq(client.workspace.send(method))
|
|
98
256
|
end
|
|
99
257
|
end
|
|
100
258
|
end
|
|
@@ -3,7 +3,9 @@ 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(
|
|
8
|
+
'someUri/Participants'
|
|
9
|
+
)
|
|
8
10
|
end
|
|
9
11
|
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
|
-
params = {'SomeKey' => 'someValue'}
|
|
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,22 @@ 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(
|
|
17
|
+
'someUri/TollFree'
|
|
18
|
+
)
|
|
17
19
|
end
|
|
18
20
|
|
|
19
21
|
it 'sets up a mobile resources object' do
|
|
20
|
-
@country.
|
|
21
|
-
@country.mobile.instance_variable_get('@path').
|
|
22
|
+
expect(@country).to respond_to(:mobile)
|
|
23
|
+
expect(@country.mobile.instance_variable_get('@path')).to eq(
|
|
24
|
+
'someUri/Mobile'
|
|
25
|
+
)
|
|
22
26
|
end
|
|
23
27
|
|
|
24
28
|
end
|
|
@@ -26,21 +30,29 @@ end
|
|
|
26
30
|
describe Twilio::REST::NumberType do
|
|
27
31
|
|
|
28
32
|
before do
|
|
29
|
-
@incoming_phone_numbers = Twilio::REST::IncomingPhoneNumbers.new(
|
|
33
|
+
@incoming_phone_numbers = Twilio::REST::IncomingPhoneNumbers.new(
|
|
34
|
+
'someUri', 'someClient'
|
|
35
|
+
)
|
|
30
36
|
end
|
|
31
37
|
|
|
32
38
|
it 'sets up a local resources object' do
|
|
33
|
-
@incoming_phone_numbers.
|
|
34
|
-
@incoming_phone_numbers.local.instance_variable_get('@path').
|
|
39
|
+
expect(@incoming_phone_numbers).to respond_to(:local)
|
|
40
|
+
expect(@incoming_phone_numbers.local.instance_variable_get('@path')).to eq(
|
|
41
|
+
'someUri/Local'
|
|
42
|
+
)
|
|
35
43
|
end
|
|
36
44
|
|
|
37
45
|
it 'sets up a toll_free resources object' do
|
|
38
|
-
@incoming_phone_numbers.
|
|
39
|
-
@incoming_phone_numbers.toll_free.instance_variable_get('@path').
|
|
46
|
+
expect(@incoming_phone_numbers).to respond_to(:toll_free)
|
|
47
|
+
expect(@incoming_phone_numbers.toll_free.instance_variable_get('@path')).to(
|
|
48
|
+
eq('someUri/TollFree')
|
|
49
|
+
)
|
|
40
50
|
end
|
|
41
51
|
|
|
42
52
|
it 'sets up a mobile resources object' do
|
|
43
|
-
@incoming_phone_numbers.
|
|
44
|
-
@incoming_phone_numbers.mobile.instance_variable_get('@path').
|
|
53
|
+
expect(@incoming_phone_numbers).to respond_to(:mobile)
|
|
54
|
+
expect(@incoming_phone_numbers.mobile.instance_variable_get('@path')).to eq(
|
|
55
|
+
'someUri/Mobile'
|
|
56
|
+
)
|
|
45
57
|
end
|
|
46
58
|
end
|
data/spec/rest/queue_spec.rb
CHANGED
|
@@ -3,7 +3,9 @@ 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(
|
|
8
|
+
'someUri/Members'
|
|
9
|
+
)
|
|
8
10
|
end
|
|
9
11
|
end
|
data/spec/rest/recording_spec.rb
CHANGED
|
@@ -3,7 +3,9 @@ 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(
|
|
8
|
+
'someUri/Transcriptions'
|
|
9
|
+
)
|
|
8
10
|
end
|
|
9
11
|
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Twilio::REST::SMS::Message do
|
|
4
|
+
|
|
5
|
+
before do
|
|
6
|
+
client = double("Client")
|
|
7
|
+
allow(client).to receive(:post) do
|
|
8
|
+
{'sid' => 'qwerty' }
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
allow(client).to receive(:get) do
|
|
12
|
+
{'sid' => 'qwerty', 'sms_message' => [] }
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
allow(client).to receive(:delete) do
|
|
16
|
+
{'sid' => 'qwerty' }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
@message = Twilio::REST::SMS::Message.new('someUri',client)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'should warn of deprecation of SMS Message Update' do
|
|
23
|
+
expect(@message).to receive(:warn)
|
|
24
|
+
@message.update
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'should warn of deprecation of SMS Message Refresh' do
|
|
28
|
+
expect(@message).to receive(:warn)
|
|
29
|
+
@message.refresh
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'should warn of deprecation of SMS Message Delete' do
|
|
33
|
+
expect(@message).to receive(:warn)
|
|
34
|
+
@message.delete
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Twilio::REST::SMS::Messages do
|
|
4
|
+
|
|
5
|
+
before do
|
|
6
|
+
client = double("Client")
|
|
7
|
+
allow(client).to receive(:post) do
|
|
8
|
+
{'sid' => 'qwerty' }
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
allow(client).to receive(:get) do
|
|
12
|
+
{'sid' => 'qwerty', 'sms_messages' => [] }
|
|
13
|
+
end
|
|
14
|
+
@messages = Twilio::REST::SMS::Messages.new('someUri',client)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'should warn of deprecation of SMS Messages Create' do
|
|
18
|
+
expect(@messages).to receive(:warn)
|
|
19
|
+
@messages.create to: "+1", from: "+2", body: "But Jenny!"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'should warn of deprecation of SMS Messages List' do
|
|
23
|
+
expect(@messages).to receive(:warn)
|
|
24
|
+
@messages.list to: "+1"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'should warn of deprecation of SMS Messages Get' do
|
|
28
|
+
expect(@messages).to receive(:warn)
|
|
29
|
+
@messages.get sid: "qwerty"
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Twilio::REST::TaskRouter::Reservations do
|
|
4
|
+
it 'creates a reservation object' do
|
|
5
|
+
task = Twilio::REST::TaskRouter::Task.new('someUri', 'someClient')
|
|
6
|
+
expect(task).to respond_to(:reservations)
|
|
7
|
+
expect(task.reservations.instance_variable_get('@path')).to eq('someUri/Reservations')
|
|
8
|
+
end
|
|
9
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Twilio::REST::TaskRouter::TaskQueues do
|
|
4
|
+
it 'creates a task queue object' do
|
|
5
|
+
workspace = Twilio::REST::TaskRouter::Workspace.new('someUri', 'someClient')
|
|
6
|
+
expect(workspace).to respond_to(:task_queues)
|
|
7
|
+
expect(workspace.task_queues.instance_variable_get('@path')).to eq('someUri/TaskQueues')
|
|
8
|
+
end
|
|
9
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
class UtilClass
|
|
4
|
+
include Twilio::REST::Utils
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
describe UtilClass do
|
|
8
|
+
subject(:util) { UtilClass.new }
|
|
9
|
+
|
|
10
|
+
it 'should convert a parameter name to a Twilio-style name' do
|
|
11
|
+
expect(util.twilify('sms_url')).to eq('SmsUrl')
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it 'should convert all parameter names to Twilio-style names' do
|
|
15
|
+
untwilified = {
|
|
16
|
+
:sms_url => 'someUrl',
|
|
17
|
+
'voiceFallbackUrl' => 'anotherUrl',
|
|
18
|
+
'Status_callback' => 'yetAnotherUrl'
|
|
19
|
+
}
|
|
20
|
+
twilified = {
|
|
21
|
+
:SmsUrl => 'someUrl',
|
|
22
|
+
:VoiceFallbackUrl => 'anotherUrl',
|
|
23
|
+
:StatusCallback => 'yetAnotherUrl'
|
|
24
|
+
}
|
|
25
|
+
expect(util.twilify(untwilified)).to eq(twilified)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'should convert a Twilio-style name to a parameter name' do
|
|
29
|
+
expect(util.detwilify('SmsUrl')).to eq('sms_url')
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'should convert all Twilio-style names to parameter names' do
|
|
33
|
+
untwilified = {
|
|
34
|
+
:sms_url => 'someUrl',
|
|
35
|
+
:voice_fallback_url => 'anotherUrl',
|
|
36
|
+
:status_callback => 'yetAnotherUrl'
|
|
37
|
+
}
|
|
38
|
+
twilified = {
|
|
39
|
+
:SmsUrl => 'someUrl',
|
|
40
|
+
:VoiceFallbackUrl => 'anotherUrl',
|
|
41
|
+
:StatusCallback => 'yetAnotherUrl'
|
|
42
|
+
}
|
|
43
|
+
expect(util.detwilify(twilified)).to eq(untwilified)
|
|
44
|
+
end
|
|
45
|
+
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
|