twilio-ruby 3.12.3 → 3.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +8 -8
  2. data/CHANGES.md +12 -0
  3. data/README.md +14 -14
  4. data/Rakefile +2 -2
  5. data/docs/faq.rst +3 -3
  6. data/docs/getting-started.rst +17 -12
  7. data/docs/usage/accounts.rst +6 -6
  8. data/docs/usage/applications.rst +5 -5
  9. data/docs/usage/basics.rst +1 -1
  10. data/docs/usage/caller-ids.rst +4 -2
  11. data/docs/usage/conferences.rst +1 -1
  12. data/docs/usage/errors.rst +3 -3
  13. data/docs/usage/messages.rst +24 -16
  14. data/docs/usage/phone-calls.rst +10 -8
  15. data/docs/usage/phone-numbers.rst +15 -11
  16. data/docs/usage/sip.rst +9 -8
  17. data/docs/usage/twiml.rst +2 -2
  18. data/examples/examples.rb +44 -20
  19. data/lib/rack/twilio_webhook_authentication.rb +5 -1
  20. data/lib/twilio-ruby/rest/calls.rb +4 -4
  21. data/lib/twilio-ruby/rest/client.rb +25 -23
  22. data/lib/twilio-ruby/rest/conferences/participants.rb +2 -2
  23. data/lib/twilio-ruby/rest/incoming_phone_numbers.rb +1 -1
  24. data/lib/twilio-ruby/rest/instance_resource.rb +9 -5
  25. data/lib/twilio-ruby/rest/list_resource.rb +18 -10
  26. data/lib/twilio-ruby/rest/outgoing_caller_ids.rb +1 -1
  27. data/lib/twilio-ruby/rest/queues/members.rb +1 -1
  28. data/lib/twilio-ruby/rest/sip.rb +1 -3
  29. data/lib/twilio-ruby/rest/utils.rb +11 -3
  30. data/lib/twilio-ruby/util/capability.rb +4 -4
  31. data/lib/twilio-ruby/version.rb +1 -1
  32. data/spec/rack/twilio_webhook_authentication_spec.rb +18 -6
  33. data/spec/rest/account_spec.rb +24 -8
  34. data/spec/rest/call_spec.rb +6 -2
  35. data/spec/rest/client_spec.rb +37 -14
  36. data/spec/rest/conference_spec.rb +3 -1
  37. data/spec/rest/instance_resource_spec.rb +1 -1
  38. data/spec/rest/numbers_spec.rb +18 -6
  39. data/spec/rest/queue_spec.rb +3 -1
  40. data/spec/rest/recording_spec.rb +3 -1
  41. data/spec/util/url_encode_spec.rb +1 -1
  42. metadata +1 -1
@@ -2,7 +2,7 @@ module Twilio
2
2
  module REST
3
3
  class OutgoingCallerIds < ListResource
4
4
  def add(phone_number)
5
- create :phone_number => phone_number
5
+ create phone_number: phone_number
6
6
  end
7
7
  alias :verify :add
8
8
 
@@ -22,7 +22,7 @@ module Twilio
22
22
 
23
23
  class Member < InstanceResource
24
24
  def dequeue(url, method='POST')
25
- update :url => url, :method => method
25
+ update url: url, method: method
26
26
  end
27
27
  end
28
28
  end
@@ -3,9 +3,7 @@ module Twilio
3
3
  class Sip < InstanceResource
4
4
  def initialize(path, client, params={})
5
5
  super
6
- resource :domains,
7
- :ip_access_control_lists,
8
- :credential_lists
6
+ resource :domains, :ip_access_control_lists, :credential_lists
9
7
  end
10
8
  end
11
9
  end
@@ -4,7 +4,10 @@ module Twilio
4
4
 
5
5
  def twilify(something)
6
6
  if something.is_a? Hash
7
- Hash[*something.to_a.map! {|a| [twilify(a[0]).to_sym, a[1]]}.flatten(1)]
7
+ something = something.to_a
8
+ something = something.map { |a| [twilify(a[0]).to_sym, a[1]] }
9
+ something = something.flatten(1)
10
+ Hash[*something]
8
11
  else
9
12
  something.to_s.split('_').map! do |s|
10
13
  [s[0,1].capitalize, s[1..-1]].join
@@ -14,9 +17,14 @@ module Twilio
14
17
 
15
18
  def detwilify(something)
16
19
  if something.is_a? Hash
