twilio-ruby 3.13.1 → 3.14.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- N2ZkYWFmMjJiYzRiMGFhOTRlNDc5ODdmOTFlZmFlMzJkN2M5NTZiNw==
5
- data.tar.gz: !binary |-
6
- ZWFkZWY0NDRiOTk1NDVkYzg2ZjdkODgzOGM5OTM5YTJhZWQ4OWMzYQ==
2
+ SHA1:
3
+ metadata.gz: 1b939e0692e2400ddc4310309010b1227d0c2b70
4
+ data.tar.gz: 38363b14c3977aab51bd0f021c6b3284e457e3f9
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- YzIyNzEzZTY3OThiMzcyMTUxOWI5MjMwNTU1NWQwNjVmZTFjNzQwZGQzYzlm
10
- MzQzNGU3Njg4NDVhMDdhODY4YzQ5MGYxNzk0NmUwNTAxNDIxNDI0OTI1ZDU3
11
- MjA5YzZhODVhM2IwOGFhODcyMmQwOTc5YmIyMzUwM2JmMDA1ZjI=
12
- data.tar.gz: !binary |-
13
- OWQ0NWE1OTYxNzc4OGY0YTBjYmFjMzQ3MmFjMTJmMGRhMDQ0MjhkYzBkNmVi
14
- YjNjMjk0ZjRlYzhkMjg5MTUyNDBmOTkyZjdmNTE3MTI4YTZiM2FiNjExMmM3
15
- Nzg2OWY2OGMyN2QxNjcyYWM3OWFiMGZkODFhODRlMmI4NmU4YWE=
6
+ metadata.gz: 45a7ea0839cb677f5310e0283371233b8a157d778b62a15373b19cb66302417da7442e259c5406a453b41b50b481156622a16d58e8a6b52209f603f069f0260f
7
+ data.tar.gz: fc3560fa5c61d3da6d9a11600921531241f1c0abfa43ff07869c3d09fb5cc556083d6556c661e75853d301fd3dda442bc2ac8ccf7f31a3191a3b145f33155d8e
data/AUTHORS.md CHANGED
@@ -6,6 +6,7 @@ A huge thanks to all of our contributors:
6
6
 
7
7
  - Adam Ballai
8
8
  - Alexander Murmann & Ryan Spore
9
+ - Alexandre Payment
9
10
  - Andrew Benton
10
11
  - Brian Levine
11
12
  - Caley Woods
data/CHANGES.md CHANGED
@@ -1,6 +1,14 @@
1
1
  twilio-ruby changelog
2
2
  =====================
3
3
 
4
+ Version 3.14.0
5
+ --------------
6
+
7
+ Released November 13, 2014
8
+
9
+ - Switch to a constant-time string comparison for TwiML request signature validation
10
+ - Add support for Call and Message deletion/redaction
11
+
4
12
  Version 3.13.1
5
13
  --------------
6
14
 
@@ -88,6 +88,25 @@ Retrieving Sent Messages
88
88
  @client.messages.list.each do |message|
89
89
  puts message.body
90
90
 
91
+ Redacting or Deleting Messages
92
+ ------------------------------
93
+
94
+ .. code-block:: ruby
95
+
96
+ require 'twilio-ruby'
97
+
98
+ # To find these visit https://www.twilio.com/user/account
99
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
100
+ auth_token = "YYYYYYYYYYYYYYYYYY"
101
+
102
+ @client = Twilio::REST::Client.new account_sid, auth_token
103
+ @msg_sid = 'MM123'
104
+ @msg = @client.messages.get('MM123')
105
+ # Deletes the Body field contents
106
+ @msg.redact
107
+
108
+ # Removes the entire Message record
109
+ @msg.delete
91
110
 
92
111
  Filtering Your Messages
93
112
  -------------------------
@@ -52,6 +52,23 @@ you can use the client to retrieve that record.
52
52
  sid = "CA12341234"
