twilio-ruby 3.14.3 → 3.14.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 77bf7b770b0f8deeac38b2ed13ddade0f5c19c38
4
- data.tar.gz: 84e2b0002a9c511296e1b57aab3a1d9ee4f857a3
3
+ metadata.gz: e8bf4ccb567cfcec52fe35a2dcbdc00d5162f3a6
4
+ data.tar.gz: e3a045befa32f513203f22a0ceee78084b7303ab
5
5
  SHA512:
6
- metadata.gz: 5ad94bb471b8adde9de5470dfd712e3c47f70c6b100db9ebe9d40000b8a58ccf23e2bc01f1b72f2e062ed3163a5297f15bec9ab26e7410976e7983f556c8913c
7
- data.tar.gz: e96311fd80abb64ee1372fe08c912e42954f57f9d473ca351d6704268301f6610487e793ffce4a58619f8dbfe4e38335babda8097b873f5f13fbd2143b8e0463
6
+ metadata.gz: e32b334d54614e3d89c2a7403f2c661b04eff50240d2fc6bda13dcab3c85a9a978a6c6f96ac74a6f734859201f8ed6ba6deb86369870379d63f14719d8a1827f
7
+ data.tar.gz: eb0b6cea76078763094d33ec83c089d0fe252eeb984444d0d6b57277171267ea70200858e2b8ac9fd9a810d5e915743f071a7347bbc6cfbb7a8d1a640184f86f
data/CHANGES.md CHANGED
@@ -1,6 +1,15 @@
1
1
  twilio-ruby changelog
2
2
  =====================
3
3
 
4
+ Version 3.14.4
5
+ --------------
6
+
7
+ Released January 8, 2015
8
+
9
+ - Feature: dynamically choose the auth token to validate requests with when using the TwilioWebhookAuthentication middleware.
10
+ - Deprecation: The Twilio::REST::SMS::Message resource is deprecated.
11
+ - More fixing of docs
12
+
4
13
  Version 3.14.3
5
14
  --------------
6
15
 
@@ -14,7 +14,7 @@ Twilio Client.
14
14
  Capability tokens are used by `Twilio Client
15
15
  <http://www.twilio.com/api/client>`_ to provide connection
16
16
  security and authorization. The `Capability Token documentation
17
- <http://www.twilio.com/docs/tokens>`_ explains in depth the purpose and
17
+ <https://www.twilio.com/docs/client/capability-tokens>`_ explains in depth the purpose and
18
18
  features of these tokens.
19
19
 
20
20
  :class:`Twilio::Util::Capability` is responsible for the creation of these
@@ -95,3 +95,13 @@ a Sinatra application:
95
95
  Now, any POST request to /messages in your application that doesn't validate as
96
96
  a Twilio request, will automatically respond with a 403 status code and your
97
97
  action will not be hit.
98
+
99
+ If you use subaccounts and need to validate with different auth tokens, you can pass a block to the middleware instead of an auth token. The block will be passed the Account Sid making the call.
100
+
101
+ .. code-block:: ruby
102
+
103
+ use Rack::TwilioWebhookAuthentication, nil, /\/messages/ do |account_sid|
104
+ # lookup auth_token from account_sid
105
+ end
106
+
107
+ Ensure you pass `nil` for the auth_token when passing a block, otherwise the block will not be called.
@@ -17,18 +17,20 @@ module Rack
17
17
  # doesn't validate then the middleware responds immediately with a 403 status.
18
18
 
19
19
  class TwilioWebhookAuthentication
20
- def initialize(app, auth_token, *paths)
20
+ def initialize(app, auth_token, *paths, &auth_token_lookup)
21
21
  @app = app
22
22
  @auth_token = auth_token
23
+ define_singleton_method(:get_auth_token, auth_token_lookup) if block_given?
23
24
  @path_regex = Regexp.union(paths)
24
25
  end
25
26
 
26
27
  def call(env)
27
28
  return @app.call(env) unless env["PATH_INFO"].match(@path_regex)
28
- validator = Twilio::Util::RequestValidator.new(@auth_token)
29
29
  request = Rack::Request.new(env)
30
30
  original_url = request.url
31
31
  params = request.post? ? request.POST : {}
32
+ auth_token = @auth_token || get_auth_token(params['AccountSid'])
33
+ validator = Twilio::Util::RequestValidator.new(auth_token)
32
34
  signature = env['HTTP_X_TWILIO_SIGNATURE'] || ""