17
- Hash[*something.to_a.map! {|pair| [detwilify(pair[0]).to_sym, pair[1]]}.flatten]
20
+ something = *something.to_a
21
+ something.map! { |pair| [detwilify(pair[0]).to_sym, pair[1]] }
22
+ something = something.flatten
23
+ Hash[something]
18
24
  else
19
- something.to_s.gsub(/[A-Z][a-z]*/) {|s| "_#{s.downcase}"}.gsub(/^_/, '')
25
+ something = something.to_s
26
+ something = something.gsub(/[A-Z][a-z]*/) { |s| "_#{s.downcase}" }
27
+ something.gsub(/^_/, '')
20
28
  end
21
29
  end
22
30
 
@@ -15,20 +15,20 @@ module Twilio
15
15
 
16
16
  def allow_client_incoming(client_name)
17
17
  @client_name = client_name # stash for use in outgoing
18
- scope_params = {'clientName' => client_name}
18
+ scope_params = { 'clientName' => client_name }
19
19
  @capabilities << scope_uri_for('client', 'incoming', scope_params)
20
20
  end
21
21
 
22
22
  def allow_client_outgoing(app_sid, params = {})
23
23
  @allow_client_outgoing = true
24
- @outgoing_scope_params = {'appSid' => app_sid}
24
+ @outgoing_scope_params = { 'appSid' => app_sid }
25
25
  unless params.empty?
26
26
  @outgoing_scope_params['appParams'] = url_encode params
27
27
  end
28
28
  end
29
29
 
30
30
  def allow_event_stream(filters = {})
31
- scope_params = {'path' => '/2010-04-01/Events'}
31
+ scope_params = { 'path' => '/2010-04-01/Events' }
32
32
  scope_params['params'] = filters unless filters.empty?
33
33
  @capabilities << scope_uri_for('stream', 'subscribe', scope_params)
34
34
  end
@@ -45,7 +45,7 @@ module Twilio
45
45
  # build the outgoing scope lazily so that we can use @client_name
46
46
  if @allow_client_outgoing
47
47
  params = @outgoing_scope_params
48
- params.merge!({'clientName' => @client_name}) if @client_name
48
+ params.merge!('clientName' => @client_name) if @client_name
49
49
  capabilities << scope_uri_for('client', 'outgoing', params)
50
50
  end
51
51
 
@@ -1,3 +1,3 @@
1
1
  module Twilio
2
- VERSION = '3.12.3'
2
+ VERSION = '3.13.0'
3
3
  end
@@ -22,7 +22,9 @@ describe Rack::TwilioWebhookAuthentication do
22
22
 
23
23
  describe 'calling against one path' do
24
24
  before do
25
- @middleware = Rack::TwilioWebhookAuthentication.new(@app, 'ABC', /\/voice/)
25
+ @middleware = Rack::TwilioWebhookAuthentication.new(
26
+ @app, 'ABC', /\/voice/
27
+ )
26
28
  end
27
29
 
28
30
  it 'should not intercept when the path doesn\'t match' do
@@ -33,14 +35,18 @@ describe Rack::TwilioWebhookAuthentication do
33
35
  end
34
36
 
35
37
  it 'should allow a request through if it validates' do
36
- expect_any_instance_of(Twilio::Util::RequestValidator).to receive(:validate).and_return(true)
38
+ expect_any_instance_of(Twilio::Util::RequestValidator).to(
39
+ receive(:validate).and_return(true)
40
+ )
37
41
  request = Rack::MockRequest.env_for('/voice')
38
42
  status, headers, body = @middleware.call(request)
39
43
  expect(status).to be(200)
40
44
  end
41
45
 
42
46
  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)
47
+ expect_any_instance_of(Twilio::Util::RequestValidator).to(
48
+ receive(:validate).and_return(false)
49
+ )
44
50
  request = Rack::MockRequest.env_for('/voice')
45
51
  status, headers, body = @middleware.call(request)
46
52
  expect(status).to be(403)
@@ -49,7 +55,9 @@ describe Rack::TwilioWebhookAuthentication do
49
55
 
50
56
  describe 'calling against many paths' do
51
57
  before do
52
- @middleware = Rack::TwilioWebhookAuthentication.new(@app, 'ABC', /\/voice/, /\/sms/)
58
+ @middleware = Rack::TwilioWebhookAuthentication.new(
59
+ @app, 'ABC', /\/voice/, /\/sms/
60
+ )
53
61
  end