53
53
  @call = @client.calls.get(sid)
54
54
 
55
+ Delete a Call Record
56
+ --------------------
57
+
58
+ .. code-block:: ruby
59
+
60
+ require 'twilio-ruby'
61
+
62
+ # To find these visit https://www.twilio.com/user/account
63
+ account_sid = "ACXXXXXXXXXXXXXXXXX"
64
+ auth_token = "YYYYYYYYYYYYYYYYYY"
65
+
66
+ @client = Twilio::REST::Client.new account_sid, auth_token
67
+ sid = "CA12341234"
68
+ @call = @client.calls.get(sid)
69
+
70
+ # Removes the entire record from Twilio's storage
71
+ @call.delete
55
72
 
56
73
  Accessing Specific Call Resources
57
74
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -12,6 +12,11 @@ module Twilio
12
12
  super
13
13
  resource :media
14
14
  end
15
+
16
+ def redact()
17
+ update({body: ''})
18
+ end
19
+
15
20
  end
16
21
  end
17
22
  end
@@ -3,29 +3,18 @@ module Twilio
3
3
  module Utils
4
4
 
5
5
  def twilify(something)
6
- if something.is_a? Hash
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]
11
- else
12
- something.to_s.split('_').map! do |s|
13
- [s[0,1].capitalize, s[1..-1]].join
14
- end.join
15
- end
6
+ return key_map(something, :twilify) if something.is_a? Hash
7
+ string = something.to_s
8
+ string.split('_').map do |string_part|
9
+ string_part[0,1].capitalize + string_part[1..-1]
10
+ end.join
16
11
  end
17
12
 
18
13
  def detwilify(something)
19
- if something.is_a? Hash
20
- something = *something.to_a
21
- something.map! { |pair| [detwilify(pair[0]).to_sym, pair[1]] }
22
- something = something.flatten
23
- Hash[something]
24
- else
25
- something = something.to_s
26
- something = something.gsub(/[A-Z][a-z]*/) { |s| "_#{s.downcase}" }
27
- something.gsub(/^_/, '')
28
- end
14
+ return key_map(something, :detwilify) if something.is_a? Hash
15
+ string = something.to_s
16
+ string = string[0,1].downcase + string[1..-1]
17
+ string.gsub(/[A-Z][a-z]*/) { |s| "_#{s.downcase}" }
29
18
  end
30
19
 
31
20
  protected
@@ -46,6 +35,15 @@ module Twilio
46
35
  end
47
36
  self.class.instance_eval { attr_reader *resources }
48
37
  end
38
+
39
+ private
40
+
41
+ def key_map(something, method)
42
+ something = something.to_a.flat_map do |pair|
43
+ [send(method, pair[0]).to_sym, pair[1]]
44
+ end
45
+ Hash[*something]
46
+ end
49
47
  end
50
48
  end
51
49
  end
@@ -9,7 +9,7 @@ module Twilio
9
9
 
10
10
  def validate(url, params, signature)
11
11
  expected = build_signature_for url, params
12
- expected == signature
12
+ secure_compare(expected, signature)
13
13
  end
14
14
 
15
15
  def build_signature_for(url, params)
@@ -18,6 +18,20 @@ module Twilio
18
18
  Base64.encode64(OpenSSL::HMAC.digest(digest, @auth_token, data)).strip
19
19
  end
20
20
 
21
+ private
22
+
23
+ # Compares two strings in constant time to avoid timing attacks.
24
+ # Borrowed from ActiveSupport::MessageVerifier.
25
+ # https://github.com/rails/rails/blob/master/activesupport/lib/active_support/message_verifier.rb
26
+ def secure_compare(a, b)
27
+ return false unless a.bytesize == b.bytesize
28
+
29
+ l = a.unpack("C#{a.bytesize}")
30
+
31
+ res = 0
32
+ b.each_byte { |byte| res |= byte ^ l.shift }
33
+ res == 0
34
+ end
21
35
  end