33
35
  if validator.validate(original_url, params, signature)
34
36
  @app.call(env)
@@ -41,4 +43,5 @@ module Rack
41
43
  end
42
44
  end
43
45
  end
46
+
44
47
  end
@@ -1,7 +1,26 @@
1
1
  module Twilio
2
2
  module REST
3
3
  module SMS
4
+
5
+ module Deprecation
6
+ def deprecate(method_name)
7
+ old_method = "_deprecated_#{method_name}"
8
+ alias_method old_method, method_name
9
+ define_method method_name do |*args, &block|
10
+ warn "[DEPRECATED] SMS Resource is deprecated. Please use Messages (https://www.twilio.com/docs/api/rest/message)"
11
+ send old_method, *args, &block
12
+ end
13
+ end
14
+ end
15
+
4
16
  class Messages < ListResource
17
+ extend Deprecation
18
+
19
+ deprecate :list
20
+ deprecate :total
21
+ deprecate :get
22
+ deprecate :create
23
+
5
24
  def initialize(path, client)
6
25
  super
7
26
  @list_key = 'sms_messages'
@@ -9,6 +28,11 @@ module Twilio
9
28
  end
10
29
 
11
30
  class Message < InstanceResource
31
+ extend Deprecation
32
+
33
+ deprecate :update
34
+ deprecate :refresh
35
+ deprecate :delete
12
36
  end
13
37
  end
14
38
  end
@@ -1,3 +1,3 @@
1
1
  module Twilio
2
- VERSION = '3.14.3'
2
+ VERSION = '3.14.4'
3
3
  end
@@ -18,6 +18,28 @@ describe Rack::TwilioWebhookAuthentication do
18
18
  Rack::TwilioWebhookAuthentication.new(@app, 'ABC', /\/voice/, /\/sms/)
19
19
  }.not_to raise_error
20
20
  end
21
+
22
+ it 'should initialize with an app, dynamic token and paths' do
23
+ expect {
24
+ Rack::TwilioWebhookAuthentication.new(@app, nil, /\/voice/, /\/sms/)
25
+ }.not_to raise_error
26
+ end
27
+ end
28
+
29
+ describe 'calling against one path with dynamic auth token' do
30
+ it 'should allow a request through if it validates' do
31
+ auth_token = 'qwerty'
32
+ account_sid = 12345
33
+ expect_any_instance_of(Rack::Request).to receive(:post?).and_return(true)
34
+ expect_any_instance_of(Rack::Request).to receive(:POST).and_return({'AccountSid' => account_sid})
35
+ @middleware = Rack::TwilioWebhookAuthentication.new(@app, nil, /\/voice/) { |asid| auth_token}
36
+ request_validator = double('RequestValidator')
37
+ expect(Twilio::Util::RequestValidator).to receive(:new).with(auth_token).and_return(request_validator)
38
+ expect(request_validator).to receive(:validate).and_return(true)
39
+ request = Rack::MockRequest.env_for('/voice')
40
+ status, headers, body = @middleware.call(request)
41
+ expect(status).to be(200)
42
+ end
21
43
  end
22
44
 
23
45
  describe 'calling against one path' do
@@ -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,36 @@
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
+
32
+ it 'should warn of deprecation of SMS Messages total' do
33
+ expect(@messages).to receive(:warn)
34
+ @messages.total
35
+ end
36
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twilio-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.14.3
4
+ version: 3.14.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Benton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-08 00:00:00.000000000 Z
11
+ date: 2015-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -195,6 +195,8 @@ files:
195
195
  - spec/rest/numbers_spec.rb
196
196
  - spec/rest/queue_spec.rb
197
197
  - spec/rest/recording_spec.rb
198
+ - spec/rest/sms/message_spec.rb
199
+ - spec/rest/sms/messages_spec.rb
198
200
  - spec/rest/token_spec.rb
199
201
  - spec/rest/utils_spec.rb
200
202
  - spec/spec_helper.rb
@@ -250,6 +252,8 @@ test_files:
250
252
  - spec/rest/numbers_spec.rb
251
253
  - spec/rest/queue_spec.rb
252
254
  - spec/rest/recording_spec.rb
255
+ - spec/rest/sms/message_spec.rb
256
+ - spec/rest/sms/messages_spec.rb
253
257
  - spec/rest/token_spec.rb
254
258
  - spec/rest/utils_spec.rb
255
259
  - spec/spec_helper.rb