54
62
 
55
63
  it 'should not intercept when the path doesn\'t match' do
@@ -60,14 +68,18 @@ describe Rack::TwilioWebhookAuthentication do
60
68
  end
61
69
 
62
70
  it 'shold allow a request through if it validates' do
63
- expect_any_instance_of(Twilio::Util::RequestValidator).to receive(:validate).and_return(true)
71
+ expect_any_instance_of(Twilio::Util::RequestValidator).to(
72
+ receive(:validate).and_return(true)
73
+ )
64
74
  request = Rack::MockRequest.env_for('/sms')
65
75
  status, headers, body = @middleware.call(request)
66
76
  expect(status).to be(200)
67
77
  end
68
78
 
69
79
  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)
80
+ expect_any_instance_of(Twilio::Util::RequestValidator).to(
81
+ receive(:validate).and_return(false)
82
+ )
71
83
  request = Rack::MockRequest.env_for('/sms')
72
84
  status, headers, body = @middleware.call(request)
73
85
  expect(status).to be(403)
@@ -8,17 +8,23 @@ describe Twilio::REST::Account do
8
8
 
9
9
  it 'sets up incoming phone numbers resources object' do
10
10
  expect(@account).to respond_to(:incoming_phone_numbers)
11
- expect(@account.incoming_phone_numbers.instance_variable_get('@path')).to eq('someUri/IncomingPhoneNumbers')
11
+ expect(@account.incoming_phone_numbers.instance_variable_get('@path')).to(
12
+ eq('someUri/IncomingPhoneNumbers')
13
+ )
12
14
  end
13
15
 
14
16
  it 'sets up an available phone numbers resources object' do
15
17
  expect(@account).to respond_to(:available_phone_numbers)
16
- expect(@account.available_phone_numbers.instance_variable_get('@path')).to eq('someUri/AvailablePhoneNumbers')
18
+ expect(@account.available_phone_numbers.instance_variable_get('@path')).to(
19
+ eq('someUri/AvailablePhoneNumbers')
20
+ )
17
21
  end
18
22
 
19
23
  it 'sets up an outgoing caller ids resources object' do
20
24
  expect(@account).to respond_to(:outgoing_caller_ids)
21
- expect(@account.outgoing_caller_ids.instance_variable_get('@path')).to eq('someUri/OutgoingCallerIds')
25
+ expect(@account.outgoing_caller_ids.instance_variable_get('@path')).to eq(
26
+ 'someUri/OutgoingCallerIds'
27
+ )
22
28
  end
23
29
 
24
30
  it 'sets up a calls resources object' do
@@ -28,12 +34,16 @@ describe Twilio::REST::Account do
28
34
 
29
35
  it 'sets up a conferences resources object' do
30
36
  expect(@account).to respond_to(:conferences)
31
- expect(@account.conferences.instance_variable_get('@path')).to eq('someUri/Conferences')
37
+ expect(@account.conferences.instance_variable_get('@path')).to eq(
38
+ 'someUri/Conferences'
39
+ )
32
40
  end
33
41
 
34
42
  it 'sets up a queues resources object' do
35
43
  expect(@account).to respond_to(:queues)
36
- expect(@account.queues.instance_variable_get('@path')).to eq('someUri/Queues')
44
+ expect(@account.queues.instance_variable_get('@path')).to eq(
45
+ 'someUri/Queues'
46
+ )
37
47
  end
38
48
 
39
49
  it 'sets up a sms resource object' do
@@ -43,16 +53,22 @@ describe Twilio::REST::Account do
43
53
 
44
54
  it 'sets up a recordings resources object' do
45
55
  expect(@account).to respond_to(:recordings)
46
- expect(@account.recordings.instance_variable_get('@path')).to eq('someUri/Recordings')
56
+ expect(@account.recordings.instance_variable_get('@path')).to eq(
57
+ 'someUri/Recordings'
58
+ )
47
59
  end
48
60
 
49
61
  it 'sets up a transcriptions resources object' do
50
62
  expect(@account).to respond_to(:transcriptions)
51
- expect(@account.transcriptions.instance_variable_get('@path')).to eq('someUri/Transcriptions')
63
+ expect(@account.transcriptions.instance_variable_get('@path')).to eq(
64
+ 'someUri/Transcriptions'
65
+ )
52
66
  end
53
67
 
54
68
  it 'sets up a notifications resources object' do