22
36
  end
23
37
  end
@@ -1,3 +1,3 @@
1
1
  module Twilio
2
- VERSION = '3.13.1'
2
+ VERSION = '3.14.0'
3
3
  end
@@ -181,19 +181,4 @@ describe Twilio::REST::Client do
181
181
  expect(client.send(method)).to eq(client.account.send(method))
182
182
  end
183
183
  end
184
-
185
- it 'should convert all parameter names to Twilio-style names' do
186
- twilio = Twilio::REST::Client.new('someSid', 'someToken')
187
- untwilified = {
188
- :sms_url => 'someUrl',
189
- 'voiceFallbackUrl' => 'anotherUrl',
190
- 'Status_callback' => 'yetAnotherUrl'
191
- }
192
- twilified = {
193
- :SmsUrl => 'someUrl',
194
- :VoiceFallbackUrl => 'anotherUrl',
195
- :StatusCallback => 'yetAnotherUrl'
196
- }
197
- expect(twilio.twilify(untwilified)).to eq(twilified)
198
- end
199
184
  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
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twilio-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.13.1
4
+ version: 3.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Benton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-01 00:00:00.000000000 Z
11
+ date: 2014-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.3.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.3.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: builder
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: 2.1.2
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 2.1.2
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: jwt
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: 1.0.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 1.0.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '1.5'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.5'
69
69
  description: A simple library for communicating with the Twilio REST API, building
@@ -76,8 +76,8 @@ extra_rdoc_files:
76
76
  - README.md
77
77
  - LICENSE.md
78
78
  files:
79
- - .gitignore
80
- - .travis.yml
79
+ - ".gitignore"
80
+ - ".travis.yml"
81
81
  - AUTHORS.md
82
82
  - CHANGES.md
83
83
  - Gemfile
@@ -190,6 +190,7 @@ files:
190
190
  - spec/rest/numbers_spec.rb
191
191
  - spec/rest/queue_spec.rb
192
192
  - spec/rest/recording_spec.rb
193
+ - spec/rest/utils_spec.rb
193
194
  - spec/spec_helper.rb
194
195
  - spec/support/fakeweb.rb
195
196
  - spec/twilio_spec.rb
@@ -204,27 +205,27 @@ licenses:
204
205
  metadata: {}
205
206
  post_install_message:
206
207
  rdoc_options:
207
- - --line-numbers
208
- - --inline-source
209
- - --title
208
+ - "--line-numbers"
209
+ - "--inline-source"
210
+ - "--title"
210
211
  - twilio-ruby
211
- - --main
212
+ - "--main"
212
213
  - README.md
213
214
  require_paths:
214
215
  - lib
215
216
  required_ruby_version: !ruby/object:Gem::Requirement
216
217
  requirements:
217
- - - ! '>='
218
+ - - ">="
218
219
  - !ruby/object:Gem::Version
219
220
  version: 1.9.3
220
221
  required_rubygems_version: !ruby/object:Gem::Requirement
221
222
  requirements:
222
- - - ! '>='
223
+ - - ">="
223
224
  - !ruby/object:Gem::Version
224
225
  version: '0'
225
226
  requirements: []
226
227
  rubyforge_project:
227
- rubygems_version: 2.4.1
228
+ rubygems_version: 2.2.2
228
229
  signing_key:
229
230
  specification_version: 4
230
231
  summary: A simple library for communicating with the Twilio REST API, building TwiML,
@@ -242,6 +243,7 @@ test_files:
242
243
  - spec/rest/numbers_spec.rb
243
244
  - spec/rest/queue_spec.rb
244
245
  - spec/rest/recording_spec.rb
246
+ - spec/rest/utils_spec.rb
245
247
  - spec/spec_helper.rb
246
248
  - spec/support/fakeweb.rb
247
249
  - spec/twilio_spec.rb