55
69
  expect(@account).to respond_to(:notifications)
56
- expect(@account.notifications.instance_variable_get('@path')).to eq('someUri/Notifications')
70
+ expect(@account.notifications.instance_variable_get('@path')).to eq(
71
+ 'someUri/Notifications'
72
+ )
57
73
  end
58
74
  end
@@ -8,11 +8,15 @@ describe Twilio::REST::Call do
8
8
 
9
9
  it 'sets up a recordings resources object' do
10
10
  expect(@call).to respond_to(:recordings)
11
- expect(@call.recordings.instance_variable_get('@path')).to eq('someUri/Recordings')
11
+ expect(@call.recordings.instance_variable_get('@path')).to eq(
12
+ 'someUri/Recordings'
13
+ )
12
14
  end
13
15
 
14
16
  it 'sets up a notifications resources object' do
15
17
  expect(@call).to respond_to(:notifications)
16
- expect(@call.notifications.instance_variable_get('@path')).to eq('someUri/Notifications')
18
+ expect(@call.notifications.instance_variable_get('@path')).to eq(
19
+ 'someUri/Notifications'
20
+ )
17
21
  end
18
22
  end
@@ -61,14 +61,14 @@ describe Twilio::REST::Client do
61
61
  end
62
62
 
63
63
  it 'should not raise an error if the response body is empty' do
64
- FakeWeb.register_uri(:any, %r/api\.twilio\.com/, :body => '')
64
+ FakeWeb.register_uri(:any, %r/api\.twilio\.com/, body: '')
65
65
  twilio = Twilio::REST::Client.new('someSid', 'someToken')
66
66
  Twilio::REST::IncomingPhoneNumber.new('/phone_number', twilio).delete
67
67
  end
68
68
 
69
69
  it 'should not raise an error if the response body is nil' do
70
- response = double(:response, :body => nil)
71
- connection = double(:connection, :request => response)
70
+ response = double(:response, body: nil)
71
+ connection = double(:connection, request: response)
72
72
  twilio = Twilio::REST::Client.new('someSid', 'someToken')
73
73
  twilio.instance_variable_set(:@connection, connection)
74
74
  Twilio::REST::IncomingPhoneNumber.new('/phone_number', twilio).delete
@@ -89,22 +89,28 @@ describe Twilio::REST::Client do
89
89
  end
90
90
 
91
91
  it 'should set up the requested ssl verification ca_file if provided' do
92
- twilio = Twilio::REST::Client.new('someSid', 'someToken', :ssl_ca_file => '/path/to/ca/file')
92
+ twilio = Twilio::REST::Client.new(
93
+ 'someSid', 'someToken', ssl_ca_file: '/path/to/ca/file'
94
+ )
93
95
  connection = twilio.instance_variable_get('@connection')
94
96
  expect(connection.ca_file).to eq('/path/to/ca/file')
95
97
  end
96
98
 
97
- it 'should set up the proper http ssl connection when a different domain is given' do
98
- twilio = Twilio::REST::Client.new('someSid', 'someToken', :host => 'api.faketwilio.com')
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
+ )
99
104
  connection = twilio.instance_variable_get('@connection')
100
105
  expect(connection.address).to eq('api.faketwilio.com')
101
106
  expect(connection.port).to eq(443)
102
107
  expect(connection.use_ssl?).to eq(true)
103
108
  end
104
109
 
105
- it 'should adjust the open and read timeouts on the underlying Net::HTTP object when asked' do
110
+ it 'should adjust the open and read timeouts on the underlying Net::HTTP ' \
111
+ 'object when asked' do
106
112
  timeout = rand(30)
107
- twilio = Twilio::REST::Client.new('someSid', 'someToken', :timeout => timeout)
113
+ twilio = Twilio::REST::Client.new('someSid', 'someToken', timeout: timeout)
108
114
  connection = twilio.instance_variable_get('@connection')
109
115
  expect(connection.port).to eq(443)
110
116
  expect(connection.use_ssl?).to eq(true)
@@ -112,8 +118,14 @@ describe Twilio::REST::Client do
112
118
  expect(connection.read_timeout).to eq(timeout)
113
119
  end
114
120
 
115
- it 'should set up the proper http ssl connection when a proxy_host is given' do
116
- twilio = Twilio::REST::Client.new('someSid', 'someToken', :host => 'api.faketwilio.com', :proxy_addr => 'localhost')
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
+ )
117
129
  connection = twilio.instance_variable_get('@connection')
118
130
  expect(connection.proxy?).to eq(true)
119
131
  expect(connection.proxy_address).to eq('localhost')
@@ -123,8 +135,15 @@ describe Twilio::REST::Client do
123
135
  expect(connection.use_ssl?).to eq(true)
124
136
  end
125
137
 
126
- it 'should set up the proper http ssl connection when a proxy_host and proxy_port are given' do
127
- twilio = Twilio::REST::Client.new('someSid', 'someToken', :host => 'api.faketwilio.com', :proxy_addr => 'localhost', :proxy_port => 13128)
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
+ )
128
147
  connection = twilio.instance_variable_get('@connection')
129
148
  expect(connection.proxy?).to eq(true)
130
149
  expect(connection.proxy_address).to eq('localhost')
@@ -137,13 +156,17 @@ describe Twilio::REST::Client do
137
156
  it 'should set up an accounts resources object' do
138
157
  twilio = Twilio::REST::Client.new('someSid', 'someToken')
139
158
  expect(twilio).to respond_to(:accounts)
140
- expect(twilio.accounts.instance_variable_get('@path')).to eq('/2010-04-01/Accounts')
159
+ expect(twilio.accounts.instance_variable_get('@path')).to eq(
160
+ '/2010-04-01/Accounts'
161
+ )
141
162
  end
142
163
 
143
164
  it 'should set up an account object with the given sid' do
144
165
  twilio = Twilio::REST::Client.new('someSid', 'someToken')
145
166
  expect(twilio).to respond_to(:account)
146
- expect(twilio.account.instance_variable_get('@path')).to eq('/2010-04-01/Accounts/someSid')
167
+ expect(twilio.account.instance_variable_get('@path')).to eq(
168
+ '/2010-04-01/Accounts/someSid'
169
+ )
147
170
  end
148
171
 
149
172
  [
@@ -4,6 +4,8 @@ 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
6
  expect(conference).to respond_to(:participants)
7
- expect(conference.participants.instance_variable_get('@path')).to eq('someUri/Participants')
7
+ expect(conference.participants.instance_variable_get('@path')).to eq(
8
+ 'someUri/Participants'
9
+ )
8
10
  end
9
11
  end
@@ -8,7 +8,7 @@ describe Twilio::REST::InstanceResource do
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
13
  expect(resource.some_key).to eq('someValue')
14
14
  end
@@ -13,12 +13,16 @@ describe Twilio::REST::Country do
13
13
 
14
14
  it 'sets up a toll_free resources object' do
15
15
  expect(@country).to respond_to(:toll_free)
16
- expect(@country.toll_free.instance_variable_get('@path')).to eq('someUri/TollFree')
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
22
  expect(@country).to respond_to(:mobile)
21
- expect(@country.mobile.instance_variable_get('@path')).to eq('someUri/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('someUri', 'someClient')
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
39
  expect(@incoming_phone_numbers).to respond_to(:local)
34
- expect(@incoming_phone_numbers.local.instance_variable_get('@path')).to eq('someUri/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
46
  expect(@incoming_phone_numbers).to respond_to(:toll_free)
39
- expect(@incoming_phone_numbers.toll_free.instance_variable_get('@path')).to eq('someUri/TollFree')
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
53
  expect(@incoming_phone_numbers).to respond_to(:mobile)
44
- expect(@incoming_phone_numbers.mobile.instance_variable_get('@path')).to eq('someUri/Mobile')
54
+ expect(@incoming_phone_numbers.mobile.instance_variable_get('@path')).to eq(
55
+ 'someUri/Mobile'
56
+ )
45
57
  end
46
58
  end
@@ -4,6 +4,8 @@ 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
6
  expect(queue).to respond_to(:members)
7
- expect(queue.members.instance_variable_get('@path')).to eq('someUri/Members')
7
+ expect(queue.members.instance_variable_get('@path')).to eq(
8
+ 'someUri/Members'
9
+ )
8
10
  end
9
11
  end
@@ -4,6 +4,8 @@ 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
6
  expect(call).to respond_to(:transcriptions)
7
- expect(call.transcriptions.instance_variable_get('@path')).to eq('someUri/Transcriptions')
7
+ expect(call.transcriptions.instance_variable_get('@path')).to eq(
8
+ 'someUri/Transcriptions'
9
+ )
8
10
  end
9
11
  end